|
|
|
@ -2,72 +2,34 @@ module Docs
|
|
|
|
|
class Babel
|
|
|
|
|
class CleanHtmlFilter < Filter
|
|
|
|
|
def call
|
|
|
|
|
css('.btn-clipboard').remove
|
|
|
|
|
|
|
|
|
|
css('div.highlighter-rouge').each do |node|
|
|
|
|
|
pre = node.at_css('pre')
|
|
|
|
|
|
|
|
|
|
# copy over the highlighting metadata
|
|
|
|
|
match = /language-(\w+)/.match(node['class'])
|
|
|
|
|
if match
|
|
|
|
|
lang = match[1]
|
|
|
|
|
if lang == 'sh'
|
|
|
|
|
lang = 'bash'
|
|
|
|
|
end
|
|
|
|
|
pre['class'] = nil
|
|
|
|
|
pre['data-language'] = lang
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# Remove the server-rendered syntax highlighting
|
|
|
|
|
code = pre.at_css('code')
|
|
|
|
|
code.content = code.text
|
|
|
|
|
|
|
|
|
|
# Remove the div.highlighter-rouge and div.highlight wrapping the <pre>
|
|
|
|
|
node.add_next_sibling pre
|
|
|
|
|
node.remove
|
|
|
|
|
if root_page?
|
|
|
|
|
doc.inner_html = '<h1>Babel</h1>'
|
|
|
|
|
return doc
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
header = at_css('.docs-header .col-md-12')
|
|
|
|
|
@doc = at_css('.docs-content')
|
|
|
|
|
doc.prepend_child(header)
|
|
|
|
|
|
|
|
|
|
css('blockquote').each do |node|
|
|
|
|
|
node.name = 'div'
|
|
|
|
|
node['class'] = '_note'
|
|
|
|
|
end
|
|
|
|
|
css('.btn-clipboard', '.package-links').remove
|
|
|
|
|
|
|
|
|
|
css((1..6).map { |n| "h#{n}" }).each do |header|
|
|
|
|
|
return unless header.at_css('a')
|
|
|
|
|
header.content = header.at_css('a').content
|
|
|
|
|
css('.col-md-12', 'h1 a', 'h2 a', 'h3 a', 'h4 a', 'h5 a', 'h5 a').each do |node|
|
|
|
|
|
node.before(node.children).remove
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
css('div.highlighter-rouge').each do |node|
|
|
|
|
|
pre = node.at_css('pre')
|
|
|
|
|
|
|
|
|
|
header = doc # .docs-content
|
|
|
|
|
.parent # .row
|
|
|
|
|
.parent # .container
|
|
|
|
|
.previous_element # .docs_header
|
|
|
|
|
lang = node['class'][/language-(\w+)/, 1]
|
|
|
|
|
lang = 'bash' if lang == 'sh'
|
|
|
|
|
pre['data-language'] = lang
|
|
|
|
|
|
|
|
|
|
toc = doc # .docs-content
|
|
|
|
|
.parent # .row
|
|
|
|
|
.at_css('.sidebar')
|
|
|
|
|
toc['class'] = '_toc'
|
|
|
|
|
toc.css('a').each do |a|
|
|
|
|
|
a['class'] = '_toc-link'
|
|
|
|
|
a.parent.remove if a.content == 'Community Discussion'
|
|
|
|
|
pre.remove_attribute('class')
|
|
|
|
|
pre.content = pre.content
|
|
|
|
|
node.replace(pre)
|
|
|
|
|
end
|
|
|
|
|
toc.css('ul').attr 'class', '_toc-list'
|
|
|
|
|
|
|
|
|
|
h1 = header.at_css('h1')
|
|
|
|
|
h1.content = h1.content
|
|
|
|
|
.titleize
|
|
|
|
|
.sub(/\bEnv\b/, 'env')
|
|
|
|
|
.sub(/\.[A-Z]/) { |s| s.downcase }
|
|
|
|
|
.sub(/\.babelrc/i, '.babelrc')
|
|
|
|
|
.sub('Common Js', 'CommonJS')
|
|
|
|
|
.sub('J Script', 'JScript')
|
|
|
|
|
.sub(/regexp/i, 'RegExp')
|
|
|
|
|
.sub(/api|Es(\d+)|cli|jsx?|[au]md/i) { |s| s.upcase }
|
|
|
|
|
|
|
|
|
|
doc.children.before toc
|
|
|
|
|
doc.children.before header.at_css 'p'
|
|
|
|
|
doc.children.before h1
|
|
|
|
|
css('code').remove_attr('class')
|
|
|
|
|
|
|
|
|
|
doc
|
|
|
|
|
end
|
|
|
|
|