diff --git a/lib/docs/core/filter.rb b/lib/docs/core/filter.rb index bbc7135e..5be77883 100644 --- a/lib/docs/core/filter.rb +++ b/lib/docs/core/filter.rb @@ -91,17 +91,6 @@ module Docs super end - def decode_cloudflare_email(str) - mask = "0x#{str[0..1]}".hex | 0 - result = '' - - str.chars.drop(2).each_slice(2) do |slice| - result += "%" + "0#{("0x#{slice.join}".hex ^ mask).to_s(16)}"[-2..-1] - end - - URI.decode(result) - end - def clean_path(path) path = path.gsub %r{[!;:]}, '-' path = path.gsub %r{\+}, '_plus_' diff --git a/lib/docs/filters/ansible/clean_html.rb b/lib/docs/filters/ansible/clean_html.rb index 2eb56df2..f24d0d01 100644 --- a/lib/docs/filters/ansible/clean_html.rb +++ b/lib/docs/filters/ansible/clean_html.rb @@ -4,10 +4,6 @@ module Docs def call @doc = at_css('#page-content') - css('.__cf_email__').each do |node| - node.replace(decode_cloudflare_email(node['data-cfemail'])) - end - doc end end diff --git a/lib/docs/filters/bootstrap/clean_html_v3.rb b/lib/docs/filters/bootstrap/clean_html_v3.rb index ddd7990a..60581dbc 100644 --- a/lib/docs/filters/bootstrap/clean_html_v3.rb +++ b/lib/docs/filters/bootstrap/clean_html_v3.rb @@ -39,10 +39,6 @@ module Docs node['class'] = 'col' end - css('.__cf_email__').each do |node| - node.replace(decode_cloudflare_email(node['data-cfemail'])) - end - css('figure.highlight').each do |node| code = node.at_css('code') node['data-language'] = code['data-lang'] diff --git a/lib/docs/filters/bootstrap/clean_html_v4.rb b/lib/docs/filters/bootstrap/clean_html_v4.rb index c7354f13..2e46c159 100644 --- a/lib/docs/filters/bootstrap/clean_html_v4.rb +++ b/lib/docs/filters/bootstrap/clean_html_v4.rb @@ -40,10 +40,6 @@ module Docs node['class'] = 'col' end - css('.__cf_email__').each do |node| - node.replace(decode_cloudflare_email(node['data-cfemail'])) - end - css('.highlight').each do |node| code = node.at_css('code') node['data-language'] = code['data-lang'] diff --git a/lib/docs/filters/core/parse_cf_email.rb b/lib/docs/filters/core/parse_cf_email.rb new file mode 100644 index 00000000..628b1429 --- /dev/null +++ b/lib/docs/filters/core/parse_cf_email.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Docs + class ParseCfEmailFilter < Filter + def call + css('.__cf_email__').each do |node| + str = node['data-cfemail'] + mask = "0x#{str[0..1]}".hex | 0 + result = '' + + str.chars.drop(2).each_slice(2) do |slice| + result += "%" + "0#{("0x#{slice.join}".hex ^ mask).to_s(16)}"[-2..-1] + end + + node.replace(URI.decode(result)) + end + + doc + end + end +end diff --git a/lib/docs/filters/flow/clean_html.rb b/lib/docs/filters/flow/clean_html.rb index df7e6f26..50269f8a 100644 --- a/lib/docs/filters/flow/clean_html.rb +++ b/lib/docs/filters/flow/clean_html.rb @@ -45,10 +45,6 @@ module Docs end end - css('.__cf_email__').each do |node| - node.replace(decode_cloudflare_email(node['data-cfemail'])) - end - css('.editor').each do |node| pre = node.at_css('.editor-code > pre') pre['data-language'] = 'javascript' diff --git a/lib/docs/filters/laravel/clean_html.rb b/lib/docs/filters/laravel/clean_html.rb index 3d711fe7..fb008028 100644 --- a/lib/docs/filters/laravel/clean_html.rb +++ b/lib/docs/filters/laravel/clean_html.rb @@ -8,10 +8,6 @@ module Docs other end - css('a.__cf_email__').each do |node| - node.replace(decode_cloudflare_email(node['data-cfemail'])) - end - # Remove code highlighting css('pre').each do |node| node.content = node.content diff --git a/lib/docs/filters/node/clean_html.rb b/lib/docs/filters/node/clean_html.rb index 32db7055..cd118927 100644 --- a/lib/docs/filters/node/clean_html.rb +++ b/lib/docs/filters/node/clean_html.rb @@ -22,10 +22,6 @@ module Docs node.content = node.content end - css('.__cf_email__').each do |node| - node.replace(decode_cloudflare_email(node['data-cfemail'])) - end - doc end end diff --git a/lib/docs/filters/vue/clean_html.rb b/lib/docs/filters/vue/clean_html.rb index 9c11608a..e9fa8f67 100644 --- a/lib/docs/filters/vue/clean_html.rb +++ b/lib/docs/filters/vue/clean_html.rb @@ -9,10 +9,6 @@ module Docs css('.demo', '.guide-links', '.footer', '#ad').remove - css('.__cf_email__').each do |node| - node.replace(decode_cloudflare_email(node['data-cfemail'])) - end - # Remove code highlighting css('figure').each do |node| node.name = 'pre' diff --git a/lib/docs/filters/yarn/clean_html.rb b/lib/docs/filters/yarn/clean_html.rb index d3e24643..6aceb70a 100644 --- a/lib/docs/filters/yarn/clean_html.rb +++ b/lib/docs/filters/yarn/clean_html.rb @@ -43,10 +43,6 @@ module Docs end end - css('.__cf_email__').each do |node| - node.replace(decode_cloudflare_email(node['data-cfemail'])) - end - css('div.highlighter-rouge').each do |node| node['data-language'] = node['class'][/language-(\w+)/, 1] if node['class'] node.content = node.content.strip diff --git a/lib/docs/scrapers/ansible.rb b/lib/docs/scrapers/ansible.rb index 8588c99e..600178f4 100644 --- a/lib/docs/scrapers/ansible.rb +++ b/lib/docs/scrapers/ansible.rb @@ -7,7 +7,7 @@ module Docs code: 'https://github.com/ansible/ansible' } - html_filters.push 'ansible/entries', 'ansible/clean_html', 'sphinx/clean_html' + html_filters.push 'ansible/entries', 'sphinx/clean_html', 'parse_cf_email' options[:skip] = %w( glossary.html diff --git a/lib/docs/scrapers/bootstrap.rb b/lib/docs/scrapers/bootstrap.rb index 859998a9..ca0aa731 100644 --- a/lib/docs/scrapers/bootstrap.rb +++ b/lib/docs/scrapers/bootstrap.rb @@ -15,6 +15,8 @@ module Docs Documentation licensed under the Creative Commons Attribution License v3.0. HTML + html_filters.push 'parse_cf_email' + version '4' do self.release = '4.0.0' self.base_url = 'https://getbootstrap.com/docs/4.0/' diff --git a/lib/docs/scrapers/flow.rb b/lib/docs/scrapers/flow.rb index cbf95f5c..b82e51f0 100644 --- a/lib/docs/scrapers/flow.rb +++ b/lib/docs/scrapers/flow.rb @@ -8,7 +8,7 @@ module Docs code: 'https://github.com/facebook/flow' } - html_filters.push 'flow/entries', 'flow/clean_html', 'title' + html_filters.push 'flow/entries', 'flow/clean_html', 'title', 'parse_cf_email' options[:trailing_slash] = false options[:root_title] = 'Flow' diff --git a/lib/docs/scrapers/laravel.rb b/lib/docs/scrapers/laravel.rb index 5bbc299a..4678ae66 100644 --- a/lib/docs/scrapers/laravel.rb +++ b/lib/docs/scrapers/laravel.rb @@ -7,7 +7,7 @@ module Docs code: 'https://github.com/laravel/laravel' } - html_filters.push 'laravel/entries', 'laravel/clean_html' + html_filters.push 'laravel/entries', 'laravel/clean_html', 'parse_cf_email' options[:container] = ->(filter) { filter.subpath.start_with?('/api') ? '#content' : '.docs-wrapper' diff --git a/lib/docs/scrapers/node.rb b/lib/docs/scrapers/node.rb index fdaf23d2..ba987465 100644 --- a/lib/docs/scrapers/node.rb +++ b/lib/docs/scrapers/node.rb @@ -8,7 +8,7 @@ module Docs code: 'https://github.com/nodejs/node' } - html_filters.push 'node/clean_html', 'node/entries', 'title' + html_filters.push 'node/clean_html', 'node/entries', 'title', 'parse_cf_email' options[:title] = false options[:root_title] = 'Node.js' diff --git a/lib/docs/scrapers/vue.rb b/lib/docs/scrapers/vue.rb index e8e29406..acaeb65d 100644 --- a/lib/docs/scrapers/vue.rb +++ b/lib/docs/scrapers/vue.rb @@ -8,7 +8,7 @@ module Docs code: 'https://github.com/vuejs/vue' } - html_filters.push 'vue/entries', 'vue/clean_html' + html_filters.push 'vue/entries', 'vue/clean_html', 'parse_cf_email' options[:only_patterns] = [/guide\//, /api\//] options[:skip] = %w(guide/team.html) diff --git a/lib/docs/scrapers/yarn.rb b/lib/docs/scrapers/yarn.rb index 8c41dd8c..230d2871 100644 --- a/lib/docs/scrapers/yarn.rb +++ b/lib/docs/scrapers/yarn.rb @@ -8,7 +8,7 @@ module Docs code: 'https://github.com/yarnpkg/yarn' } - html_filters.push 'yarn/entries', 'yarn/clean_html', 'title' + html_filters.push 'yarn/entries', 'yarn/clean_html', 'title', 'parse_cf_email' options[:root_title] = 'Yarn' options[:trailing_slash] = false