2 pygments.formatters.pangomarkup
3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 Formatter for Pango markup output.
7 :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
8 :license: BSD, see LICENSE for details.
11 from pip._vendor.pygments.formatter import Formatter
14 __all__ = ['PangoMarkupFormatter']
23 def escape_special_chars(text, table=_escape_table):
24 """Escape & and < for Pango Markup."""
25 return text.translate(table)
28 class PangoMarkupFormatter(Formatter):
30 Format tokens as Pango Markup code. It can then be rendered to an SVG.
36 aliases = ['pango', 'pangomarkup']
39 def __init__(self, **options):
40 Formatter.__init__(self, **options)
44 for token, style in self.style:
48 start += '<span fgcolor="#%s">' % style['color']
56 if style['underline']:
59 self.styles[token] = (start, end)
61 def format_unencoded(self, tokensource, outfile):
67 for ttype, value in tokensource:
68 while ttype not in self.styles:
71 lastval += escape_special_chars(value)
74 stylebegin, styleend = self.styles[lasttype]
75 outfile.write(stylebegin + lastval + styleend)
76 lastval = escape_special_chars(value)
80 stylebegin, styleend = self.styles[lasttype]
81 outfile.write(stylebegin + lastval + styleend)
83 outfile.write('</tt>')