ThirdParty/Pygments/pygments/formatters/html.py

changeset 4172
4f20dba37ab6
parent 3079
0233bbe9a9c4
child 4697
c2e9bf425554
diff -r 8bc578136279 -r 4f20dba37ab6 ThirdParty/Pygments/pygments/formatters/html.py
--- a/ThirdParty/Pygments/pygments/formatters/html.py	Wed Mar 11 18:25:37 2015 +0100
+++ b/ThirdParty/Pygments/pygments/formatters/html.py	Wed Mar 11 18:32:27 2015 +0100
@@ -5,23 +5,20 @@
 
     Formatter for HTML output.
 
-    :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
+    :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS.
     :license: BSD, see LICENSE for details.
 """
 
-try:
-    basestring    # __IGNORE_WARNING__
-except NameError:
-    basestring = str
+from __future__ import print_function
 
 import os
 import sys
 import os.path
-import io
 
 from pygments.formatter import Formatter
 from pygments.token import Token, Text, STANDARD_TYPES
-from pygments.util import get_bool_opt, get_int_opt, get_list_opt, bytes
+from pygments.util import get_bool_opt, get_int_opt, get_list_opt, \
+    StringIO, string_types, iteritems
 
 try:
     import ctags
@@ -32,11 +29,11 @@
 
 
 _escape_html_table = {
-    ord('&'): '&',
-    ord('<'): '&lt;',
-    ord('>'): '&gt;',
-    ord('"'): '&quot;',
-    ord("'"): '&#39;',
+    ord('&'): u'&amp;',
+    ord('<'): u'&lt;',
+    ord('>'): u'&gt;',
+    ord('"'): u'&quot;',
+    ord("'"): u'&#39;',
 }
 
 def escape_html(text, table=_escape_html_table):
@@ -223,29 +220,34 @@
         If you set this option, the default selector for `get_style_defs()`
         will be this class.
 
-        *New in Pygments 0.9:* If you select the ``'table'`` line numbers, the
-        wrapping table will have a CSS class of this string plus ``'table'``,
-        the default is accordingly ``'highlighttable'``.
+        .. versionadded:: 0.9
+           If you select the ``'table'`` line numbers, the wrapping table will
+           have a CSS class of this string plus ``'table'``, the default is
+           accordingly ``'highlighttable'``.
 
     `cssstyles`
         Inline CSS styles for the wrapping ``<div>`` tag (default: ``''``).
 
     `prestyles`
-        Inline CSS styles for the ``<pre>`` tag (default: ``''``).  *New in
-        Pygments 0.11.*
+        Inline CSS styles for the ``<pre>`` tag (default: ``''``).
+
+        .. versionadded:: 0.11
 
     `cssfile`
         If the `full` option is true and this option is given, it must be the
         name of an external file. If the filename does not include an absolute
         path, the file's path will be assumed to be relative to the main output
         file's path, if the latter can be found. The stylesheet is then written
-        to this file instead of the HTML file. *New in Pygments 0.6.*
+        to this file instead of the HTML file.
+
+        .. versionadded:: 0.6
 
     `noclobber_cssfile`
         If `cssfile` is given and the specified file exists, the css file will
         not be overwritten. This allows the use of the `full` option in
         combination with a user specified css file. Default is ``False``.
-        *New in Pygments 1.1.*
+
+        .. versionadded:: 1.1
 
     `linenos`
         If set to ``'table'``, output line numbers as a table with two cells,
@@ -268,7 +270,9 @@
         125%``).
 
     `hl_lines`
-        Specify a list of lines to be highlighted.  *New in Pygments 0.11.*
+        Specify a list of lines to be highlighted.
+
+        .. versionadded:: 0.11
 
     `linenostart`
         The line number for the first line (default: ``1``).
@@ -284,24 +288,30 @@
         If set to ``True``, the formatter won't output the background color
         for the wrapping element (this automatically defaults to ``False``
         when there is no wrapping element [eg: no argument for the
-        `get_syntax_defs` method given]) (default: ``False``). *New in
-        Pygments 0.6.*
+        `get_syntax_defs` method given]) (default: ``False``).
+
+        .. versionadded:: 0.6
 
     `lineseparator`
         This string is output between lines of code. It defaults to ``"\n"``,
         which is enough to break a line inside ``<pre>`` tags, but you can
-        e.g. set it to ``"<br>"`` to get HTML line breaks. *New in Pygments
-        0.7.*
+        e.g. set it to ``"<br>"`` to get HTML line breaks.
+
+        .. versionadded:: 0.7
 
     `lineanchors`
         If set to a nonempty string, e.g. ``foo``, the formatter will wrap each
         output line in an anchor tag with a ``name`` of ``foo-linenumber``.
-        This allows easy linking to certain lines. *New in Pygments 0.9.*
+        This allows easy linking to certain lines.
+
+        .. versionadded:: 0.9
 
     `linespans`
         If set to a nonempty string, e.g. ``foo``, the formatter will wrap each
         output line in a span tag with an ``id`` of ``foo-linenumber``.
-        This allows easy access to lines via javascript. *New in Pygments 1.6.*
+        This allows easy access to lines via javascript.
+
+        .. versionadded:: 1.6
 
     `anchorlinenos`
         If set to `True`, will wrap line numbers in <a> tags. Used in
@@ -311,18 +321,20 @@
         If set to the path of a ctags file, wrap names in anchor tags that
         link to their definitions. `lineanchors` should be used, and the
         tags file should specify line numbers (see the `-n` option to ctags).
-        *New in Pygments 1.6.*
+
+        .. versionadded:: 1.6
 
     `tagurlformat`
         A string formatting pattern used to generate links to ctags definitions.
         Available variables are `%(path)s`, `%(fname)s` and `%(fext)s`.
         Defaults to an empty string, resulting in just `#prefix-number` links.
-        *New in Pygments 1.6.*
+
+        .. versionadded:: 1.6
 
 
     **Subclassing the HTML formatter**
 
-    *New in Pygments 0.7.*
+    .. versionadded:: 0.7
 
     The HTML formatter is now built in a way that allows easy subclassing, thus
     customizing the output HTML code. The `format()` method calls
@@ -458,7 +470,7 @@
         """
         if arg is None:
             arg = ('cssclass' in self.options and '.'+self.cssclass or '')
