Update React documentation (16.0.0)

pull/667/merge
Thibaut Courouble 7 years ago
parent 1181bd7498
commit e4d841d595

@ -1,4 +1,4 @@
/* 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 */ /* 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 */
var _self = (typeof window !== 'undefined') var _self = (typeof window !== 'undefined')
? window // if in browser ? window // if in browser
: ( : (
@ -1681,6 +1681,44 @@ Prism.languages.python= {
'punctuation' : /[{}[\];(),.:]/ 'punctuation' : /[{}[\];(),.:]/
}; };
(function(Prism) {
var javascript = Prism.util.clone(Prism.languages.javascript);
Prism.languages.jsx = Prism.languages.extend('markup', javascript);
Prism.languages.jsx.tag.pattern= /<\/?[\w\.:-]+\s*(?:\s+(?:[\w\.:-]+(?:=(?:("|')(\\?[\s\S])*?\1|[^\s'">=]+|(\{[\s\S]*?\})))?|\{\.{3}\w+\}))*\s*\/?>/i;
Prism.languages.jsx.tag.inside['attr-value'].pattern = /=(?!\{)(?:('|")[\s\S]*?(\1)|[^\s>]+)/i;
Prism.languages.insertBefore('inside', 'attr-name', {
'spread': {
pattern: /\{\.{3}\w+\}/,
inside: {
'punctuation': /\{|\}|\./,
'attr-value': /\w+/
}
}
}, Prism.languages.jsx.tag);
var jsxExpression = Prism.util.clone(Prism.languages.jsx);
delete jsxExpression.punctuation
jsxExpression = Prism.languages.insertBefore('jsx', 'operator', {
'punctuation': /=(?={)|[{}[\];(),.:]/
}, { jsx: jsxExpression });
Prism.languages.insertBefore('inside', 'attr-value',{
'script': {
// Allow for one level of nesting
pattern: /=(\{(?:\{[^}]*\}|[^}])+\})/i,
inside: jsxExpression,
'alias': 'language-javascript'
}
}, Prism.languages.jsx.tag);
}(Prism));
(function(Prism) { (function(Prism) {
Prism.languages.crystal = Prism.languages.extend('ruby', { Prism.languages.crystal = Prism.languages.extend('ruby', {
keyword: [ keyword: [

@ -2,59 +2,27 @@ module Docs
class React class React
class CleanHtmlFilter < Filter class CleanHtmlFilter < Filter
def call def call
@doc = at_css('.inner-content, article.withtoc') @doc = at_css('article')
if root_page? if root_page?
at_css('h1').content = context[:root_title] at_css('h1').content = 'React Documentation'
end end
css('.docs-prevnext', '.hash-link', '.edit-page-link', '.edit-github', 'a.hash', '.edit-page-block', 'a.show', 'a.hide', 'hr').remove css('header', 'div[class^="css-"]', '.gatsby-resp-image-link span').each do |node|
node.before(node.children).remove
css('table h1', 'table h2', 'table h3').each do |node|
table = node
table = table.parent until table.name == 'table'
table.replace(node)
end
css('a.anchor', 'a.hashref').each do |node|
node.parent['id'] ||= node['name'] || node['id']
end
css('.highlight').each do |node|
node.name = 'pre'
node.css('.gutter').remove
node['data-language'] = node.at_css('[data-lang]').try(:[], 'data-lang') || 'js'
node.content = node.content.strip
end
css('table.highlighttable').each do |node|
node.replace(node.at_css('pre.highlight'))
end end
css('.prism').each do |node| css('.gatsby-highlight > pre').each do |node|
node.name = 'pre'
node['data-language'] = node['class'][/(?<=language\-)(\w+)/]
node.content = node.content node.content = node.content
node['data-language'] = node['class'][/(?<=gatsby\-code\-)(\w+)/]
node.remove_attribute('class')
node.parent.replace(node)
end end
css('blockquote > p:first-child').each do |node| css('a.anchor', 'a:contains("Edit this page")', 'hr').remove
node.remove if node.content.strip == 'Note:'
end
css('h3#props', 'h3#methods').each { |node| node.name = 'h2' }
css('h4.propTitle').each { |node| node.name = 'h3' }
css('> div > div', '> div', 'div > span', '.props', '.prop').each do |node|
node.before(node.children).remove
end
css('a pre', 'h3 .propType').each do |node|
node.name = 'code'
end
css('a[target]').each do |node| css('a').remove_attr('rel').remove_attr('target').remove_attr('class').remove_attr('style')
node.remove_attribute('target') css('img').remove_attr('style').remove_attr('srcset').remove_attr('sizes').remove_attr('class')
end
doc doc
end end

@ -2,28 +2,24 @@ module Docs
class React class React
class EntriesFilter < Docs::EntriesFilter class EntriesFilter < Docs::EntriesFilter
def get_name def get_name
at_css('h1').children.select(&:text?).map(&:content).join.strip at_css('article h1').content
end end
def get_type def get_type
link = at_css('.nav-docs-section .active, .toc .active') link = at_css("nav a[href='#{result[:path].split('/').last}']")
return 'Miscellaneous' unless link link.ancestors('ul').last.previous_element.content
section = link.ancestors('.nav-docs-section, section').first
type = section.at_css('h3').content.strip
type
end end
def additional_entries def additional_entries
entries = [] entries = []
css('.inner-content h3 code, .inner-content h4 code').each do |node| css('article h3 code, article h4 code').each do |node|
name = node.content next if node.previous.try(:content).present?
name.remove! %r{[#\(\)]} name = node.content.strip
name.remove! %r{\w+\:} # name.remove! %r{[#\(\)]}
name.strip! # name.remove! %r{\w+\:}
name = 'createFragmentobject' if name.include?('createFragmentobject') # name.strip!
id = name.parameterize # name = 'createFragmentobject' if name.include?('createFragmentobject')
node.parent['id'] = id
type = if slug == 'react-component' type = if slug == 'react-component'
'Reference: Component' 'Reference: Component'
elsif slug == 'react-api' elsif slug == 'react-api'
@ -31,18 +27,7 @@ module Docs
else else
'Reference' 'Reference'
end end
entries << [name, id, type] entries << [name, node.parent['id'], type]
end
css('.apiIndex a pre').each do |node| # relay
next unless node.parent['href'].start_with?('#')
id = node.parent['href'].remove('#')
name = node.content.strip
sep = name.start_with?('static') ? '.' : '#'
name.remove! %r{(abstract|static) }
name.sub! %r{\(.*\)}, '()'
name.prepend(self.name + sep)
entries << [name, id]
end end
entries entries

@ -1,29 +1,29 @@
module Docs module Docs
class React < UrlScraper class React < UrlScraper
self.name = 'React' self.name = 'React'
self.type = 'react' self.type = 'simple'
self.release = '15.6.1' self.release = '16.0.0'
self.base_url = 'https://facebook.github.io/react/docs/' self.base_url = 'https://reactjs.org/docs/'
self.root_path = 'hello-world.html' self.root_path = 'hello-world.html'
self.links = { self.links = {
home: 'https://facebook.github.io/react/', home: 'https://reactjs.org/',
code: 'https://github.com/facebook/react' code: 'https://github.com/facebook/react'
} }
html_filters.push 'react/entries', 'react/clean_html' html_filters.push 'react/entries', 'react/clean_html'
options[:root_title] = 'React Documentation' options[:skip] = %w(
options[:container] = '.documentationContent' codebase-overview.html
design-principles.html
how-to-contribute.html
implementation-notes.html
)
options[:replace_paths] = { options[:replace_paths] = {
'top-level-api.html' => 'react-api.html',
'working-with-the-browser.html' => 'refs-and-the-dom.html',
'interactivity-and-dynamic-uis.html' => 'state-and-lifecycle.html',
'more-about-refs.html' => 'refs-and-the-dom.html', 'more-about-refs.html' => 'refs-and-the-dom.html',
'advanced-performance.html' => 'optimizing-performance.html', 'interactivity-and-dynamic-uis.html' => 'state-and-lifecycle.html',
'component-api.html' => 'react-component.html', 'working-with-the-browser.html' => 'refs-and-the-dom.html',
'component-specs.html' => 'react-component.html', 'top-level-api.html' => 'react-api.html',
'multiple-components.html' => 'composition-vs-inheritance.html',
} }
options[:attribution] = <<-HTML options[:attribution] = <<-HTML

Loading…
Cancel
Save