Class: Docs::C::CleanHtmlFilter

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

def call
  css('h1').remove if root_page?

  css('#siteSub', '#contentSub', '.printfooter', '.t-navbar', '.editsection', '#toc',
      '.t-dsc-sep', '.t-dcl-sep', '#catlinks', '.ambox-notice', '.mw-cite-backlink',
      '.t-sdsc-sep:first-child:last-child', '.t-example-live-link').remove

  css('#bodyContent', '.mw-content-ltr', 'span[style]').each do |node|
    node.before(node.children).remove
  end

  css('h2 > span[id]', 'h3 > span[id]', 'h4 > span[id]', 'h5 > span[id]', 'h6 > span[id]').each do |node|
    node.parent['id'] = node['id']
    node.before(node.children).remove
  end

  css('table[style]', 'th[style]', 'td[style]').remove_attr('style')

  css('.t-dsc-hitem > td', '.t-dsc-header > td').each do |node|
    node.name = 'th'
    node.content = ' ' if node.content.empty?
  end

  css('tt', 'span > span.source-cpp').each do |node|
    node.name = 'code'
  end

  css('div > span.source-cpp').each do |node|
    node.name = 'pre'
    node.inner_html = node.inner_html.gsub('<br>', "\n")
    node.content = node.content
  end

  css('div > a > img[alt="About this image"]').each do |node|
    node.parent.parent.remove
  end

  css('area[href]').each do |node|
    node['href'] = node['href'].remove('.html')
  end

  css('h1 ~ .fmbox').each do |node|
    node.name = 'div'
    node.content = node.content
  end

  doc
end