|
|
|
@ -2,59 +2,27 @@ module Docs
|
|
|
|
|
class React
|
|
|
|
|
class CleanHtmlFilter < Filter
|
|
|
|
|
def call
|
|
|
|
|
@doc = at_css('.inner-content, article.withtoc')
|
|
|
|
|
@doc = at_css('article')
|
|
|
|
|
|
|
|
|
|
if root_page?
|
|
|
|
|
at_css('h1').content = context[:root_title]
|
|
|
|
|
at_css('h1').content = 'React Documentation'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
css('.docs-prevnext', '.hash-link', '.edit-page-link', '.edit-github', 'a.hash', '.edit-page-block', 'a.show', 'a.hide', 'hr').remove
|
|
|
|
|
|
|
|
|
|
css('table h1', 'table h2', 'table h3').each do |node|
|
|
|
|
|
table = node
|
|
|
|
|
table = table.parent until table.name == 'table'
|
|
|
|
|
table.replace(node)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
css('a.anchor', 'a.hashref').each do |node|
|
|
|
|
|
node.parent['id'] ||= node['name'] || node['id']
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
css('.highlight').each do |node|
|
|
|
|
|
node.name = 'pre'
|
|
|
|
|
node.css('.gutter').remove
|
|
|
|
|
node['data-language'] = node.at_css('[data-lang]').try(:[], 'data-lang') || 'js'
|
|
|
|
|
node.content = node.content.strip
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
css('table.highlighttable').each do |node|
|
|
|
|
|
node.replace(node.at_css('pre.highlight'))
|
|
|
|
|
css('header', 'div[class^="css-"]', '.gatsby-resp-image-link span').each do |node|
|
|
|
|
|
node.before(node.children).remove
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
css('.prism').each do |node|
|
|
|
|
|
node.name = 'pre'
|
|
|
|
|
node['data-language'] = node['class'][/(?<=language\-)(\w+)/]
|
|
|
|
|
css('.gatsby-highlight > pre').each do |node|
|
|
|
|
|
node.content = node.content
|
|
|
|
|
node['data-language'] = node['class'][/(?<=gatsby\-code\-)(\w+)/]
|
|
|
|
|
node.remove_attribute('class')
|
|
|
|
|
node.parent.replace(node)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
css('blockquote > p:first-child').each do |node|
|
|
|
|
|
node.remove if node.content.strip == 'Note:'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
css('h3#props', 'h3#methods').each { |node| node.name = 'h2' }
|
|
|
|
|
css('h4.propTitle').each { |node| node.name = 'h3' }
|
|
|
|
|
|
|
|
|
|
css('> div > div', '> div', 'div > span', '.props', '.prop').each do |node|
|
|
|
|
|
node.before(node.children).remove
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
css('a pre', 'h3 .propType').each do |node|
|
|
|
|
|
node.name = 'code'
|
|
|
|
|
end
|
|
|
|
|
css('a.anchor', 'a:contains("Edit this page")', 'hr').remove
|
|
|
|
|
|
|
|
|
|
css('a[target]').each do |node|
|
|
|
|
|
node.remove_attribute('target')
|
|
|
|
|
end
|
|
|
|
|
css('a').remove_attr('rel').remove_attr('target').remove_attr('class').remove_attr('style')
|
|
|
|
|
css('img').remove_attr('style').remove_attr('srcset').remove_attr('sizes').remove_attr('class')
|
|
|
|
|
|
|
|
|
|
doc
|
|
|
|
|
end
|
|
|
|
|