Class: Docs::Haskell::CleanHtmlFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/docs/filters/haskell/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
# File 'lib/docs/filters/haskell/clean_html.rb', line 4

def call
  root_page? ? root : other
  doc
end

#otherObject


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
# File 'lib/docs/filters/haskell/clean_html.rb', line 15

def other
  css('h1').each do |node|
    node.remove if node.content == 'Documentation'
  end

  css('h1, h2, h3, h4').each do |node|
    node.name = node.name.sub(/\d/) { |i| i.to_i + 1 }
  end

  at_css('#module-header').tap do |node|
    heading = at_css('.caption')
    heading.name = 'h1'
    node.before(heading)
    node.before(node.children).remove
  end

  css('#synopsis').remove

  css('#interface', 'h2 code').each do |node|
    node.before(node.children).remove
  end

  css('a[name]').each do |node|
    node['id'] = node['name']
    node.remove_attribute('name')
  end

  css('p.caption').each do |node|
    node.name = 'h4'
  end

  css('em').each do |node|
    if node.content.start_with?('O(')
      node.name = 'span'
      node['class'] = 'complexity'
    elsif node.content.start_with?('Since')
      node.name = 'span'
      node['class'] = 'version'
    end
  end

  doc
end

#rootObject


9
10
11
12
13
# File 'lib/docs/filters/haskell/clean_html.rb', line 9

def root
  css('#description', '#module-list').each do |node|
    node.before(node.children).remove
  end
end