@@ -16,6 +16,36 @@ class Cpp
1616 end
1717end
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+ }
1949base_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 )
171210end
0 commit comments