Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
bbcode.py
Go to the documentation of this file.
1
"""
2
pygments.formatters.bbcode
3
~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5
BBcode formatter.
6
7
:copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
8
:license: BSD, see LICENSE for details.
9
"""
10
11
12
from
pip._vendor.pygments.formatter
import
Formatter
13
from
pip._vendor.pygments.util
import
get_bool_opt
14
15
__all__ = [
'BBCodeFormatter'
]
16
17
18
class
BBCodeFormatter
(
Formatter
):
19
"""
20
Format tokens with BBcodes. These formatting codes are used by many
21
bulletin boards, so you can highlight your sourcecode with pygments before
22
posting it there.
23
24
This formatter has no support for background colors and borders, as there
25
are no common BBcode tags for that.
26
27
Some board systems (e.g. phpBB) don't support colors in their [code] tag,
28
so you can't use the highlighting together with that tag.
29
Text in a [code] tag usually is shown with a monospace font (which this
30
formatter can do with the ``monofont`` option) and no spaces (which you
31
need for indentation) are removed.
32
33
Additional options accepted:
34
35
`style`
36
The style to use, can be a string or a Style subclass (default:
37
``'default'``).
38
39
`codetag`
40
If set to true, put the output into ``[code]`` tags (default:
41
``false``)
42
43
`monofont`
44
If set to true, add a tag to show the code with a monospace font
45
(default: ``false``).
46
"""
47
name =
'BBCode'
48
aliases = [
'bbcode'
,
'bb'
]
49
filenames = []
50
51
def
__init__
(self, **options):
52
Formatter.__init__
(self, **options)
53
self.
_code
= get_bool_opt(options,
'codetag'
,
False
)
54
self.
_mono
= get_bool_opt(options,
'monofont'
,
False
)
55
56
self.
styles
= {}
57
self.
_make_styles
()
58
59
def
_make_styles
(self):
60
for
ttype, ndef
in
self.
style
:
61
start = end =
''
62
if
ndef[
'color'
]:
63
start +=
'[color=#%s]'
% ndef[
'color'
]
64
end =
'[/color]'
+ end
65
if
ndef[
'bold'
]:
66
start +=
'[b]'
67
end =
'[/b]'
+ end
68
if
ndef[
'italic'
]:
69
start +=
'[i]'
70
end =
'[/i]'
+ end
71
if
ndef[
'underline'
]:
72
start +=
'[u]'
73
end =
'[/u]'
+ end
74
# there are no common BBcodes for background-color and border
75
76
self.
styles
[ttype] = start, end
77
78
def
format_unencoded
(self, tokensource, outfile):
79
if
self.
_code
:
80
outfile.write
(
'[code]'
)
81
if
self.
_mono
:
82
outfile.write
(
'[font=monospace]'
)
83
84
lastval =
''
85
lasttype =
None
86
87
for
ttype, value
in
tokensource:
88
while
ttype
not
in
self.
styles
:
89
ttype =
ttype.parent
90
if
ttype == lasttype:
91
lastval += value
92
else
:
93
if
lastval:
94
start, end = self.
styles
[lasttype]
95
outfile.write
(
''
.join((start, lastval, end)))
96
lastval = value
97
lasttype = ttype
98
99
if
lastval:
100
start, end = self.
styles
[lasttype]
101
outfile.write
(
''
.join((start, lastval, end)))
102
103
if
self.
_mono
:
104
outfile.write
(
'[/font]'
)
105
if
self.
_code
:
106
outfile.write
(
'[/code]'
)
107
if
self.
_code
or
self.
_mono
:
108
outfile.write
(
'\n'
)
pip._vendor.pygments.formatter.Formatter
Definition
formatter.py:25
pip._vendor.pygments.formatter.Formatter.style
style
Definition
formatter.py:89
pip._vendor.pygments.formatters.bbcode.BBCodeFormatter
Definition
bbcode.py:18
pip._vendor.pygments.formatters.bbcode.BBCodeFormatter._code
_code
Definition
bbcode.py:53
pip._vendor.pygments.formatters.bbcode.BBCodeFormatter._mono
_mono
Definition
bbcode.py:54
pip._vendor.pygments.formatters.bbcode.BBCodeFormatter._make_styles
_make_styles(self)
Definition
bbcode.py:59
pip._vendor.pygments.formatters.bbcode.BBCodeFormatter.__init__
__init__(self, **options)
Definition
bbcode.py:51
pip._vendor.pygments.formatters.bbcode.BBCodeFormatter.styles
styles
Definition
bbcode.py:56
pip._vendor.pygments.formatters.bbcode.BBCodeFormatter.format_unencoded
format_unencoded(self, tokensource, outfile)
Definition
bbcode.py:78
pip._vendor.pygments.formatter
Definition
formatter.py:1
pip._vendor.pygments.util
Definition
util.py:1
i
for i
Definition
prime_search.m:10
venv
lib
python3.12
site-packages
pip
_vendor
pygments
formatters
bbcode.py
Generated by
1.9.8