| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import collections | 6 import collections |
| 7 import os | 7 import os |
| 8 import re | 8 import re |
| 9 import sys | 9 import sys |
| 10 | 10 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 callouts = collections.defaultdict(int) | 70 callouts = collections.defaultdict(int) |
| 71 for i, line in enumerate(output.splitlines(True)): | 71 for i, line in enumerate(output.splitlines(True)): |
| 72 m = callout_re.match(line) | 72 m = callout_re.match(line) |
| 73 if m: | 73 if m: |
| 74 callouts[i + int(m.group(1)) - len(callouts)] += 1 | 74 callouts[i + int(m.group(1)) - len(callouts)] += 1 |
| 75 | 75 |
| 76 output = callout_re.sub('', output) | 76 output = callout_re.sub('', output) |
| 77 | 77 |
| 78 w = sys.stdout.write | 78 w = sys.stdout.write |
| 79 | 79 |
| 80 comment_marker = '###COMMENT###' |
| 81 |
| 80 callout_counter = 1 | 82 callout_counter = 1 |
| 81 if backend == 'xhtml11': | 83 if backend == 'xhtml11': |
| 82 preamble = ( | 84 preamble = ( |
| 83 '</p></div><div class="listingblock"><div class="content"><pre><code>' | 85 '</p></div><div class="listingblock"><div class="content"><pre><code>' |
| 84 ) | 86 ) |
| 85 postamble = '</code></pre></div></div><p><div class="paragraph">' | 87 postamble = '</code></pre></div></div><p><div class="paragraph">' |
| 86 c = ansi2html.Ansi2HTMLConverter(inline=True, scheme='custom') | 88 c = ansi2html.Ansi2HTMLConverter(inline=True, scheme='custom') |
| 87 | 89 |
| 88 in_code = False | 90 in_code = False |
| 89 body = c.convert(output, full=False) | 91 body = c.convert(output, full=False) |
| 90 for i, line in enumerate(body.splitlines()): | 92 for i, line in enumerate(body.splitlines()): |
| 91 if line.startswith('# '): | 93 if line.startswith(comment_marker): |
| 92 if in_code: | 94 if in_code: |
| 93 w(postamble) | 95 w(postamble) |
| 94 in_code = False | 96 in_code = False |
| 95 w(line[1:]) | 97 w(line[len(comment_marker):]) |
| 96 else: | 98 else: |
| 97 if not in_code: | 99 if not in_code: |
| 98 w(preamble) | 100 w(preamble) |
| 99 in_code = True | 101 in_code = True |
| 100 ext = '' | 102 ext = '' |
| 101 for _ in xrange(callouts[i]): | 103 for _ in xrange(callouts[i]): |
| 102 if not ext: | 104 if not ext: |
| 103 ext += '</span>' | 105 ext += '</span>' |
| 104 ext += ' <b><%d></b>' % callout_counter | 106 ext += ' <b><%d></b>' % callout_counter |
| 105 callout_counter += 1 | 107 callout_counter += 1 |
| 106 if ext: | 108 if ext: |
| 107 ext += '<span>' | 109 ext += '<span>' |
| 108 w(line + ext + '\n') | 110 w(line + ext + '\n') |
| 109 if in_code: | 111 if in_code: |
| 110 w(postamble) | 112 w(postamble) |
| 111 else: | 113 else: |
| 112 preamble = '</simpara><literallayout class="monospaced">' | 114 preamble = '</simpara><literallayout class="monospaced">' |
| 113 postamble = '</literallayout><simpara>' | 115 postamble = '</literallayout><simpara>' |
| 114 | 116 |
| 115 in_code = False | 117 in_code = False |
| 116 body = simpleXML(output) | 118 body = simpleXML(output) |
| 117 for i, line in enumerate(body.splitlines()): | 119 for i, line in enumerate(body.splitlines()): |
| 118 if line.startswith('# '): | 120 if line.startswith(comment_marker): |
| 119 if in_code: | 121 if in_code: |
| 120 w(postamble) | 122 w(postamble) |
| 121 in_code = False | 123 in_code = False |
| 122 w(line[1:]) | 124 w(line[len(comment_marker):]) |
| 123 else: | 125 else: |
| 124 if not in_code: | 126 if not in_code: |
| 125 w(preamble) | 127 w(preamble) |
| 126 in_code = True | 128 in_code = True |
| 127 ext = '' | 129 ext = '' |
| 128 for _ in xrange(callouts[i]): | 130 for _ in xrange(callouts[i]): |
| 129 ext += ' <emphasis role="strong">(%d)</emphasis>' % callout_counter | 131 ext += ' <emphasis role="strong">(%d)</emphasis>' % callout_counter |
| 130 callout_counter += 1 | 132 callout_counter += 1 |
| 131 w(line + ext + '\n') | 133 w(line + ext + '\n') |
| 132 if in_code: | 134 if in_code: |
| 133 w(postamble) | 135 w(postamble) |
| 134 | 136 |
| 135 | 137 |
| 136 if __name__ == '__main__': | 138 if __name__ == '__main__': |
| 137 main() | 139 main() |
| OLD | NEW |