-        if isinstance(arg, basestring):
+        if isinstance(arg, string_types):
             args = [arg]
         else:
             args = list(arg)
@@ -472,7 +484,7 @@
             return ', '.join(tmp)
 
         styles = [(level, ttype, cls, style)
-                  for cls, (style, ttype, level) in self.class2style.items()
+                  for cls, (style, ttype, level) in iteritems(self.class2style)
                   if cls and style]
         styles.sort()
         lines = ['%s { %s } /* %s */' % (prefix(cls), style, repr(ttype)[6:])
@@ -510,8 +522,9 @@
                     cssfilename = os.path.join(os.path.dirname(filename),
                                                self.cssfile)
                 except AttributeError:
-                    sys.stderr.write('Note: Cannot determine output file name, ' \
-                          'using current directory as base for the CSS file name')
+                    print('Note: Cannot determine output file name, ' \
+                          'using current directory as base for the CSS file name',
+                          file=sys.stderr)
                     cssfilename = self.cssfile
             # write CSS file only if noclobber_cssfile isn't given as an option.
             try:
@@ -539,7 +552,7 @@
         yield 0, DOC_FOOTER
 
     def _wrap_tablelinenos(self, inner):
-        dummyoutfile = io.StringIO()
+        dummyoutfile = StringIO()
         lncount = 0
         for t, line in inner:
             if t:
@@ -615,24 +628,24 @@
                         style = 'background-color: #ffffc0; padding: 0 5px 0 5px'
                     else:
                         style = 'background-color: #f0f0f0; padding: 0 5px 0 5px'
-                    yield 1, '<span style="%s">%*s</span> ' % (
+                    yield 1, '<span style="%s">%*s </span>' % (
                         style, mw, (num%st and ' ' or num)) + line
                     num += 1
             else:
                 for t, line in lines:
                     yield 1, ('<span style="background-color: #f0f0f0; '
-                              'padding: 0 5px 0 5px">%*s</span> ' % (
+                              'padding: 0 5px 0 5px">%*s </span>' % (
                               mw, (num%st and ' ' or num)) + line)
                     num += 1
         elif sp:
             for t, line in lines:
-                yield 1, '<span class="lineno%s">%*s</span> ' % (
+                yield 1, '<span class="lineno%s">%*s </span>' % (
                     num%sp == 0 and ' special' or '', mw,
                     (num%st and ' ' or num)) + line
                 num += 1
         else:
             for t, line in lines:
-                yield 1, '<span class="lineno">%*s</span> ' % (
+                yield 1, '<span class="lineno">%*s </span>' % (
                     mw, (num%st and ' ' or num)) + line
                 num += 1
 

eric ide

mercurial