[devdocsgjs/main: 204/239] Simplify the HTML output




commit 4d02410ac1af4ad7296fd692ad32338edc0636d2
Author: Nicolas Ettlin <nicolas ettlin me com>
Date:   Wed Feb 16 12:56:54 2022 +0100

    Simplify the HTML output

 lib/docs/filters/scala/clean_html_v3.rb | 36 ++++++++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 7 deletions(-)
---
diff --git a/lib/docs/filters/scala/clean_html_v3.rb b/lib/docs/filters/scala/clean_html_v3.rb
index 207d3ccd..8e869e37 100644
--- a/lib/docs/filters/scala/clean_html_v3.rb
+++ b/lib/docs/filters/scala/clean_html_v3.rb
@@ -11,13 +11,7 @@ module Docs
         format_top_links
         format_metadata
         format_members
-
-        # Simplify the HTML structure
-        @doc = at_css('#content > div')
-        css('.documentableList > *').each do |element|
-          element.parent = doc
-        end
-        at_css('.membersList').remove
+        simplify_html
 
         doc
       end
@@ -91,6 +85,10 @@ module Docs
       def format_metadata
         # Metadata (attributes)
         css('.tabs.single .monospace').each do |node|
+          node.css('> div').each do |div|
+            div['class'] = 'member'
+          end
+
           node['class'] = 'related-types'
 
           if node.children.count > 15
@@ -183,6 +181,30 @@ module Docs
         end
       end
 
+      def simplify_html
+        @doc = at_css('#content > div')
+
+        css('.documentableList > *').each do |element|
+          element.parent = doc
+        end
+        at_css('.membersList').remove
+
+        # Remove useless classes
+        css('.header, .groupHeader, .cover, .documentableName').each do |element|
+          element.remove_attribute('class')
+        end
+
+        # Remove useless attributes
+        css('[t]').each do |element|
+          element.remove_attribute('t')
+        end
+
+        # Remove useless wrapper elements
+        css('.docs, .doc, .memberDocumentation, span, div:not([class])').each do |element|
+          element.replace(element.children)
+        end
+      end
+
       def convert_dl_to_table(dl)
         table = Nokogiri::XML::Node.new('table', doc)
         table['class'] = 'attributes'


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]