Class: Docs::Jquery::CleanHtmlFilter

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

def call
  css('hr', '.icon-link', '.entry-meta').remove

  if css('> article').length == 1
    doc.children = at_css('article').children
  end

  if root_page?
    # Remove index page title
    at_css('.page-title').remove

    # Change headings on index page
    css('h1.entry-title').each do |node|
      node.name = 'h2'
    end
  end

  # Remove useless <header>
  css('.entry-header > .entry-title', 'header > .underline', 'header > h2:only-child').to_a.uniq.each do |node|
    node.parent.replace node
  end

  # Remove code highlighting
  css('div.syntaxhighlighter').each do |node|
    node.name = 'pre'
    node.content = node.at_css('td.code').css('div.line').map(&:content).join("\n")
  end

  # jQueryMobile/jqmData, etc.
  css('dd > dl').each do |node|
    node.parent.replace(node)
  end

  doc
end