Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
pangomarkup.py
Go to the documentation of this file.
1
"""
2
pygments.formatters.pangomarkup
3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5
Formatter for Pango markup output.
6
7
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8
:license: BSD, see LICENSE for details.
9
"""
10
11
from
pip._vendor.pygments.formatter
import
Formatter
12
13
14
__all__ = [
'PangoMarkupFormatter'
]
15
16
17
_escape_table = {
18
ord
(
'&'
):
'&'
,
19
ord
(
'<'
):
'<'
,
20
}
21
22
23
def
escape_special_chars
(text, table=_escape_table):
24
"""Escape & and < for Pango Markup."""
25
return
text.translate
(table)
26
27
28
class
PangoMarkupFormatter
(
Formatter
):
29
"""
30
Format tokens as Pango Markup code. It can then be rendered to an SVG.
31
32
.. versionadded:: 2.9
33
"""
34
35
name =
'Pango Markup'
36
aliases = [
'pango'
,
'pangomarkup'
]
37
filenames = []
38
39
def
__init__
(self, **options):
40
Formatter.__init__
(self, **options)
41
42
self.
styles
= {}
43
44
for
token, style
in
self.
style
:
45
start =
''
46
end =
''
47
if
style[
'color'
]:
48
start +=
'<span fgcolor="#%s">'
% style[
'color'
]
49
end =
'</span>'
+ end
50
if
style[
'bold'
]:
51
start +=
'<b>'
52
end =
'</b>'
+ end
53
if
style[
'italic'
]:
54
start +=
'<i>'
55
end =
'</i>'
+ end
56
if
style[
'underline'
]:
57
start +=
'<u>'
58
end =
'</u>'
+ end
59
self.
styles
[token] = (start, end)
60
61
def
format_unencoded
(self, tokensource, outfile):
62
lastval =
''
63
lasttype =
None
64
65
outfile.write
(
'<tt>'
)
66
67
for
ttype, value
in
tokensource:
68
while
ttype
not
in
self.
styles
:
69
ttype =
ttype.parent
70
if
ttype == lasttype:
71
lastval +=
escape_special_chars
(value)
72
else
:
73
if
lastval:
74
stylebegin, styleend = self.
styles
[lasttype]
75
outfile.write
(stylebegin + lastval + styleend)
76
lastval =
escape_special_chars
(value)
77
lasttype = ttype
78
79
if
lastval:
80
stylebegin, styleend = self.
styles
[lasttype]
81
outfile.write
(stylebegin + lastval + styleend)
82
83
outfile.write
(
'</tt>'
)
pip._vendor.pygments.formatter.Formatter
Definition
formatter.py:25
pip._vendor.pygments.formatter.Formatter.style
style
Definition
formatter.py:89
pip._vendor.pygments.formatters.pangomarkup.PangoMarkupFormatter
Definition
pangomarkup.py:28
pip._vendor.pygments.formatters.pangomarkup.PangoMarkupFormatter.__init__
__init__(self, **options)
Definition
pangomarkup.py:39
pip._vendor.pygments.formatters.pangomarkup.PangoMarkupFormatter.styles
styles
Definition
pangomarkup.py:42
pip._vendor.pygments.formatters.pangomarkup.PangoMarkupFormatter.format_unencoded
format_unencoded(self, tokensource, outfile)
Definition
pangomarkup.py:61
pip._vendor.pygments.formatter
Definition
formatter.py:1
pip._vendor.pygments.formatters.pangomarkup.escape_special_chars
escape_special_chars(text, table=_escape_table)
Definition
pangomarkup.py:23
i
for i
Definition
prime_search.m:10
venv
lib
python3.12
site-packages
pip
_vendor
pygments
formatters
pangomarkup.py
Generated by
1.9.8