|
|
@@ -2,44 +2,38 @@ module Docs
|
|
|
class Angular
|
|
|
class CleanHtmlFilter < Filter
|
|
|
def call
|
|
|
- # Fix internal links (remove colons)
|
|
|
- css('a[href]').each do |node|
|
|
|
- node['href'] = node['href'].gsub %r{(directive|filter):}, '\1-'
|
|
|
+ root_page? ? root : other
|
|
|
+
|
|
|
+ # Remove ng-* attributes
|
|
|
+ css('*').each do |node|
|
|
|
+ node.attributes.each_key do |attribute|
|
|
|
+ node.remove_attribute(attribute) if attribute.start_with? 'ng-'
|
|
|
+ end
|
|
|
end
|
|
|
|
|
|
- root_page? ? root : other
|
|
|
doc
|
|
|
end
|
|
|
|
|
|
def root
|
|
|
- css('.pull-right', '.ng-hide').remove
|
|
|
-
|
|
|
- # Turn "module [...]" <li> into <h2>
|
|
|
- css('.nav-header.module').each do |node|
|
|
|
- node.name = 'h2'
|
|
|
- node.parent.before(node)
|
|
|
+ css('.nav-index-group').each do |node|
|
|
|
+ if heading = node.at_css('.nav-index-group-heading')
|
|
|
+ heading.name = 'h2'
|
|
|
+ end
|
|
|
+ node.parent.before(node.children)
|
|
|
end
|
|
|
|
|
|
- # Remove links to "Directive", "Filter", etc.
|
|
|
- css('a.guide').each do |node|
|
|
|
- node.replace(node.content)
|
|
|
+ css('.nav-index-section').each do |node|
|
|
|
+ node.content = node.content
|
|
|
end
|
|
|
+
|
|
|
+ css('.toc-close', '.naked-list').remove
|
|
|
end
|
|
|
|
|
|
def other
|
|
|
- css('#example', '.example', '#description_source', '#description_demo', '[id$="example"]').remove
|
|
|
+ css('#example', '.example', '#description_source', '#description_demo', '[id$="example"]', 'hr').remove
|
|
|
|
|
|
- if at_css('h1').content.strip.empty?
|
|
|
- # Ensure proper <h1> (e.g. ngResource, AUTO, etc.)
|
|
|
- at_css('h2').tap do |node|
|
|
|
- at_css('h1').content = node.try(:content) || slug
|
|
|
- node.try(:remove)
|
|
|
- end
|
|
|
- else
|
|
|
- # Clean up .hint in <h1>
|
|
|
- css('h1 > div > .hint').each do |node|
|
|
|
- node.parent.before("<small>(#{node.content.strip})</small>").remove
|
|
|
- end
|
|
|
+ css('header').each do |node|
|
|
|
+ node.before(node.children).remove
|
|
|
end
|
|
|
|
|
|
at_css('h1').add_child(css('.view-source', '.improve-docs'))
|
|
|
@@ -50,34 +44,41 @@ module Docs
|
|
|
div.remove
|
|
|
end
|
|
|
|
|
|
+ css('.api-profile-header-structure > li').each do |node|
|
|
|
+ node.inner_html = node.inner_html.remove('- ')
|
|
|
+ end
|
|
|
+
|
|
|
+ css('h1').each_with_index do |node, i|
|
|
|
+ next if i == 0
|
|
|
+ node.name = 'h2'
|
|
|
+ end
|
|
|
+
|
|
|
+ # Remove examples
|
|
|
+ css('.runnable-example').each do |node|
|
|
|
+ node.parent.remove
|
|
|
+ end
|
|
|
+
|
|
|
# Remove dead links (e.g. ngRepeat)
|
|
|
css('a.type-hint').each do |node|
|
|
|
node.name = 'code'
|
|
|
node.remove_attribute 'href'
|
|
|
end
|
|
|
|
|
|
- # Remove some <code> elements
|
|
|
- css('h1 > code', 'pre > code', 'h6 > code').each do |node|
|
|
|
- node.before(node.content).remove
|
|
|
- end
|
|
|
-
|
|
|
- # Fix code indentation
|
|
|
- css('code', 'pre').each do |node|
|
|
|
- node.inner_html = node.inner_html.strip_heredoc.strip
|
|
|
+ css('pre > code').each do |node|
|
|
|
+ node.parent['class'] = node['class']
|
|
|
+ node.before(node.children).remove
|
|
|
end
|
|
|
|
|
|
- # Make <pre> elements
|
|
|
- css('.in-javascript', '.in-html-template-binding').each do |node|
|
|
|
- node.name = 'pre'
|
|
|
- node.content = node.content
|
|
|
+ # Remove some <code> elements
|
|
|
+ css('h1 > code', 'h2 > code', 'h3 > code', 'h4 > code', 'h6 > code').each do |node|
|
|
|
+ node.before(node.content).remove
|
|
|
end
|
|
|
|
|
|
- css('ul.methods', 'ul.properties', 'ul.events').add_class('defs')
|
|
|
-
|
|
|
- # Remove ng-* attributes
|
|
|
- css('*').each do |node|
|
|
|
- node.attributes.each_key do |attribute|
|
|
|
- node.remove_attribute(attribute) if attribute.start_with? 'ng-'
|
|
|
+ css('ul.methods', 'ul.properties', 'ul.events').add_class('defs').each do |node|
|
|
|
+ node.css('> li > h3').each do |h3|
|
|
|
+ next if h3.content.present?
|
|
|
+ h3.content = h3.next_element.content
|
|
|
+ h3.next_element.remove
|
|
|
end
|
|
|
end
|
|
|
end
|