Index: utils/opt-viewer/opt-viewer.py =================================================================== --- utils/opt-viewer/opt-viewer.py +++ utils/opt-viewer/opt-viewer.py @@ -184,18 +184,29 @@ '''.format(filename), file=self.stream) self.html_formatter = HtmlFormatter(encoding='utf-8') - self.cpp_lexer = CppLexer() + self.cpp_lexer = CppLexer(stripnl=False) - def render_source_line(self, linenum, line): - html_line = highlight(line, self.cpp_lexer, self.html_formatter) - print(''' + def render_source_lines(self, stream, line_remarks): + file_text = stream.read() + html_highlighted = highlight(file_text, self.cpp_lexer, self.html_formatter) + + # Take off the header and footer, these must be + # reapplied line-wise, within the page structure + html_highlighted = html_highlighted.replace('
', '')
+        html_highlighted = html_highlighted.replace('
', '') + + for (linenum, html_line) in enumerate(html_highlighted.split('\n'), start=1): + print(''' {linenum} -{html_line} +
{html_line}
'''.format(**locals()), file=self.stream) + for remark in line_remarks.get(linenum, []): + self.render_inline_remarks(remark, html_line) + def render_inline_remarks(self, r, line): inlining_context = r.DemangledFunctionName print @@ -237,10 +248,8 @@ Source Inline Context ''', file=self.stream) - for (linenum, line) in enumerate(self.source_stream.readlines(), start=1): - self.render_source_line(linenum, line) - for remark in line_remarks.get(linenum, []): - self.render_inline_remarks(remark, line) + self.render_source_lines(self.source_stream, line_remarks) + print('''