Explorar el Código

Preserve whitespace in Rust Reference syntax definitions

Calum Smith hace 3 meses
padre
commit
97f7b5ad59
Se han modificado 2 ficheros con 8 adiciones y 0 borrados
  1. 6 0
      lib/docs/filters/rust/clean_html.rb
  2. 2 0
      lib/docs/scrapers/rust.rb

+ 6 - 0
lib/docs/filters/rust/clean_html.rb

@@ -64,6 +64,12 @@ module Docs
             next_element.remove
             node.add_child(next_element)
           end
+
+          # We changed this to a <pre> in parse(), changing it back here
+          node.name = 'div'
+          node.css('.grammar-literal').each do |literal|
+            literal.name = 'code'
+          end
         end
 
         css('.grammar-railroad').each do |node|

+ 2 - 0
lib/docs/scrapers/rust.rb

@@ -57,6 +57,8 @@ module Docs
 
     def parse(response) # Hook here because Nokogori removes whitespace from headings
       response.body.gsub! %r{<h[1-6] class="code-header">}, '<pre class="code-header">'
+      # And the reference uses whitespace for indentation in grammar definitions
+      response.body.gsub! %r{<div class="grammar-container">([\W\w]+?)</div>}, '<pre class="grammar-container">\1</pre>'
       super
     end
   end