|
|
@@ -2,103 +2,86 @@ module Docs
|
|
|
class Angular
|
|
|
class CleanHtmlFilter < Filter
|
|
|
def call
|
|
|
- container = at_css('article.docs-content')
|
|
|
- badges = css('header.hero .badge, header.hero .hero-subtitle').map do |node|
|
|
|
- node.name = 'span'
|
|
|
- node['class'] = 'status-badge'
|
|
|
- node.to_html
|
|
|
- end.join(' ')
|
|
|
- badges = %(<div class="badges">#{badges}</div>)
|
|
|
- container.child.before(at_css('header.hero h1')).before(badges).before(css('header.hero + .banner, header.hero .breadcrumbs'))
|
|
|
- @doc = container
|
|
|
-
|
|
|
- title = at_css('h1').content.strip
|
|
|
if root_page?
|
|
|
+ css('.card-container').remove
|
|
|
at_css('h1').content = 'Angular Documentation'
|
|
|
- elsif title == 'Index'
|
|
|
- at_css('h1').content = result[:entries].first.name
|
|
|
- elsif title == 'Angular'
|
|
|
- at_css('h1').content = slug.split('/').last.gsub('-', ' ')
|
|
|
- elsif at_css('.breadcrumbs') && title != result[:entries].first.name
|
|
|
- at_css('h1').content = result[:entries].first.name
|
|
|
end
|
|
|
|
|
|
- css('pre.no-bg-with-indent').each do |node|
|
|
|
- node.content = ' ' + node.content.gsub("\n", "\n ")
|
|
|
- end
|
|
|
-
|
|
|
- css('.openParens').each do |node|
|
|
|
- node.parent.name = 'pre'
|
|
|
- node.parent.content = node.parent.css('code, pre').map(&:content).join("\n")
|
|
|
- end
|
|
|
-
|
|
|
- css('button.verbose', 'button.verbose + .l-verbose-section', 'a[id=top]', 'a[href="#top"]', '.sidebar').remove
|
|
|
+ css('br', 'hr', '.material-icons', '.header-link').remove
|
|
|
|
|
|
- css('.c10', '.showcase', '.showcase-content', '.l-main-section', 'div.div', 'div[flex]', 'code-tabs', 'md-card', 'md-card-content', 'div:not([class])', 'footer', '.card-row', '.card-row-container', 'figure', 'blockquote', 'exported', 'defined', 'div.ng-scope', '.code-example header', 'section.desc', '.row', '.dart-api-entry-main', '.main-content', 'section.summary', 'span.signature').each do |node|
|
|
|
+ css('.content', 'article', '.api-header', 'section', '.instance-member').each do |node|
|
|
|
node.before(node.children).remove
|
|
|
end
|
|
|
|
|
|
- css('span.badges').each do |node|
|
|
|
- node.name = 'div'
|
|
|
+ css('label', 'h2 > em', 'h3 > em').each do |node|
|
|
|
+ node.name = 'code'
|
|
|
end
|
|
|
|
|
|
- css('pre[language]').each do |node|
|
|
|
- node['data-language'] = node['language'].sub(/\Ats/, 'typescript').strip
|
|
|
- node['data-language'] = 'html' if node.content.start_with?('<')
|
|
|
+ css('h1 + code').each do |node|
|
|
|
+ node.before('<p></p>')
|
|
|
+ while node.next_element.name == 'code'
|
|
|
+ node.previous_element << ' '
|
|
|
+ node.previous_element << node.next_element
|
|
|
+ end
|
|
|
+ node.previous_element.prepend_child(node)
|
|
|
end
|
|
|
|
|
|
- css('pre.prettyprint').each do |node|
|
|
|
- node.content = node.content.strip
|
|
|
- node['data-language'] = 'dart' if node['class'].include?('dart')
|
|
|
- node['data-language'] = 'html' if node.content.start_with?('<')
|
|
|
+ css('td h3', '.l-sub-section > h3', '.alert h3', '.row-margin > h3', '.api-heading ~ h3', '.api-heading + h2', '.metadata-member h3').each do |node|
|
|
|
+ node.name = 'h4'
|
|
|
end
|
|
|
|
|
|
- css('.multi-line-signature').each do |node|
|
|
|
- node.name = 'pre'
|
|
|
- node.content = node.content.strip
|
|
|
+ css('.l-sub-section', '.alert', '.banner').each do |node|
|
|
|
+ node.name = 'blockquote'
|
|
|
end
|
|
|
|
|
|
- css('a[id]:empty').each do |node|
|
|
|
- node.next_element['id'] = node['id'] if node.next_element
|
|
|
+ css('.file').each do |node|
|
|
|
+ node.content = node.content.strip
|
|
|
end
|
|
|
|
|
|
- css('a[name]:empty').each do |node|
|
|
|
- node.next_element['id'] = node['name'] if node.next_element
|
|
|
+ css('.filetree .children').each do |node|
|
|
|
+ node.css('.file').each do |n|
|
|
|
+ n.content = " #{n.content}"
|
|
|
+ end
|
|
|
end
|
|
|
|
|
|
- css('tr[style]').each do |node|
|
|
|
- node.remove_attribute 'style'
|
|
|
+ css('.filetree').each do |node|
|
|
|
+ node.content = node.css('.file').map(&:inner_html).join("\n")
|
|
|
+ node.name = 'pre'
|
|
|
+ node.remove_attribute('class')
|
|
|
end
|
|
|
|
|
|
- css('h1:not(:first-child)').each do |node|
|
|
|
- node.name = 'h2'
|
|
|
- end unless at_css('h2')
|
|
|
+ css('pre').each do |node|
|
|
|
+ node.content = node.content.strip
|
|
|
|
|
|
- css('img[style]').each do |node|
|
|
|
- node['align'] ||= node['style'][/float:\s*(left|right)/, 1]
|
|
|
- node['style'] = node['style'].split(';').map(&:strip).select { |s| s =~ /\Awidth|height/ }.join(';')
|
|
|
- end
|
|
|
+ node['data-language'] = 'typescript' if node['path'].try(:ends_with?, '.ts')
|
|
|
+ node['data-language'] = 'html' if node['path'].try(:ends_with?, '.html')
|
|
|
+ node['data-language'] = 'css' if node['path'].try(:ends_with?, '.css')
|
|
|
+ node['data-language'] = node['language'].sub(/\Ats/, 'typescript').strip if node['language']
|
|
|
+ node['data-language'] ||= 'typescript' if node.content.start_with?('@')
|
|
|
|
|
|
- css('.example-title + pre').each do |node|
|
|
|
- node['name'] = node.previous_element.content.strip
|
|
|
- node.previous_element.remove
|
|
|
- end
|
|
|
+ node.before(%(<div class="pre-title">#{node['title']}</div>)) if node['title']
|
|
|
|
|
|
- css('pre[name]').each do |node|
|
|
|
- node.before(%(<div class="pre-title">#{node['name']}</div>))
|
|
|
- end
|
|
|
+ if node['class'] && node['class'].include?('api-heading')
|
|
|
+ node.name = 'h3'
|
|
|
+ node.inner_html = "<code>#{node.inner_html}</code>"
|
|
|
+ end
|
|
|
|
|
|
- css('a.is-button > h3').each do |node|
|
|
|
- node.parent.content = node.content
|
|
|
+ node.remove_attribute('path')
|
|
|
+ node.remove_attribute('region')
|
|
|
+ node.remove_attribute('linenums')
|
|
|
+ node.remove_attribute('title')
|
|
|
+ node.remove_attribute('language')
|
|
|
+ node.remove_attribute('hidecopy')
|
|
|
+ node.remove_attribute('class')
|
|
|
end
|
|
|
|
|
|
- css('#angular-2-glossary ~ .l-sub-section').each do |node|
|
|
|
- node.before(node.children).remove
|
|
|
- end
|
|
|
+ css('h1[class]').remove_attr('class')
|
|
|
+ css('table[class]').remove_attr('class')
|
|
|
+ css('table[width]').remove_attr('width')
|
|
|
+ css('tr[style]').remove_attr('style')
|
|
|
|
|
|
- location_badge = at_css('.location-badge')
|
|
|
- if location_badge && doc.last_element_child != location_badge
|
|
|
- doc.last_element_child.after(location_badge)
|
|
|
+ if at_css('.api-type-label.module')
|
|
|
+ at_css('h1').content = subpath.remove('api/')
|
|
|
end
|
|
|
|
|
|
doc
|