Class: Docs::Coffeescript::CleanHtmlFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/docs/filters/coffeescript/clean_html.rb

Constant Summary

Constants inherited from Filter

Filter::SCHEME_RGX

Instance Method Summary collapse

Methods inherited from Filter

#absolute_url_string?, #at_css, #at_xpath, #base_url, #css, #current_url, #fragment_url_string?, #initial_page?, #parse_html, #relative_url_string?, #root_page?, #root_path, #root_url, #slug, #subpath, #subpath_to, #xpath

Instance Method Details

#callObject


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/docs/filters/coffeescript/clean_html.rb', line 4

def call
  css('#top', '.minibutton', '.clear').remove

  # Set id attributes on actual elements instead of an empty <span>
  css('.bookmark').each do |node|
    if node.parent.name == 'h2'
      node.parent['id'] = node['id']
    elsif node.next_element.name == 'b'
      node.next_element['id'] = node['id']
    end
    node.remove
  end

  # Remove Books, Screencasts, etc.
  while doc.children.last['id'] != 'scripts'
    doc.children.last.remove
  end
  doc.children.last.remove

  # Make proper headings
  css('.header').each do |node|
    node.parent.before(node)
    node.name = 'h3'
    node['id'] ||= node.content.strip.parameterize
    node.remove_attribute 'class'
  end

  # Remove "Latest Version" paragraph
  css('b').each do |node|
    if node.content =~ /Latest Version/i
      node.parent.next_element.remove
      node.parent.remove
      break
    end
  end

  # Remove "examples can be run" paragraph
  css('i').each do |node|
    if node.content =~ /examples can be run/i
      node.parent.remove
      break
    end
  end

  # Remove code highlighting
  css('pre').each do |node|
    node.content = node.content
  end

  css('tt').each do |node|
    node.name = 'code'
  end

  doc
end