From df2af95a54f3f6837c99749f17b939653119cf4b Mon Sep 17 00:00:00 2001 From: Thibaut Courouble Date: Sun, 16 Jul 2017 16:54:58 -0400 Subject: [PATCH] Update MDN documentations Closes #615. --- assets/stylesheets/pages/_mdn.scss | 4 +--- lib/docs/filters/dom/entries.rb | 4 ++-- lib/docs/filters/dom_events/entries.rb | 5 +++-- lib/docs/filters/http/entries.rb | 5 +++++ lib/docs/filters/javascript/clean_html.rb | 5 ----- lib/docs/filters/mdn/clean_html.rb | 16 ++++++++++++++- lib/docs/scrapers/http.rb | 24 ++++++++++------------- lib/docs/scrapers/mdn/css.rb | 1 + lib/docs/scrapers/mdn/html.rb | 2 ++ lib/docs/scrapers/mdn/mdn.rb | 2 +- 10 files changed, 40 insertions(+), 28 deletions(-) diff --git a/assets/stylesheets/pages/_mdn.scss b/assets/stylesheets/pages/_mdn.scss index 778b4cf5..b1f89f4f 100644 --- a/assets/stylesheets/pages/_mdn.scss +++ b/assets/stylesheets/pages/_mdn.scss @@ -24,7 +24,7 @@ > h3 { @extend %block-label, %label-blue; } > h4 { font-size: 1em; } - p > code { @extend %label; } + p > code, li > code { @extend %label; } > .note, .notice, @@ -104,6 +104,4 @@ .cleared { clear: both; } // CSS/box-shadow code > strong { font-weight: normal; } - - #compat-desktop, #compat-mobile { @extend ._table; } } diff --git a/lib/docs/filters/dom/entries.rb b/lib/docs/filters/dom/entries.rb index e418bbd5..4a1fc343 100644 --- a/lib/docs/filters/dom/entries.rb +++ b/lib/docs/filters/dom/entries.rb @@ -225,8 +225,8 @@ module Docs entries = [] if slug == 'history' || slug == 'XMLHttpRequest' - css('dt a[title*="not yet been written"]').each do |node| - next if node.parent.at_css('.obsolete') + css('dt a[href^="https://developer.mozilla.org"]').each do |node| + next if node.parent.at_css('.obsolete') || node.content.include?('moz') name = node.content.sub('History', 'history') id = node.parent['id'] = name.parameterize entries << [name, id] diff --git a/lib/docs/filters/dom_events/entries.rb b/lib/docs/filters/dom_events/entries.rb index 608caa9e..bc34f1ea 100644 --- a/lib/docs/filters/dom_events/entries.rb +++ b/lib/docs/filters/dom_events/entries.rb @@ -8,7 +8,7 @@ module Docs 'Clipboard' => 'Clipboard', 'CSS' => 'CSS', 'Drag' => 'Drag & Drop', - 'Focus' => 'Focus', + 'Fetch' => 'Fetch', 'Fullscreen' => 'Fullscreen', 'Gamepad' => 'Gamepad', 'HashChange' => 'History', @@ -43,7 +43,8 @@ module Docs 'WebRTC' => 'WebRTC', 'WebVR' => 'WebVR', 'Wheel' => 'Mouse', - 'Worker' => 'Web Workers' } + 'Worker' => 'Web Workers', + 'Focus' => 'Focus' } FORM_SLUGS = %w(change compositionend compositionstart compositionupdate input invalid reset select submit) diff --git a/lib/docs/filters/http/entries.rb b/lib/docs/filters/http/entries.rb index a6793f86..027d7fde 100644 --- a/lib/docs/filters/http/entries.rb +++ b/lib/docs/filters/http/entries.rb @@ -83,6 +83,11 @@ module Docs [2, 5, 6], [3, 4], [] + ], + 'rfc5023' => [ + [], + [], + [] ] } diff --git a/lib/docs/filters/javascript/clean_html.rb b/lib/docs/filters/javascript/clean_html.rb index f4e97865..5f7ebcb3 100644 --- a/lib/docs/filters/javascript/clean_html.rb +++ b/lib/docs/filters/javascript/clean_html.rb @@ -7,11 +7,6 @@ module Docs end def root - # Move "Global Objects" lists to the same level as the other ones - css('#Global_Objects + p').remove - div = at_css '#Global_Objects + div' - div.css('h3').each { |node| node.name = 'h2' } - at_css('#Global_Objects').replace(div.children) end def other diff --git a/lib/docs/filters/mdn/clean_html.rb b/lib/docs/filters/mdn/clean_html.rb index 84829aba..bd443cb0 100644 --- a/lib/docs/filters/mdn/clean_html.rb +++ b/lib/docs/filters/mdn/clean_html.rb @@ -21,12 +21,16 @@ module Docs node.name = 'th' end - css('nobr', 'span[style*="font"]', 'pre code', 'h2 strong').each do |node| + css('nobr', 'span[style*="font"]', 'pre code', 'h2 strong', 'div:not([class])', 'span.seoSummary').each do |node| node.before(node.children).remove end css('h2[style]', 'pre[style]', 'th[style]', 'div[style*="line-height"]', 'table[style]', 'pre p[style]').remove_attr('style') + css('a[title]', 'span[title]').remove_attr('title') + css('a.glossaryLink').remove_attr('class') + css('*[lang]').remove_attr('lang') + css('h2 > a[name]', 'h3 > a[name]').each do |node| node.parent['id'] = node['name'] node.before(node.content).remove @@ -37,6 +41,16 @@ module Docs node.remove_attribute('class') end + css('pre.eval').each do |node| + node.content = node.content + node.remove_attribute('class') + end + + css('table').each do |node| + node.before %(
) + node.previous_element << node + end + doc end end diff --git a/lib/docs/scrapers/http.rb b/lib/docs/scrapers/http.rb index 81f81ee3..881c0545 100644 --- a/lib/docs/scrapers/http.rb +++ b/lib/docs/scrapers/http.rb @@ -8,26 +8,21 @@ module Docs html_filters.push 'http/clean_html', 'http/entries', 'title' options[:root_title] = 'HTTP' - options[:title] = ->(filter) { - filter.current_url.host == 'tools.ietf.org' ? false : filter.default_title - } - options[:container] = ->(filter) { - filter.current_url.host == 'tools.ietf.org' ? '.content' : nil - } - options[:skip_links] = ->(filter) { - filter.current_url.host == 'tools.ietf.org' ? true : false - } - options[:fix_urls] = ->(url) { + options[:title] = ->(filter) { filter.current_url.host == 'tools.ietf.org' ? false : filter.default_title } + options[:container] = ->(filter) { filter.current_url.host == 'tools.ietf.org' ? '.content' : nil } + options[:skip_links] = ->(filter) { filter.current_url.host == 'tools.ietf.org' ? true : false } + options[:fix_urls] = ->(url) do url.sub! %r{(Status/\d\d\d)_[A-Z].+}, '\1' url - } - options[:attribution] = ->(filter) { + end + + options[:attribution] = ->(filter) do if filter.current_url.host == 'tools.ietf.org' "© document authors. All rights reserved." else Docs::Mdn.options[:attribution] end - } + end def initial_urls %w(https://developer.mozilla.org/en-US/docs/Web/HTTP @@ -38,7 +33,8 @@ module Docs https://tools.ietf.org/html/rfc7232 https://tools.ietf.org/html/rfc7233 https://tools.ietf.org/html/rfc7234 - https://tools.ietf.org/html/rfc7235) + https://tools.ietf.org/html/rfc7235 + https://tools.ietf.org/html/rfc5023) end end end diff --git a/lib/docs/scrapers/mdn/css.rb b/lib/docs/scrapers/mdn/css.rb index 56daa563..4c44f1f1 100644 --- a/lib/docs/scrapers/mdn/css.rb +++ b/lib/docs/scrapers/mdn/css.rb @@ -21,6 +21,7 @@ module Docs '/var' => '/var()', '/element' => '/element()', '/Flexbox' => '/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes', + '/flexbox' => '/CSS_Flexible_Box_Layout/Using_CSS_flexible_boxes', '/currentColor' => '/color_value' } diff --git a/lib/docs/scrapers/mdn/html.rb b/lib/docs/scrapers/mdn/html.rb index 9e5e7c8a..4b28cefd 100644 --- a/lib/docs/scrapers/mdn/html.rb +++ b/lib/docs/scrapers/mdn/html.rb @@ -1,5 +1,7 @@ module Docs class Html < Mdn + prepend FixInternalUrlsBehavior + self.name = 'HTML' self.base_url = 'https://developer.mozilla.org/en-US/docs/Web/HTML' diff --git a/lib/docs/scrapers/mdn/mdn.rb b/lib/docs/scrapers/mdn/mdn.rb index 1c01ccd7..ae7a8533 100644 --- a/lib/docs/scrapers/mdn/mdn.rb +++ b/lib/docs/scrapers/mdn/mdn.rb @@ -6,7 +6,7 @@ module Docs params[:raw] = 1 params[:macros] = 1 - html_filters.push 'mdn/clean_html' + html_filters.push 'mdn/clean_html', 'images' text_filters.insert_before 'attribution', 'mdn/contribute_link' options[:trailing_slash] = false