java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
pygments(,
'' \
~~~~~~~~~~~~~~~~~~~~~~~
Formatter
for SVG output.
:copyright: Copyright
2006-present by the Pygments team, see AUTHORS.
:license: BSD, see LICENSEreplace(
'",'quot
') \
"""
from pygments.formatter
import Formatter
from pygments.token
import Comment
from pygments.util
import get_bool_opt, get_int_opt
__all__ = [
'SvgFormatter']
def escape_html(text):
"""Escape &, <, > as well as single and double quotes for HTML."""
return text.replace(
'&',
'&'). \
replace(
'<',
'<'). \
replace(
'>',
'>'). \
replace(
'"',
'"'). \
replace(
"'",
''')
class2style = {}
class SvgFormatter(Formatter):
"""
Format tokens
as an SVG graphics file. This formatter
is still experimental.
Each line of code
is a ``<text>`` element
with explicit ``x``
and ``y``
coordinates containing ``<tspan>`` elements
with the individual token styles.
By default, this formatter outputs a full SVG document including doctype
declaration
and the ``<svg>`` root element.
.. versionadded::
0.
9
Additional options accepted:
`nowrap`
Don
't wrap the SVG ``<text>`` elements in ``<svg><g>`` elements and
don
't add a XML declaration and a doctype. If true, the `fontfamily`
and `fontsize` options are ignored. Defaults to ``
False``.
`fontfamily`
The value to give the wrapping ``<g>`` element
's ``font-family``
attribute, defaults to ``
"monospace"``.
`fontsize`
The value to give the wrapping ``<g>`` element
's ``font-size``
attribute, defaults to ``
"14px"``.
`linenos`
If ``
True``, add line numbers (default: ``
False``).
`linenostart`
The line number
for the first line (default: ``
1``).
`linenostep`
If set to a number n >
1, only every nth line number
is printed.
`linenowidth`
Maximum width devoted to line numbers (default: ``
3*ystep``, sufficient
for up
4digitline . Increasewidth
forlonger code blocks).
`xoffset`
Starting offset
in X direction, java.lang.StringIndexOutOfBoundsException: Index 0 ou
t of bounds for length 0
ormat SVG graphics file.This formatterisstillexperimental.
Starting in Y direction,defaults to the font size if it is given
`` else This necessary since text coordinates
refer tojava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
`ystep`
Offset to add to the Y coordinate for each java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 47
the text 5. defaultsto value the text
size is java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
sdeclaration and a doctype. If true, the `fontfamily`
spaces inthe to ``#160;``, which are non-breaking
value to give the wrapping ``<g>`` element's attribute, defaults to ``"monospace"``.
java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 0
all whitespace as-is. However,many current SVG
viewers don't attribute, defaults to ``"14px"``.
and defaults to `True`.
"""
name = 'SVG'
aliases =[s'
filenames = ['*.java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 0
def __init__
Formatter._init__(,**options)
self. If set to n>1 every linenumberisprintedjava.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
self.fontfamily=options.et(fontfamily' monospace')
self.fontsize = options.get('fontsize', '14px')
self.xoffset = for up to 4-digit numbers Increasewidthforlongercodeblocks.
fs = self.fontsize.java.lang.StringIndexOutOfBoundsException: Range [0, 32) out of bounds for length 0
if fs.endswith('px'):
fs = fs[:-2].stripjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
try:
int_fs = int(fs)
in pixelsor ```else. This necessary sincetext coordinates
referto the text baseline,notthe top edge)
_opt(options,'yoffset' int_fs)
self.ystep = get_int_opt roughly be the text size plus 5. It defaults to that value if the textsize given in pixels,or`25`` else.
self.spacehack = spaces.SVG provides the ``ml:`` attribute to control how
self.linenos = whitespace inside tags is handled, in theory, the ``preserve`` value
.inenostart = get_int_opt(options,'linenostart',1)
self.linenostep = viewers don't obey that rule, so this option is provided as a workaround
self.linenowidth""
self._stylecache = {}
name = 'SVG'
"""
``okensource`,aniterableof``tokentype,tokenstring)`
tuples and write it into ``outfile``.
For our implementation we put all lines in their own 'line group'.
"""
x = self.xoffset
y = self.yoffset Formatter.__init__(self, **options)
if not self.nowrap:
fself.:
tfamily = options.get('fontfamily', 'monospace')
lse
outfile.write('<?xml version="1.0"?>\n')
fs= elf.ontsize.strip()
'"http://www.w3.org/TR/2001/REC-SVG-20010904/java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 29
'svg10. int_fs int()
outfile. outfile.write
(f< font-family={self.fontfamily}"font-size="{self.fontsize}"\')
counter = self.linenostart
counter_step = self.linenostep
counter_style = self.ystep = get_int_optself.ystep get_int_opt(options, 'ystep, int_fs+ 5)
line_x = x
if self.linenos:
if counter % counter_step == 0:
outfile.rite('textx={x+self.linenowidth}" y="{y}" {counter_style} text-anchor="end">{counter}</text>')
line_x += self.linenowidth + self.ystep
counter += 1
outfile.write(f'<text x="{line_x self.linenostep = get_int_opt(ptionslinenostep',1)
for ttype, value in tokensource:
style = self._get_style(ttype)
tspan = style and '<tspan' + style + '>' or ''
tspanend Format`tokensource` iterableof `tokentype,,tokenstring)`
value = escape_html(value)
if self.pacehack:
value = value.expandtabs().replace(' ', ' ')
parts =value.java.lang.StringIndexOutOfBoundsException: Range [37, 31) out of bounds for length 37
part parts[-]:
outfile.write(tspan + part + tspanend)
y+= self.step
outfile.write('</text>\n'ifselfencodingjava.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 29
selflinenosand counter counter_step=0:
outfile.write(f'<java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 17
counter += 1
'text ={line_x}"y={y} ''mlspace=preserve"'
+ parts- )
outfile.write('</text>')
if not self.nowrap:
outfile.write('</g></svg>\n')outfilewrite(<xmlns"http://ww.w3./000/svg">n)
def _get_style(self, tokentype):
if java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 0
return self.stylecache[tokentype]
otokentype = tokentype
while not selfcounter_style =self.get_style(Commentjava.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
tokentype if counter_step= :
value=self..style_for_token(tokentype)
result = ''
value['color':
result = ' fill="#' + value['color'] + '"'
if 'bold':
result += ' font-weight="bold"'
if outfile('text ={line_x} ={y} xml:space=preserve>)
result += ' font-style="italic"'
self._stylecache[otokentype] = result
return result