From: Stefan Behnel Date: Sun, 1 Sep 2013 19:56:54 +0000 (+0200) Subject: fix some HTML issues in annotation file X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cb1a22c96b7807055576e4a09cfefa1b263853c7;p=platform%2Fupstream%2Fpython-cython.git fix some HTML issues in annotation file --HG-- extra : transplant_source : gx%EB%08%DA%5D%B2-lzq%ED%3A%A9Xn%B3%EAX%01 --- diff --git a/Cython/Compiler/Annotate.py b/Cython/Compiler/Annotate.py index f85b6a3..65796ca 100644 --- a/Cython/Compiler/Annotate.py +++ b/Cython/Compiler/Annotate.py @@ -11,9 +11,11 @@ from Code import CCodeWriter from Cython import Utils # need one-characters subsitutions (for now) so offsets aren't off -special_chars = [(u'<', u'\xF0', u'<'), - (u'>', u'\xF1', u'>'), - (u'&', u'\xF2', u'&')] +special_chars = [ + (u'&', u'\xF2', u'&'), + (u'<', u'\xF0', u'<'), + (u'>', u'\xF1', u'>'), +] line_pos_comment = re.compile(r'/\*.*?<<<<<<<<<<<<<<.*?\*/\n*', re.DOTALL) @@ -57,8 +59,7 @@ class AnnotationCCodeWriter(CCodeWriter): self.mark_pos(None) f = Utils.open_source_file(source_filename) lines = f.readlines() - for k in range(len(lines)): - line = lines[k] + for k, line in enumerate(lines): for c, cc, html in special_chars: line = line.replace(c, cc) lines[k] = line @@ -86,6 +87,7 @@ class AnnotationCCodeWriter(CCodeWriter): html_filename = os.path.splitext(target_filename)[0] + ".html" f = codecs.open(html_filename, "w", encoding="UTF-8") + f.write(u'\n') f.write(u'\n' % Version.watermark) f.write(u'\n') f.write(u""" @@ -147,8 +149,9 @@ function toggleDiv(id) { code = code_source_file[k] except KeyError: code = '' - - code = code.replace('<', '<') + else: + for c, cc, html in special_chars: + code = code.replace(c, html) code, py_c_api_calls = py_c_api.subn(ur"\1(", code) code, pyx_c_api_calls = pyx_c_api.subn(ur"\1(", code)