From 66d6b2e49cd07b2217a3511b7c142b2b570c3e69 Mon Sep 17 00:00:00 2001 From: Simon Legner Date: Wed, 16 Mar 2022 16:46:37 +0100 Subject: [PATCH] Update Prettier documentation (2.6.0) --- lib/docs/filters/prettier/clean_html.rb | 83 +++++++++++++++++++++++++ lib/docs/scrapers/prettier.rb | 4 +- 2 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 lib/docs/filters/prettier/clean_html.rb diff --git a/lib/docs/filters/prettier/clean_html.rb b/lib/docs/filters/prettier/clean_html.rb new file mode 100644 index 00000000..7af0bd9c --- /dev/null +++ b/lib/docs/filters/prettier/clean_html.rb @@ -0,0 +1,83 @@ +module Docs + class Prettier + class CleanHtmlFilter < Filter + def call + @doc = at_css('.post') + + if root_page? + at_css('h1').content = 'React Native Documentation' + css('h1 ~ *').remove + end + + css('.docs-prevnext', '.hash-link', '.edit-page-link', '.edit-github', 'a.hash', '.edit-page-block', 'a.show', 'a.hide', 'hr').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 + + css('.prism').each do |node| + node.name = 'pre' + node['data-language'] = node['class'][/(?<=language\-)(\w+)/] + node.content = node.content + end + + css('pre > code.hljs').each do |node| + node.parent['data-language'] = 'jsx' + node.before(node.children).remove + end + + css('blockquote > p:first-child').each do |node| + 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', '> article', '.postHeader', '.web-player').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| + node.remove_attribute('target') + end + + css('center > .button', 'p:contains("short survey")', 'iframe', '.embedded-simulator', '.deprecatedIcon').remove + + css('h4.methodTitle').each do |node| + node.name = 'h3' + end + + css('div:not([class])', 'span:not([class])').each do |node| + node.before(node.children).remove + end + + css('ul').each do |node| + node.before(node.children).remove if node.at_css('> p', '> h2') + end + + doc + end + end + end +end diff --git a/lib/docs/scrapers/prettier.rb b/lib/docs/scrapers/prettier.rb index 7027d9fa..e11f8d77 100644 --- a/lib/docs/scrapers/prettier.rb +++ b/lib/docs/scrapers/prettier.rb @@ -2,7 +2,7 @@ module Docs class Prettier < UrlScraper self.name = 'Prettier' self.type = 'simple' - self.release = '2.5.1' + self.release = '2.6.0' self.base_url = 'https://prettier.io/docs/en/' self.links = { home: 'https://prettier.io/', @@ -10,7 +10,7 @@ module Docs } # Docusaurus like react_native - html_filters.push 'prettier/entries', 'react_native/clean_html' + html_filters.push 'prettier/entries', 'prettier/clean_html' options[:container] = '.docMainWrapper'