Skip to content

Commit e4d841d

Browse files
committed
Update React documentation (16.0.0)
1 parent 1181bd7 commit e4d841d

File tree

4 files changed

+74
-83
lines changed

4 files changed

+74
-83
lines changed

assets/javascripts/vendor/prism.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript+c+cpp+coffeescript+ruby+d+elixir+erlang+go+java+json+kotlin+lua+nginx+nim+perl+php+python+crystal+rust+scss+sql+typescript */
1+
/* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript+c+cpp+coffeescript+ruby+d+elixir+erlang+go+java+json+kotlin+lua+nginx+nim+perl+php+python+jsx+crystal+rust+scss+sql+typescript */
22
var _self = (typeof window !== 'undefined')
33
? window // if in browser
44
: (
@@ -1681,6 +1681,44 @@ Prism.languages.python= {
16811681
'punctuation' : /[{}[\];(),.:]/
16821682
};
16831683

1684+
(function(Prism) {
1685+
1686+
var javascript = Prism.util.clone(Prism.languages.javascript);
1687+
1688+
Prism.languages.jsx = Prism.languages.extend('markup', javascript);
1689+
Prism.languages.jsx.tag.pattern= /<\/?[\w\.:-]+\s*(?:\s+(?:[\w\.:-]+(?:=(?:("|')(\\?[\s\S])*?\1|[^\s'">=]+|(\{[\s\S]*?\})))?|\{\.{3}\w+\}))*\s*\/?>/i;
1690+
1691+
Prism.languages.jsx.tag.inside['attr-value'].pattern = /=(?!\{)(?:('|")[\s\S]*?(\1)|[^\s>]+)/i;
1692+
1693+
Prism.languages.insertBefore('inside', 'attr-name', {
1694+
'spread': {
1695+
pattern: /\{\.{3}\w+\}/,
1696+
inside: {
1697+
'punctuation': /\{|\}|\./,
1698+
'attr-value': /\w+/
1699+
}
1700+
}
1701+
}, Prism.languages.jsx.tag);
1702+
1703+
var jsxExpression = Prism.util.clone(Prism.languages.jsx);
1704+
1705+
delete jsxExpression.punctuation
1706+
1707+
jsxExpression = Prism.languages.insertBefore('jsx', 'operator', {
1708+
'punctuation': /=(?={)|[{}[\];(),.:]/
1709+
}, { jsx: jsxExpression });
1710+
1711+
Prism.languages.insertBefore('inside', 'attr-value',{
1712+
'script': {
1713+
// Allow for one level of nesting
1714+
pattern: /=(\{(?:\{[^}]*\}|[^}])+\})/i,
1715+
inside: jsxExpression,
1716+
'alias': 'language-javascript'
1717+
}
1718+
}, Prism.languages.jsx.tag);
1719+
1720+
}(Prism));
1721+
16841722
(function(Prism) {
16851723
Prism.languages.crystal = Prism.languages.extend('ruby', {
16861724
keyword: [

lib/docs/filters/react/clean_html.rb

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,27 @@ module Docs
22
class React
33
class CleanHtmlFilter < Filter
44
def call
5-
@doc = at_css('.inner-content, article.withtoc')
5+
@doc = at_css('article')
66

77
if root_page?
8-
at_css('h1').content = context[:root_title]
8+
at_css('h1').content = 'React Documentation'
99
end
1010

11-
css('.docs-prevnext', '.hash-link', '.edit-page-link', '.edit-github', 'a.hash', '.edit-page-block', 'a.show', 'a.hide', 'hr').remove
12-
13-
css('table h1', 'table h2', 'table h3').each do |node|
14-
table = node
15-
table = table.parent until table.name == 'table'
16-
table.replace(node)
17-
end
18-
19-
css('a.anchor', 'a.hashref').each do |node|
20-
node.parent['id'] ||= node['name'] || node['id']
21-
end
22-
23-
css('.highlight').each do |node|
24-
node.name = 'pre'
25-
node.css('.gutter').remove
26-
node['data-language'] = node.at_css('[data-lang]').try(:[], 'data-lang') || 'js'
27-
node.content = node.content.strip
28-
end
29-
30-
css('table.highlighttable').each do |node|
31-
node.replace(node.at_css('pre.highlight'))
11+
css('header', 'div[class^="css-"]', '.gatsby-resp-image-link span').each do |node|
12+
node.before(node.children).remove
3213
end
3314

34-
css('.prism').each do |node|
35-
node.name = 'pre'
36-
node['data-language'] = node['class'][/(?<=language\-)(\w+)/]
15+
css('.gatsby-highlight > pre').each do |node|
3716
node.content = node.content
17+
node['data-language'] = node['class'][/(?<=gatsby\-code\-)(\w+)/]
18+
node.remove_attribute('class')
19+
node.parent.replace(node)
3820
end
3921

40-
css('blockquote > p:first-child').each do |node|
41-
node.remove if node.content.strip == 'Note:'
42-
end
43-
44-
css('h3#props', 'h3#methods').each { |node| node.name = 'h2' }
45-
css('h4.propTitle').each { |node| node.name = 'h3' }
46-
47-
css('> div > div', '> div', 'div > span', '.props', '.prop').each do |node|
48-
node.before(node.children).remove
49-
end
50-
51-
css('a pre', 'h3 .propType').each do |node|
52-
node.name = 'code'
53-
end
22+
css('a.anchor', 'a:contains("Edit this page")', 'hr').remove
5423

55-
css('a[target]').each do |node|
56-
node.remove_attribute('target')
57-
end
24+
css('a').remove_attr('rel').remove_attr('target').remove_attr('class').remove_attr('style')
25+
css('img').remove_attr('style').remove_attr('srcset').remove_attr('sizes').remove_attr('class')
5826

5927
doc
6028
end

lib/docs/filters/react/entries.rb

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,32 @@ module Docs
22
class React
33
class EntriesFilter < Docs::EntriesFilter
44
def get_name
5-
at_css('h1').children.select(&:text?).map(&:content).join.strip
5+
at_css('article h1').content
66
end
77

88
def get_type
9-
link = at_css('.nav-docs-section .active, .toc .active')
10-
return 'Miscellaneous' unless link
11-
section = link.ancestors('.nav-docs-section, section').first
12-
type = section.at_css('h3').content.strip
13-
type
9+
link = at_css("nav a[href='#{result[:path].split('/').last}']")
10+
link.ancestors('ul').last.previous_element.content
1411
end
1512

1613
def additional_entries
1714
entries = []
1815

19-
css('.inner-content h3 code, .inner-content h4 code').each do |node|
20-
name = node.content
21-
name.remove! %r{[#\(\)]}
22-
name.remove! %r{\w+\:}
23-
name.strip!
24-
name = 'createFragmentobject' if name.include?('createFragmentobject')
25-
id = name.parameterize
26-
node.parent['id'] = id
16+
css('article h3 code, article h4 code').each do |node|
17+
next if node.previous.try(:content).present?
18+
name = node.content.strip
19+
# name.remove! %r{[#\(\)]}
20+
# name.remove! %r{\w+\:}
21+
# name.strip!
22+
# name = 'createFragmentobject' if name.include?('createFragmentobject')
2723
type = if slug == 'react-component'
2824
'Reference: Component'
2925
elsif slug == 'react-api'
3026
'Reference: React'
3127
else
3228
'Reference'
3329
end
34-
entries << [name, id, type]
35-
end
36-
37-
css('.apiIndex a pre').each do |node| # relay
38-
next unless node.parent['href'].start_with?('#')
39-
id = node.parent['href'].remove('#')
40-
name = node.content.strip
41-
sep = name.start_with?('static') ? '.' : '#'
42-
name.remove! %r{(abstract|static) }
43-
name.sub! %r{\(.*\)}, '()'
44-
name.prepend(self.name + sep)
45-
entries << [name, id]
30+
entries << [name, node.parent['id'], type]
4631
end
4732

4833
entries

lib/docs/scrapers/react.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
module Docs
22
class React < UrlScraper
33
self.name = 'React'
4-
self.type = 'react'
5-
self.release = '15.6.1'
6-
self.base_url = 'https://facebook.github.io/react/docs/'
4+
self.type = 'simple'
5+
self.release = '16.0.0'
6+
self.base_url = 'https://reactjs.org/docs/'
77
self.root_path = 'hello-world.html'
88
self.links = {
9-
home: 'https://facebook.github.io/react/',
9+
home: 'https://reactjs.org/',
1010
code: 'https://github.com/facebook/react'
1111
}
1212

1313
html_filters.push 'react/entries', 'react/clean_html'
1414

15-
options[:root_title] = 'React Documentation'
16-
options[:container] = '.documentationContent'
15+
options[:skip] = %w(
16+
codebase-overview.html
17+
design-principles.html
18+
how-to-contribute.html
19+
implementation-notes.html
20+
)
1721

1822
options[:replace_paths] = {
19-
'top-level-api.html' => 'react-api.html',
20-
'working-with-the-browser.html' => 'refs-and-the-dom.html',
21-
'interactivity-and-dynamic-uis.html' => 'state-and-lifecycle.html',
2223
'more-about-refs.html' => 'refs-and-the-dom.html',
23-
'advanced-performance.html' => 'optimizing-performance.html',
24-
'component-api.html' => 'react-component.html',
25-
'component-specs.html' => 'react-component.html',
26-
'multiple-components.html' => 'composition-vs-inheritance.html',
24+
'interactivity-and-dynamic-uis.html' => 'state-and-lifecycle.html',
25+
'working-with-the-browser.html' => 'refs-and-the-dom.html',
26+
'top-level-api.html' => 'react-api.html',
2727
}
2828

2929
options[:attribution] = <<-HTML

0 commit comments

Comments
 (0)