Skip to content

Commit 97f7b5a

Browse files
committed
Preserve whitespace in Rust Reference syntax definitions
1 parent 1bebe5b commit 97f7b5a

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/docs/filters/rust/clean_html.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ def call
6464
next_element.remove
6565
node.add_child(next_element)
6666
end
67+
68+
# We changed this to a <pre> in parse(), changing it back here
69+
node.name = 'div'
70+
node.css('.grammar-literal').each do |literal|
71+
literal.name = 'code'
72+
end
6773
end
6874

6975
css('.grammar-railroad').each do |node|

lib/docs/scrapers/rust.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ def process_response?(response)
5757

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

0 commit comments

Comments
 (0)