Skip to content

Commit 7224ae4

Browse files
committed
try cleaning up the html entity mess
1 parent b3f4fd6 commit 7224ae4

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

tools/rehighlight.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,36 @@ class Cpp
1616
end
1717
end
1818

19+
20+
ENTITY_MAP = {
21+
'&' => '&',
22+
'&curlybr;' => '{',
23+
'&rcurlybr;' => '}',
24+
'_' => '_',
25+
'.' => '.',
26+
':' => ':',
27+
'[' => '[',
28+
']' => ']',
29+
'|' => '|',
30+
'/' => '/',
31+
'?' => '?',
32+
'!' => '!',
33+
'#' => '#',
34+
'$' => '$',
35+
'%' => '%',
36+
'*' => '*',
37+
'+' => '+',
38+
'=' => '=',
39+
',' => ',',
40+
';' => ';',
41+
'"' => '"',
42+
''' => "'",
43+
'}' => '}',
44+
'{' => '{',
45+
# these replacements happen in code blocks some time, just revert them
46+
'®' => '(R)',
47+
'©' => '(C)',
48+
}
1949
base_path = ARGV[0] || 'build'
2050

2151
# Dump all Rouge themes and patch them
@@ -112,10 +142,12 @@ class Cpp
112142
links = []
113143
source = source_html.gsub(/<a[^>]*class="xref[^"]*"[^>]*>.*?<\/a>/) do |link|
114144
token = "ROUGE_LINK_#{links.length}"
145+
ENTITY_MAP.each { |k,v| link.gsub!(k,v) }
115146
links << link
116147
token
117148
end
118149
source = Nokogiri::HTML.fragment(source).text
150+
ENTITY_MAP.each { |k,v| source.gsub!(k,v) }
119151

120152
lexer = Rouge::Lexer.find_fancy(lang, source) || Rouge::Lexers::PlainText.new
121153
formatter = Rouge::Formatters::HTML.new
@@ -168,4 +200,11 @@ class Cpp
168200
File.write(path, doc.to_html)
169201
puts "Rehighlighted #{path}"
170202
end
203+
end
204+
205+
206+
html_files.each do |path|
207+
content = File.read(path)
208+
ENTITY_MAP.each { |k,v| content.gsub!(k,v) }
209+
File.write(path, content)
171210
end

0 commit comments

Comments
 (0)