History

Update MDN docs

Thibaut Courouble committed 7 years ago

Commit f1cc4a71 parent 9e37ff58 files · +149 −17Browse files

Unified · Split

8 files
  1. assets/stylesheets/pages/_mdn.scss +25 −0
  2. lib/docs/filters/css/entries.rb +17 −10
  3. lib/docs/filters/dom/clean_html.rb +1 −1
  4. lib/docs/filters/dom/entries.rb +12 −2
  5. lib/docs/filters/html/entries.rb +1 −1
  6. lib/docs/filters/javascript/clean_html.rb +2 −2
  7. lib/docs/filters/javascript/entries.rb +1 −1
  8. lib/docs/filters/mdn/clean_html.rb +90 −0
assets/stylesheets/pages/_mdn.scss+25−0
@@ -30,6 +30,7 @@ · 29 unmodified lines
3030 .notice,
3131 .warning,
3232 .overheadIndicator,
33+ .blockIndicator,
3334 .syntaxbox, // CSS, JavaScript
3435 .twopartsyntaxbox, // CSS
3536 .inheritsbox, // JavaScript
@@ -104,4 +105,28 @@ · 68 unmodified lines
104105 .cleared { clear: both; } // CSS/box-shadow
105106
106107 code > strong { font-weight: normal; }
108+
109+ // Compatibility tablees
110+
111+ .bc-github-link {
112+ float: right;
113+ font-size: .75rem;
114+ }
115+
116+ .bc-supports-yes, .bc-supports-yes + dd, .bc-supports-yes + dd + dd { background: var(--noteGreenBackground); }
117+ .bc-supports-partial, .bc-supports-partial + dd, .bc-supports-partial + dd + dd { background: var(--noteOrangeBackground); }
118+ .bc-supports-no, .bc-supports-no + dd, .bc-supports-no + dd + dd { background: var(--noteRedBackground); }
119+
120+ .bc-table {
121+ min-width: 100%;
122+
123+ dl {
124+ margin: .25rem 0 0;
125+ padding: .25rem 0 0;
126+ font-size: .75rem;
127+ border-top: 1px solid var(--boxBorder);
128+ }
129+
130+ dd { margin: 0; }
131+ }
107132 }
lib/docs/filters/css/entries.rb+17−10
@@ -6,13 +6,16 @@ module Docs · 5 unmodified lines
66 'CSS_Background_and_Borders' => 'Backgrounds & Borders',
77 'CSS_Columns' => 'Multi-column Layout',
88 'CSS_Flexible_Box_Layout' => 'Flexible Box Layout',
9+ 'CSS_Fonts' => 'Fonts',
910 'CSS_Grid_Layout' => 'Grid Layout',
1011 'CSS_Images' => 'Images',
1112 'CSS_Lists_and_Counters' => 'Lists',
1213 'CSS_Transforms' => 'Transforms',
1314 'Media_Queries' => 'Media Queries',
15+ 'filter-function' => 'Filter Effects',
1416 'transform-function' => 'Transforms',
1517 '@media' => 'Media Queries',
18+ 'overscroll' => 'Overscroll',
1619 'text-size-adjust' => 'Miscellaneous',
1720 'resolved_value' => 'Miscellaneous',
1821 'touch-action' => 'Miscellaneous',
@@ -42,7 +45,7 @@ module Docs · 23 unmodified lines
4245 end
4346
4447 def get_type
45− if slug.include?('-webkit') || slug.include?('-moz')
48+ if slug.include?('-webkit') || slug.include?('-moz') || slug.include?('-ms')
4649 'Extensions'
4750 elsif type = TYPE_BY_PATH[slug.split('/').first]
4851 type
@@ -66,19 +69,22 @@ module Docs · 17 unmodified lines
6669 'Pseudo-Elements'
6770 elsif name.start_with?(':')
6871 'Selectors'
72+ elsif name.start_with?('display-')
73+ 'Display'
6974 else
7075 'Miscellaneous'
7176 end
7277 end
7378
7479 STATUSES = {
75− 'spec-Living' => 0,
76− 'spec-REC' => 1,
77− 'spec-CR' => 2,
78− 'spec-PR' => 3,
79− 'spec-LC' => 4,
80− 'spec-WD' => 5,
81− 'spec-ED' => 6
80+ 'spec-Living' => 0,
81+ 'spec-REC' => 1,
82+ 'spec-CR' => 2,
83+ 'spec-PR' => 3,
84+ 'spec-LC' => 4,
85+ 'spec-WD' => 5,
86+ 'spec-ED' => 6,
87+ 'spec-Obsolete' => 7
8288 }
8389
8490 PRIORITY_STATUSES = %w(spec-REC spec-CR)
@@ -86,6 +92,7 @@ module Docs · 1 unmodified line
8692
8793 def get_spec
8894 return unless table = at_css('#Specifications + table') || css('.standard-table').last
95+
8996 specs = table.css('tbody tr').to_a
9097 # [link, span]
9198 specs.map! { |node| [node.at_css('> td:nth-child(1) > a'), node.at_css('> td:nth-child(2) > span')] }
@@ -110,8 +117,8 @@ module Docs · 18 unmodified lines
110117 'shape' => [
111118 %w(rect() Syntax) ],
112119 'timing-function' => [
113− %w(cubic-bezier() The_cubic-bezier()_class_of_timing-functions),
114− %w(steps() The_steps()_class_of_timing-functions),
120+ %w(cubic-bezier()),
121+ %w(steps()),
115122 %w(linear linear),
116123 %w(ease ease),
117124 %w(ease-in ease-in),
lib/docs/filters/dom/clean_html.rb+1−1
@@ -30,7 +30,7 @@ module Docs · 29 unmodified lines
3030 end
3131
3232 # Remove <div> wrapping .overheadIndicator
33− css('div > .overheadIndicator:first-child:last-child').each do |node|
33+ css('div > .overheadIndicator:first-child:last-child', 'div > .blockIndicator:first-child:last-child').each do |node|
3434 node.parent.replace(node)
3535 end
3636
lib/docs/filters/dom/entries.rb+12−2
@@ -6,6 +6,7 @@ module Docs · 5 unmodified lines
66 'EXT_' => 'WebGL',
77 'OES_' => 'WebGL',
88 'WEBGL_' => 'WebGL',
9+ 'Sensor API' => 'Sensors',
910 'Ambient Light' => 'Ambient Light',
1011 'Audio' => 'Audio',
1112 'Battery Status' => 'Battery Status',
@@ -22,10 +23,12 @@ module Docs · 10 unmodified lines
2223 'Encrypted Media Extensions' => 'Encrypted Media',
2324 'Fetch' => 'Fetch',
2425 'File API' => 'File',
26+ 'Fullscreen' => 'Fullscreen',
2527 'Geolocation' => 'Geolocation',
2628 'Geometry' => 'Geometry',
2729 'High Resolution Time' => 'Performance',
2830 'Intersection' => 'Intersection Observer',
31+ 'Keyboard' => 'Keyboard',
2932 'Media Capabilities' => 'Media',
3033 'Media Capture' => 'Media',
3134 'Media Session' => 'Media',
@@ -35,6 +38,7 @@ module Docs · 3 unmodified lines
3538 'MIDI' => 'Audio',
3639 'Navigation Timing' => 'Performance',
3740 'Network Information' => 'Network Information',
41+ 'Orientation Sensor' => 'Sensors',
3842 'Payment' => 'Payments',
3943 'Performance Timeline' => 'Performance',
4044 'Pointer Events' => 'Pointer Events',
@@ -53,11 +57,13 @@ module Docs · 12 unmodified lines
5357 'Web App Manifest' => 'Web App Manifest',
5458 'Budget' => 'Budget',
5559 'Web Authentication' => 'Authentication',
60+ 'Web Locks' => 'Locks',
5661 'Web Workers' => 'Web Workers',
5762 'WebGL' => 'WebGL',
5863 'WebRTC' => 'WebRTC',
5964 'WebUSB' => 'WebUSB',
60− 'WebVR' => 'WebVR' }
65+ 'WebVR' => 'WebVR',
66+ 'WebVTT' => 'WebVTT' }
6167
6268 TYPE_BY_NAME_STARTS_WITH = {
6369 'AbortController' => 'Fetch',
@@ -89,10 +95,12 @@ module Docs · 25 unmodified lines
8995 'Fetch' => 'Fetch',
9096 'File' => 'File',
9197 'GlobalEventHandlers' => 'GlobalEventHandlers',
98+ 'HMDVR' => 'WebVR',
9299 'history' => 'History',
93100 'HTML Drag' => 'Drag & Drop',
94101 'HTML' => 'Elements',
95102 'IDB' => 'IndexedDB',
103+ 'Keyboard' => 'Keyboard',
96104 'location' => 'Location',
97105 'navigator' => 'Navigator',
98106 'MediaKeySession' => 'Encrypted Media',
@@ -122,6 +130,7 @@ module Docs · 23 unmodified lines
122130 'StyleSheet' => 'CSS',
123131 'Stylesheet' => 'CSS',
124132 'SVG' => 'SVG',
133+ 'TextTrack' => 'WebVTT',
125134 'TimeRanges' => 'Media',
126135 'timing' => 'Performance',
127136 'Timing' => 'Performance',
@@ -160,6 +169,7 @@ module Docs · 32 unmodified lines
160169 'timing' => 'Performance',
161170 'Timing' => 'Performance',
162171 'udio' => 'Audio',
172+ 'VRDevice' => 'WebVR',
163173 'WebGL' => 'WebGL',
164174 'WEBGL' => 'WebGL',
165175 'WebRTC' => 'WebRTC',
@@ -239,7 +249,7 @@ module Docs · 73 unmodified lines
239249
240250 def include_default_entry?
241251 return true if type == 'Console'
242− return true unless node = doc.at_css('.overheadIndicator')
252+ return true unless node = doc.at_css('.overheadIndicator, .blockIndicator')
243253 node = node.parent while node.parent != doc
244254 return true if node.previous_element.try(:name).in?(%w(h2 h3))
245255 content = node.content
lib/docs/filters/html/entries.rb+1−1
@@ -28,7 +28,7 @@ module Docs · 27 unmodified lines
2828
2929 def include_default_entry?
3030 return false if %w(Element/Heading_Elements).include?(slug)
31− (node = doc.at_css '.overheadIndicator').nil? || node.content.exclude?('not on a standards track')
31+ (node = doc.at_css '.overheadIndicator, .blockIndicator').nil? || node.content.exclude?('not on a standards track')
3232 end
3333
3434 def additional_entries
lib/docs/filters/javascript/clean_html.rb+2−2
@@ -11,12 +11,12 @@ module Docs · 10 unmodified lines
1111
1212 def other
1313 # Remove "style" attribute
14− css('.inheritsbox', '.overheadIndicator').each do |node|
14+ css('.inheritsbox', '.overheadIndicator', '.blockIndicator').each do |node|
1515 node.remove_attribute 'style'
1616 end
1717
1818 # Remove <div> wrapping .overheadIndicator
19− css('div > .overheadIndicator:first-child:last-child').each do |node|
19+ css('div > .overheadIndicator:first-child:last-child', 'div > .blockIndicator:first-child:last-child').each do |node|
2020 node.parent.replace(node)
2121 end
2222 end
lib/docs/filters/javascript/entries.rb+1−1
@@ -88,7 +88,7 @@ module Docs · 87 unmodified lines
8888 end
8989
9090 def include_default_entry?
91− node = doc.at_css '.overheadIndicator, .warning'
91+ node = doc.at_css '.blockIndicator, .warning'
9292
9393 # Can't use :first-child because #doc is a DocumentFragment
9494 return true unless node && node.parent == doc && !node.previous_element
lib/docs/filters/mdn/clean_html.rb+90−0
@@ -14,6 +14,8 @@ module Docs · 13 unmodified lines
1414 '#Quick_Links',
1515 'hr']
1616
17+ BROWSER_UNNECESSARY_CLASS_REGEX = /\s*bc-browser[\w_-]+/
18+
1719 def call
1820 css(*REMOVE_NODES).remove
1921
@@ -61,6 +63,94 @@ module Docs · 41 unmodified lines
6163 node.previous_element << node
6264 end
6365
66+ # New compatibility tables
67+
68+ css('.bc-data #Legend + dl', '.bc-data #Legend', '.bc-data #Legend_2 + dl', '.bc-data #Legend_2', '.bc-browser-name').remove
69+
70+ css('abbr.only-icon[title="Full support"]',
71+ 'abbr.only-icon[title="Partial support"]',
72+ 'abbr.only-icon[title="No support"]',
73+ 'abbr.only-icon[title="See implementation notes"]').remove
74+
75+ css('.bc-data .ic-altname', '.bc-data .ic-deprecated', '.bc-data .ic-non-standard', '.bc-data .ic-experimental').each do |node|
76+ node.parent.remove
77+ end
78+
79+ css('abbr.only-icon').each do |node|
80+ node.replace(node.content)
81+ end
82+
83+ css('.bc-table .bc-platforms td', '.bc-table .bc-browsers td').each do |node|
84+ node.name = 'th'
85+ end
86+
87+ css('.bc-data').each do |node|
88+ link = node.at_css('.bc-github-link')
89+ prev = node.previous_element
90+ prev = prev.previous_element until prev.name == 'h2'
91+ prev.add_child(link)
92+
93+ node.before(node.children).remove
94+ end
95+
96+ css('.bc-table').each do |node|
97+ desktop_table = node
98+
99+ mobile_table = node.dup
100+ desktop_table.after(mobile_table)
101+
102+ if desktop_table.at_css('.bc-platform-server')
103+ server_table = node.dup
104+ mobile_table.after(server_table)
105+ end
106+
107+ desktop_columns = desktop_table.at_css('th.bc-platform-desktop')['colspan'].to_i
108+ mobile_columns = desktop_table.at_css('th.bc-platform-mobile')['colspan'].to_i
109+
110+ desktop_table.css('.bc-platform-mobile').remove
111+ desktop_table.css('.bc-platform-server').remove
112+ desktop_table.css('.bc-browsers th').to_a[(desktop_columns + 1)..-1].each(&:remove)
113+ desktop_table.css('tr:not(.bc-platforms):not(.bc-browsers)').each do |line|
114+ line.css('td').to_a[(desktop_columns)..-1].each(&:remove)
115+ end
116+
117+ mobile_table.css('.bc-platform-desktop').remove
118+ mobile_table.css('.bc-platform-server').remove
119+ mobile_table.css('.bc-browsers th').to_a[1..(desktop_columns)].each(&:remove)
120+ mobile_table.css('.bc-browsers th').to_a[(mobile_columns + 1)..-1].each(&:remove)
121+ mobile_table.css('tr:not(.bc-platforms):not(.bc-browsers)').each do |line|
122+ line.css('td').to_a[0..(desktop_columns - 1)].each(&:remove)
123+ line.css('td').to_a[(mobile_columns)..-1].each(&:remove)
124+ end
125+
126+ if server_table
127+ server_table.css('.bc-platform-desktop').remove
128+ server_table.css('.bc-platform-mobile').remove
129+ server_table.css('.bc-browsers th').to_a[1..(desktop_columns + mobile_columns)].each(&:remove)
130+ server_table.css('tr:not(.bc-platforms):not(.bc-browsers)').each do |line|
131+ line.css('td').to_a[0..(desktop_columns + mobile_columns - 1)].each(&:remove)
132+ end
133+ end
134+ end
135+
136+ # Reduce page size to make the offline bundle smaller.
137+ css('.bc-supports-unknown').remove_attr('class')
138+ css('td[class*="bc-platform"], th[class*="bc-platform"]').remove_attr('class')
139+ css('td[class*="bc-browser"], th[class*="bc-browser"]').each do |node|
140+ class_name = node['class']
141+ class_name.remove!(BROWSER_UNNECESSARY_CLASS_REGEX)
142+
143+ if class_name.present?
144+ node['class'] = class_name
145+ else
146+ node.remove_attribute('class')
147+ end
148+ end
149+
150+ css('abbr[title*="Compatibility unknown"]').each do |node|
151+ node.before(node.children).remove
152+ end
153+
64154 doc
65155 end
66156 end

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t