Add a core `rouge` filter to correctly highlight pages using Jekyll

pull/721/head
Jed Fox 7 years ago
parent 63af2153d8
commit 64ccc946fd

@ -0,0 +1,17 @@
# frozen_string_literal: true
module Docs
class RougeFilter < Filter
def call
css('div.highlighter-rouge').each do |node|
node['data-language'] = node['class'][/language-(\w+)/, 1] if node['class']
node.content = node.content.strip
node.name = 'pre'
end
css('.highlighter-rouge').remove_attr('class')
doc
end
end
end

@ -22,14 +22,6 @@ module Docs
node.name = node.name.sub(/\d/) { |i| i.to_i - 1 } unless node.name == 'h3' && node.at_css('code')
end if !at_css('h2') && at_css('h4')
css('div.highlighter-rouge').each do |node|
node['data-language'] = node['class'][/language-(\w+)/, 1] if node['class']
node.content = node.content.strip
node.name = 'pre'
end
css('.highlighter-rouge').remove_attr('class')
css('pre').each do |node|
node.content = node.content
end

@ -52,13 +52,6 @@ module Docs
node.replace(pre)
end
css('div.highlighter-rouge').each do |node|
node['data-language'] = node['class'][/language-(\w+)/, 1] if node['class']
node.content = node.content.strip
node.name = 'pre'
end
css('.highlighter-rouge').remove_attr('class')
end
end
end

@ -42,14 +42,6 @@ module Docs
node.name = node.name.sub(/\d/) { |i| i.to_i - 1 }
end
end
css('div.highlighter-rouge').each do |node|
node['data-language'] = node['class'][/language-(\w+)/, 1] if node['class']
node.content = node.content.strip
node.name = 'pre'
end
css('.highlighter-rouge').remove_attr('class')
end
end
end

@ -8,7 +8,7 @@ module Docs
code: 'https://github.com/electron/electron'
}
html_filters.push 'electron/clean_html', 'electron/entries'
html_filters.push 'electron/clean_html', 'electron/entries', 'rouge'
options[:trailing_slash] = true
options[:container] = '.page-section > .container, .page-section > .container-narrow'

@ -8,7 +8,7 @@ module Docs
code: 'https://github.com/facebook/flow'
}
html_filters.push 'flow/entries', 'flow/clean_html', 'title', 'parse_cf_email'
html_filters.push 'flow/entries', 'flow/clean_html', 'title', 'parse_cf_email', 'rouge'
options[:trailing_slash] = false
options[:root_title] = 'Flow'

@ -8,7 +8,7 @@ module Docs
code: 'https://github.com/yarnpkg/yarn'
}
html_filters.push 'yarn/entries', 'yarn/clean_html', 'title', 'parse_cf_email'
html_filters.push 'yarn/entries', 'yarn/clean_html', 'title', 'parse_cf_email', 'rouge'
options[:root_title] = 'Yarn'
options[:trailing_slash] = false

Loading…
Cancel
Save