@@ -2,26 +2,38 @@ module Docs
22 class Tailwindcss
33 class CleanHtmlFilter < Filter
44 def call
5+ # Move h1 out of wrapper.
6+ css ( 'h1' ) . each do |node |
7+ doc . prepend_child ( node )
8+ end
9+
510 # Remove main page headers (top level sticky)
6- css ( '#__next > .sticky' ) . remove
11+ css ( '#__next > .sticky' , 'div.fixed.inset-x-0.top-0' ) . remove
712 # And anything absolutely positioned (fancy floating navigation elements we don't care about)
8- css ( '#__next .absolute' ) . remove
13+ css ( '#__next .absolute' , '.fixed' ) . remove
914 # Remove the left-navigation we scraped
1015 css ( 'nav' ) . remove
1116
1217 css ( 'svg' ) . remove if root_page?
1318
14- # Remove the duplicate category name at the top of the page - redundant
15- at_css ( 'header#header > div:first-child > p:first-child' ) . remove
16-
1719 # Remove the right navigation sidebar
18- at_css ( 'header#header' ) . parent . css ( '> div:has(h5:contains("On this page"))' ) . remove
20+ css ( 'header#header' , 'p[data-section]' ) . each do |node |
21+ node . parent . css ( '> div:has(h5:contains("On this page"))' ) . remove # v3
22+
23+ node . parent . parent . css ( 'div.max-xl\\:hidden' ) . remove # v4
24+ end
25+
26+ # Remove the duplicate category name at the top of the page - redundant
27+ css (
28+ 'header#header > div:first-child > p:first-child' , # v3
29+ 'p[data-section]' # v4
30+ ) . remove
1931
2032 # Remove footer + prev/next navigation
21- at_css ( 'footer' ) . remove
33+ css ( 'footer' , '.row-start-5 ') . remove
2234
2335 # Handle long lists of class reference that otherwise span several scrolled pages
24- if class_reference = at_css ( '#class-reference' )
36+ if class_reference = at_css ( '#class-reference' , '#quick-reference' )
2537 reference_container = class_reference . parent
2638 classes_container = reference_container . children . reject { |child | child == class_reference } . first
2739
@@ -33,7 +45,7 @@ def call
3345 end
3446
3547 # Remove border color preview column as it isn't displayed anyway
36- if result [ :path ] == "border-color" and class_reference = at_css ( '#class-reference' )
48+ if result [ :path ] == "border-color" and class_reference = at_css ( '#class-reference' , '#quick-reference' )
3749 class_reference . parent . css ( "thead th:nth-child(3)" ) . remove
3850 class_reference . parent . css ( "tbody td:nth-child(3)" ) . remove
3951 end
@@ -59,29 +71,48 @@ def call
5971 end
6072
6173 # Remove buttons to expand lists - those are already expanded and the button is useless
62- css ( 'div > button:contains("Show all classes")' ) . each do |node |
74+ css (
75+ 'div > button:contains("Show all classes")' ,
76+ 'div > button:contains("Show more")'
77+ ) . each do |node |
6378 node . parent . remove
6479 end
6580
6681 # Remove class examples - not part of devdocs styleguide? (similar to bootstrap)
6782 # Refer to https://github.com/freeCodeCamp/devdocs/pull/1534#pullrequestreview-649818936
68- css ( '.not-prose' ) . each do |node |
69- if node . parent . children . length == 1
70- node . parent . remove
71- else
72- node . remove
73- end
74- end
83+ css ( '.mt-4.-mb-3' , 'figure' , 'svg' , '.flex.space-x-2' ) . remove
7584
76- # Properly format code examples
85+ # Properly format code examples.
7786 css ( 'pre > code:first-child' ) . each do |node |
78- node . parent [ 'data-language' ] = node [ 'class' ] [ /language-(\w +)/ , 1 ] if node [ 'class' ] and node [ 'class' ] [ /language-(\w +)/ ]
79- node . parent . content = node . parent . content
87+ # v4 doesn't provide language context, so it must be inferred imperfectly.
88+ node . parent [ 'data-language' ] =
89+ if node . content . include? ( 'function' )
90+ 'jsx'
91+ elsif node . content . include? ( "</" )
92+ 'html'
93+ else
94+ 'css'
95+ end
96+
97+ node . parent . content =
98+ if version == '3'
99+ node . parent . content
100+ else
101+ node . css ( '.line' ) . map ( &:content ) . join ( "\n " )
102+ end
103+ end
104+
105+ # Remove headers some code examples have.
106+ css ( '.flex.text-slate-400.text-xs.leading-6' , '.px-3.pt-0\\.5.pb-1\\.5' ) . remove
107+
108+ # Strip anchor from headers
109+ css ( 'h2' , 'h3' ) . each do |node |
110+ node . content = node . inner_text
80111 end
81112
82113 @doc . traverse { |node | cleanup_tailwind_classes ( node ) }
83114
84- #remove weird <hr> (https://github.com/damms005/devdocs/commit/8c9fbd859b71a2525b94a35ea994393ce2b6fedb#commitcomment-50091018)
115+ # Remove weird <hr> (https://github.com/damms005/devdocs/commit/8c9fbd859b71a2525b94a35ea994393ce2b6fedb#commitcomment-50091018)
85116 css ( 'hr' ) . remove
86117
87118 doc
0 commit comments