Sfoglia il codice sorgente

Allow Python scraper to keep empty spans with ids

Tim Lim 2 anni fa
parent
commit
b46cb9598d
2 ha cambiato i file con 11 aggiunte e 3 eliminazioni
  1. 5 3
      lib/docs/filters/sphinx/clean_html.rb
  2. 6 0
      lib/docs/scrapers/python.rb

+ 5 - 3
lib/docs/filters/sphinx/clean_html.rb

@@ -36,9 +36,11 @@ module Docs
           node.replace(pre)
         end
 
-        css('span[id]:empty').each do |node|
-          (node.next_element || node.previous_element)['id'] ||= node['id'] if node.next_element || node.previous_element
-          node.remove
+        unless context[:sphinx_keep_empty_ids]
+          css('span[id]:empty').each do |node|
+            (node.next_element || node.previous_element)['id'] ||= node['id'] if node.next_element || node.previous_element
+            node.remove
+          end
         end
 
         css('.section').each do |node|

+ 6 - 0
lib/docs/scrapers/python.rb

@@ -7,6 +7,12 @@ module Docs
       code: 'https://github.com/python/cpython'
     }
 
+    # bypass the clean_text filter as it removes empty span with ids
+    options[:clean_text] = false
+
+    # bypass sphinx modifying empty ids
+    options[:sphinx_keep_empty_ids] = true
+
     options[:skip_patterns] = [/whatsnew/]
     options[:skip] = %w(
       library/2to3.html