From 6d7ba58f880be618ade07f8ea080fe8c4bf8a896 Mon Sep 17 00:00:00 2001 From: cyfraeviolae Date: Wed, 3 Apr 2024 03:10:44 -0400 Subject: venv --- .../site-packages/pygments/formatters/__init__.py | 158 ++++ .../__pycache__/__init__.cpython-311.pyc | Bin 0 -> 7737 bytes .../__pycache__/_mapping.cpython-311.pyc | Bin 0 -> 4215 bytes .../formatters/__pycache__/bbcode.cpython-311.pyc | Bin 0 -> 4447 bytes .../formatters/__pycache__/groff.cpython-311.pyc | Bin 0 -> 7820 bytes .../formatters/__pycache__/html.cpython-311.pyc | Bin 0 -> 42707 bytes .../formatters/__pycache__/img.cpython-311.pyc | Bin 0 -> 30048 bytes .../formatters/__pycache__/irc.cpython-311.pyc | Bin 0 -> 6361 bytes .../formatters/__pycache__/latex.cpython-311.pyc | Bin 0 -> 21749 bytes .../formatters/__pycache__/other.cpython-311.pyc | Bin 0 -> 7577 bytes .../__pycache__/pangomarkup.cpython-311.pyc | Bin 0 -> 3157 bytes .../formatters/__pycache__/rtf.cpython-311.pyc | Bin 0 -> 6812 bytes .../formatters/__pycache__/svg.cpython-311.pyc | Bin 0 -> 9620 bytes .../__pycache__/terminal.cpython-311.pyc | Bin 0 -> 5987 bytes .../__pycache__/terminal256.cpython-311.pyc | Bin 0 -> 16365 bytes .../site-packages/pygments/formatters/_mapping.py | 23 + .../site-packages/pygments/formatters/bbcode.py | 108 +++ .../site-packages/pygments/formatters/groff.py | 170 ++++ .../site-packages/pygments/formatters/html.py | 990 +++++++++++++++++++++ .../site-packages/pygments/formatters/img.py | 684 ++++++++++++++ .../site-packages/pygments/formatters/irc.py | 154 ++++ .../site-packages/pygments/formatters/latex.py | 521 +++++++++++ .../site-packages/pygments/formatters/other.py | 161 ++++ .../pygments/formatters/pangomarkup.py | 83 ++ .../site-packages/pygments/formatters/rtf.py | 146 +++ .../site-packages/pygments/formatters/svg.py | 188 ++++ .../site-packages/pygments/formatters/terminal.py | 127 +++ .../pygments/formatters/terminal256.py | 338 +++++++ 28 files changed, 3851 insertions(+) create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/__init__.py create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/__init__.cpython-311.pyc create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/_mapping.cpython-311.pyc create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/bbcode.cpython-311.pyc create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/groff.cpython-311.pyc create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/html.cpython-311.pyc create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/img.cpython-311.pyc create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/irc.cpython-311.pyc create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/latex.cpython-311.pyc create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/other.cpython-311.pyc create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/pangomarkup.cpython-311.pyc create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/rtf.cpython-311.pyc create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/svg.cpython-311.pyc create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/terminal.cpython-311.pyc create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/terminal256.cpython-311.pyc create mode 100755 venv/lib/python3.11/site-packages/pygments/formatters/_mapping.py create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/bbcode.py create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/groff.py create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/html.py create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/img.py create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/irc.py create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/latex.py create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/other.py create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/pangomarkup.py create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/rtf.py create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/svg.py create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/terminal.py create mode 100644 venv/lib/python3.11/site-packages/pygments/formatters/terminal256.py (limited to 'venv/lib/python3.11/site-packages/pygments/formatters') diff --git a/venv/lib/python3.11/site-packages/pygments/formatters/__init__.py b/venv/lib/python3.11/site-packages/pygments/formatters/__init__.py new file mode 100644 index 0000000..6e482a1 --- /dev/null +++ b/venv/lib/python3.11/site-packages/pygments/formatters/__init__.py @@ -0,0 +1,158 @@ +""" + pygments.formatters + ~~~~~~~~~~~~~~~~~~~ + + Pygments formatters. + + :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import re +import sys +import types +import fnmatch +from os.path import basename + +from pygments.formatters._mapping import FORMATTERS +from pygments.plugin import find_plugin_formatters +from pygments.util import ClassNotFound + +__all__ = ['get_formatter_by_name', 'get_formatter_for_filename', + 'get_all_formatters', 'load_formatter_from_file'] + list(FORMATTERS) + +_formatter_cache = {} # classes by name +_pattern_cache = {} + + +def _fn_matches(fn, glob): + """Return whether the supplied file name fn matches pattern filename.""" + if glob not in _pattern_cache: + pattern = _pattern_cache[glob] = re.compile(fnmatch.translate(glob)) + return pattern.match(fn) + return _pattern_cache[glob].match(fn) + + +def _load_formatters(module_name): + """Load a formatter (and all others in the module too).""" + mod = __import__(module_name, None, None, ['__all__']) + for formatter_name in mod.__all__: + cls = getattr(mod, formatter_name) + _formatter_cache[cls.name] = cls + + +def get_all_formatters(): + """Return a generator for all formatter classes.""" + # NB: this returns formatter classes, not info like get_all_lexers(). + for info in FORMATTERS.values(): + if info[1] not in _formatter_cache: + _load_formatters(info[0]) + yield _formatter_cache[info[1]] + for _, formatter in find_plugin_formatters(): + yield formatter + + +def find_formatter_class(alias): + """Lookup a formatter by alias. + + Returns None if not found. + """ + for module_name, name, aliases, _, _ in FORMATTERS.values(): + if alias in aliases: + if name not in _formatter_cache: + _load_formatters(module_name) + return _formatter_cache[name] + for _, cls in find_plugin_formatters(): + if alias in cls.aliases: + return cls + + +def get_formatter_by_name(_alias, **options): + """ + Return an instance of a :class:`.Formatter` subclass that has `alias` in its + aliases list. The formatter is given the `options` at its instantiation. + + Will raise :exc:`pygments.util.ClassNotFound` if no formatter with that + alias is found. + """ + cls = find_formatter_class(_alias) + if cls is None: + raise ClassNotFound("no formatter found for name %r" % _alias) + return cls(**options) + + +def load_formatter_from_file(filename, formattername="CustomFormatter", **options): + """ + Return a `Formatter` subclass instance loaded from the provided file, relative + to the current directory. + + The file is expected to contain a Formatter class named ``formattername`` + (by default, CustomFormatter). Users should be very careful with the input, because + this method is equivalent to running ``eval()`` on the input file. The formatter is + given the `options` at its instantiation. + + :exc:`pygments.util.ClassNotFound` is raised if there are any errors loading + the formatter. + + .. versionadded:: 2.2 + """ + try: + # This empty dict will contain the namespace for the exec'd file + custom_namespace = {} + with open(filename, 'rb') as f: + exec(f.read(), custom_namespace) + # Retrieve the class `formattername` from that namespace + if formattername not in custom_namespace: + raise ClassNotFound('no valid %s class found in %s' % + (formattername, filename)) + formatter_class = custom_namespace[formattername] + # And finally instantiate it with the options + return formatter_class(**options) + except OSError as err: + raise ClassNotFound('cannot read %s: %s' % (filename, err)) + except ClassNotFound: + raise + except Exception as err: + raise ClassNotFound('error when loading custom formatter: %s' % err) + + +def get_formatter_for_filename(fn, **options): + """ + Return a :class:`.Formatter` subclass instance that has a filename pattern + matching `fn`. The formatter is given the `options` at its instantiation. + + Will raise :exc:`pygments.util.ClassNotFound` if no formatter for that filename + is found. + """ + fn = basename(fn) + for modname, name, _, filenames, _ in FORMATTERS.values(): + for filename in filenames: + if _fn_matches(fn, filename): + if name not in _formatter_cache: + _load_formatters(modname) + return _formatter_cache[name](**options) + for _name, cls in find_plugin_formatters(): + for filename in cls.filenames: + if _fn_matches(fn, filename): + return cls(**options) + raise ClassNotFound("no formatter found for file name %r" % fn) + + +class _automodule(types.ModuleType): + """Automatically import formatters.""" + + def __getattr__(self, name): + info = FORMATTERS.get(name) + if info: + _load_formatters(info[0]) + cls = _formatter_cache[info[1]] + setattr(self, name, cls) + return cls + raise AttributeError(name) + + +oldmod = sys.modules[__name__] +newmod = _automodule(__name__) +newmod.__dict__.update(oldmod.__dict__) +sys.modules[__name__] = newmod +del newmod.newmod, newmod.oldmod, newmod.sys, newmod.types diff --git a/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/__init__.cpython-311.pyc b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..de3734e Binary files /dev/null and b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/__init__.cpython-311.pyc differ diff --git a/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/_mapping.cpython-311.pyc b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/_mapping.cpython-311.pyc new file mode 100644 index 0000000..268b46e Binary files /dev/null and b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/_mapping.cpython-311.pyc differ diff --git a/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/bbcode.cpython-311.pyc b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/bbcode.cpython-311.pyc new file mode 100644 index 0000000..f958bd3 Binary files /dev/null and b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/bbcode.cpython-311.pyc differ diff --git a/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/groff.cpython-311.pyc b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/groff.cpython-311.pyc new file mode 100644 index 0000000..d578aa0 Binary files /dev/null and b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/groff.cpython-311.pyc differ diff --git a/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/html.cpython-311.pyc b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/html.cpython-311.pyc new file mode 100644 index 0000000..42eb8bd Binary files /dev/null and b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/html.cpython-311.pyc differ diff --git a/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/img.cpython-311.pyc b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/img.cpython-311.pyc new file mode 100644 index 0000000..60484d1 Binary files /dev/null and b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/img.cpython-311.pyc differ diff --git a/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/irc.cpython-311.pyc b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/irc.cpython-311.pyc new file mode 100644 index 0000000..022a40e Binary files /dev/null and b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/irc.cpython-311.pyc differ diff --git a/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/latex.cpython-311.pyc b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/latex.cpython-311.pyc new file mode 100644 index 0000000..2bbb094 Binary files /dev/null and b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/latex.cpython-311.pyc differ diff --git a/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/other.cpython-311.pyc b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/other.cpython-311.pyc new file mode 100644 index 0000000..6bc4288 Binary files /dev/null and b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/other.cpython-311.pyc differ diff --git a/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/pangomarkup.cpython-311.pyc b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/pangomarkup.cpython-311.pyc new file mode 100644 index 0000000..8db5e7e Binary files /dev/null and b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/pangomarkup.cpython-311.pyc differ diff --git a/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/rtf.cpython-311.pyc b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/rtf.cpython-311.pyc new file mode 100644 index 0000000..173c930 Binary files /dev/null and b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/rtf.cpython-311.pyc differ diff --git a/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/svg.cpython-311.pyc b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/svg.cpython-311.pyc new file mode 100644 index 0000000..d579678 Binary files /dev/null and b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/svg.cpython-311.pyc differ diff --git a/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/terminal.cpython-311.pyc b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/terminal.cpython-311.pyc new file mode 100644 index 0000000..e46767f Binary files /dev/null and b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/terminal.cpython-311.pyc differ diff --git a/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/terminal256.cpython-311.pyc b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/terminal256.cpython-311.pyc new file mode 100644 index 0000000..560606f Binary files /dev/null and b/venv/lib/python3.11/site-packages/pygments/formatters/__pycache__/terminal256.cpython-311.pyc differ diff --git a/venv/lib/python3.11/site-packages/pygments/formatters/_mapping.py b/venv/lib/python3.11/site-packages/pygments/formatters/_mapping.py new file mode 100755 index 0000000..72ca840 --- /dev/null +++ b/venv/lib/python3.11/site-packages/pygments/formatters/_mapping.py @@ -0,0 +1,23 @@ +# Automatically generated by scripts/gen_mapfiles.py. +# DO NOT EDIT BY HAND; run `tox -e mapfiles` instead. + +FORMATTERS = { + 'BBCodeFormatter': ('pygments.formatters.bbcode', 'BBCode', ('bbcode', 'bb'), (), 'Format tokens with BBcodes. These formatting codes are used by many bulletin boards, so you can highlight your sourcecode with pygments before posting it there.'), + 'BmpImageFormatter': ('pygments.formatters.img', 'img_bmp', ('bmp', 'bitmap'), ('*.bmp',), 'Create a bitmap image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'), + 'GifImageFormatter': ('pygments.formatters.img', 'img_gif', ('gif',), ('*.gif',), 'Create a GIF image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'), + 'GroffFormatter': ('pygments.formatters.groff', 'groff', ('groff', 'troff', 'roff'), (), 'Format tokens with groff escapes to change their color and font style.'), + 'HtmlFormatter': ('pygments.formatters.html', 'HTML', ('html',), ('*.html', '*.htm'), "Format tokens as HTML 4 ```` tags. By default, the content is enclosed in a ``
`` tag, itself wrapped in a ``
`` tag (but see the `nowrap` option). The ``
``'s CSS class can be set by the `cssclass` option."), + 'IRCFormatter': ('pygments.formatters.irc', 'IRC', ('irc', 'IRC'), (), 'Format tokens with IRC color sequences'), + 'ImageFormatter': ('pygments.formatters.img', 'img', ('img', 'IMG', 'png'), ('*.png',), 'Create a PNG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'), + 'JpgImageFormatter': ('pygments.formatters.img', 'img_jpg', ('jpg', 'jpeg'), ('*.jpg',), 'Create a JPEG image from source code. This uses the Python Imaging Library to generate a pixmap from the source code.'), + 'LatexFormatter': ('pygments.formatters.latex', 'LaTeX', ('latex', 'tex'), ('*.tex',), 'Format tokens as LaTeX code. This needs the `fancyvrb` and `color` standard packages.'), + 'NullFormatter': ('pygments.formatters.other', 'Text only', ('text', 'null'), ('*.txt',), 'Output the text unchanged without any formatting.'), + 'PangoMarkupFormatter': ('pygments.formatters.pangomarkup', 'Pango Markup', ('pango', 'pangomarkup'), (), 'Format tokens as Pango Markup code. It can then be rendered to an SVG.'), + 'RawTokenFormatter': ('pygments.formatters.other', 'Raw tokens', ('raw', 'tokens'), ('*.raw',), 'Format tokens as a raw representation for storing token streams.'), + 'RtfFormatter': ('pygments.formatters.rtf', 'RTF', ('rtf',), ('*.rtf',), 'Format tokens as RTF markup. This formatter automatically outputs full RTF documents with color information and other useful stuff. Perfect for Copy and Paste into Microsoft(R) Word(R) documents.'), + 'SvgFormatter': ('pygments.formatters.svg', 'SVG', ('svg',), ('*.svg',), 'Format tokens as an SVG graphics file. This formatter is still experimental. Each line of code is a ```` element with explicit ``x`` and ``y`` coordinates containing ```` elements with the individual token styles.'), + 'Terminal256Formatter': ('pygments.formatters.terminal256', 'Terminal256', ('terminal256', 'console256', '256'), (), 'Format tokens with ANSI color sequences, for output in a 256-color terminal or console. Like in `TerminalFormatter` color sequences are terminated at newlines, so that paging the output works correctly.'), + 'TerminalFormatter': ('pygments.formatters.terminal', 'Terminal', ('terminal', 'console'), (), 'Format tokens with ANSI color sequences, for output in a text console. Color sequences are terminated at newlines, so that paging the output works correctly.'), + 'TerminalTrueColorFormatter': ('pygments.formatters.terminal256', 'TerminalTrueColor', ('terminal16m', 'console16m', '16m'), (), 'Format tokens with ANSI color sequences, for output in a true-color terminal or console. Like in `TerminalFormatter` color sequences are terminated at newlines, so that paging the output works correctly.'), + 'TestcaseFormatter': ('pygments.formatters.other', 'Testcase', ('testcase',), (), 'Format tokens as appropriate for a new testcase.'), +} diff --git a/venv/lib/python3.11/site-packages/pygments/formatters/bbcode.py b/venv/lib/python3.11/site-packages/pygments/formatters/bbcode.py new file mode 100644 index 0000000..9ce4ebc --- /dev/null +++ b/venv/lib/python3.11/site-packages/pygments/formatters/bbcode.py @@ -0,0 +1,108 @@ +""" + pygments.formatters.bbcode + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + + BBcode formatter. + + :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + + +from pygments.formatter import Formatter +from pygments.util import get_bool_opt + +__all__ = ['BBCodeFormatter'] + + +class BBCodeFormatter(Formatter): + """ + Format tokens with BBcodes. These formatting codes are used by many + bulletin boards, so you can highlight your sourcecode with pygments before + posting it there. + + This formatter has no support for background colors and borders, as there + are no common BBcode tags for that. + + Some board systems (e.g. phpBB) don't support colors in their [code] tag, + so you can't use the highlighting together with that tag. + Text in a [code] tag usually is shown with a monospace font (which this + formatter can do with the ``monofont`` option) and no spaces (which you + need for indentation) are removed. + + Additional options accepted: + + `style` + The style to use, can be a string or a Style subclass (default: + ``'default'``). + + `codetag` + If set to true, put the output into ``[code]`` tags (default: + ``false``) + + `monofont` + If set to true, add a tag to show the code with a monospace font + (default: ``false``). + """ + name = 'BBCode' + aliases = ['bbcode', 'bb'] + filenames = [] + + def __init__(self, **options): + Formatter.__init__(self, **options) + self._code = get_bool_opt(options, 'codetag', False) + self._mono = get_bool_opt(options, 'monofont', False) + + self.styles = {} + self._make_styles() + + def _make_styles(self): + for ttype, ndef in self.style: + start = end = '' + if ndef['color']: + start += '[color=#%s]' % ndef['color'] + end = '[/color]' + end + if ndef['bold']: + start += '[b]' + end = '[/b]' + end + if ndef['italic']: + start += '[i]' + end = '[/i]' + end + if ndef['underline']: + start += '[u]' + end = '[/u]' + end + # there are no common BBcodes for background-color and border + + self.styles[ttype] = start, end + + def format_unencoded(self, tokensource, outfile): + if self._code: + outfile.write('[code]') + if self._mono: + outfile.write('[font=monospace]') + + lastval = '' + lasttype = None + + for ttype, value in tokensource: + while ttype not in self.styles: + ttype = ttype.parent + if ttype == lasttype: + lastval += value + else: + if lastval: + start, end = self.styles[lasttype] + outfile.write(''.join((start, lastval, end))) + lastval = value + lasttype = ttype + + if lastval: + start, end = self.styles[lasttype] + outfile.write(''.join((start, lastval, end))) + + if self._mono: + outfile.write('[/font]') + if self._code: + outfile.write('[/code]') + if self._code or self._mono: + outfile.write('\n') diff --git a/venv/lib/python3.11/site-packages/pygments/formatters/groff.py b/venv/lib/python3.11/site-packages/pygments/formatters/groff.py new file mode 100644 index 0000000..687fd54 --- /dev/null +++ b/venv/lib/python3.11/site-packages/pygments/formatters/groff.py @@ -0,0 +1,170 @@ +""" + pygments.formatters.groff + ~~~~~~~~~~~~~~~~~~~~~~~~~ + + Formatter for groff output. + + :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import math +from pygments.formatter import Formatter +from pygments.util import get_bool_opt, get_int_opt + +__all__ = ['GroffFormatter'] + + +class GroffFormatter(Formatter): + """ + Format tokens with groff escapes to change their color and font style. + + .. versionadded:: 2.11 + + Additional options accepted: + + `style` + The style to use, can be a string or a Style subclass (default: + ``'default'``). + + `monospaced` + If set to true, monospace font will be used (default: ``true``). + + `linenos` + If set to true, print the line numbers (default: ``false``). + + `wrap` + Wrap lines to the specified number of characters. Disabled if set to 0 + (default: ``0``). + """ + + name = 'groff' + aliases = ['groff','troff','roff'] + filenames = [] + + def __init__(self, **options): + Formatter.__init__(self, **options) + + self.monospaced = get_bool_opt(options, 'monospaced', True) + self.linenos = get_bool_opt(options, 'linenos', False) + self._lineno = 0 + self.wrap = get_int_opt(options, 'wrap', 0) + self._linelen = 0 + + self.styles = {} + self._make_styles() + + + def _make_styles(self): + regular = '\\f[CR]' if self.monospaced else '\\f[R]' + bold = '\\f[CB]' if self.monospaced else '\\f[B]' + italic = '\\f[CI]' if self.monospaced else '\\f[I]' + + for ttype, ndef in self.style: + start = end = '' + if ndef['color']: + start += '\\m[%s]' % ndef['color'] + end = '\\m[]' + end + if ndef['bold']: + start += bold + end = regular + end + if ndef['italic']: + start += italic + end = regular + end + if ndef['bgcolor']: + start += '\\M[%s]' % ndef['bgcolor'] + end = '\\M[]' + end + + self.styles[ttype] = start, end + + + def _define_colors(self, outfile): + colors = set() + for _, ndef in self.style: + if ndef['color'] is not None: + colors.add(ndef['color']) + + for color in sorted(colors): + outfile.write('.defcolor ' + color + ' rgb #' + color + '\n') + + + def _write_lineno(self, outfile): + self._lineno += 1 + outfile.write("%s% 4d " % (self._lineno != 1 and '\n' or '', self._lineno)) + + + def _wrap_line(self, line): + length = len(line.rstrip('\n')) + space = ' ' if self.linenos else '' + newline = '' + + if length > self.wrap: + for i in range(0, math.floor(length / self.wrap)): + chunk = line[i*self.wrap:i*self.wrap+self.wrap] + newline += (chunk + '\n' + space) + remainder = length % self.wrap + if remainder > 0: + newline += line[-remainder-1:] + self._linelen = remainder + elif self._linelen + length > self.wrap: + newline = ('\n' + space) + line + self._linelen = length + else: + newline = line + self._linelen += length + + return newline + + + def _escape_chars(self, text): + text = text.replace('\\', '\\[u005C]'). \ + replace('.', '\\[char46]'). \ + replace('\'', '\\[u0027]'). \ + replace('`', '\\[u0060]'). \ + replace('~', '\\[u007E]') + copy = text + + for char in copy: + if len(char) != len(char.encode()): + uni = char.encode('unicode_escape') \ + .decode()[1:] \ + .replace('x', 'u00') \ + .upper() + text = text.replace(char, '\\[u' + uni[1:] + ']') + + return text + + + def format_unencoded(self, tokensource, outfile): + self._define_colors(outfile) + + outfile.write('.nf\n\\f[CR]\n') + + if self.linenos: + self._write_lineno(outfile) + + for ttype, value in tokensource: + while ttype not in self.styles: + ttype = ttype.parent + start, end = self.styles[ttype] + + for line in value.splitlines(True): + if self.wrap > 0: + line = self._wrap_line(line) + + if start and end: + text = self._escape_chars(line.rstrip('\n')) + if text != '': + outfile.write(''.join((start, text, end))) + else: + outfile.write(self._escape_chars(line.rstrip('\n'))) + + if line.endswith('\n'): + if self.linenos: + self._write_lineno(outfile) + self._linelen = 0 + else: + outfile.write('\n') + self._linelen = 0 + + outfile.write('\n.fi') diff --git a/venv/lib/python3.11/site-packages/pygments/formatters/html.py b/venv/lib/python3.11/site-packages/pygments/formatters/html.py new file mode 100644 index 0000000..df2469e --- /dev/null +++ b/venv/lib/python3.11/site-packages/pygments/formatters/html.py @@ -0,0 +1,990 @@ +""" + pygments.formatters.html + ~~~~~~~~~~~~~~~~~~~~~~~~ + + Formatter for HTML output. + + :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import functools +import os +import sys +import os.path +from io import StringIO + +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 + +try: + import ctags +except ImportError: + ctags = None + +__all__ = ['HtmlFormatter'] + + +_escape_html_table = { + ord('&'): '&', + ord('<'): '<', + ord('>'): '>', + ord('"'): '"', + ord("'"): ''', +} + + +def escape_html(text, table=_escape_html_table): + """Escape &, <, > as well as single and double quotes for HTML.""" + return text.translate(table) + + +def webify(color): + if color.startswith('calc') or color.startswith('var'): + return color + else: + return '#' + color + + +def _get_ttype_class(ttype): + fname = STANDARD_TYPES.get(ttype) + if fname: + return fname + aname = '' + while fname is None: + aname = '-' + ttype[-1] + aname + ttype = ttype.parent + fname = STANDARD_TYPES.get(ttype) + return fname + aname + + +CSSFILE_TEMPLATE = '''\ +/* +generated by Pygments +Copyright 2006-2023 by the Pygments team. +Licensed under the BSD license, see LICENSE for details. +*/ +%(styledefs)s +''' + +DOC_HEADER = '''\ + + + + + %(title)s + + + + +

%(title)s

+ +''' + +DOC_HEADER_EXTERNALCSS = '''\ + + + + + %(title)s + + + + +

%(title)s

+ +''' + +DOC_FOOTER = '''\ + + +''' + + +class HtmlFormatter(Formatter): + r""" + Format tokens as HTML 4 ```` tags. By default, the content is enclosed + in a ``
`` tag, itself wrapped in a ``
`` tag (but see the `nowrap` option). + The ``
``'s CSS class can be set by the `cssclass` option. + + If the `linenos` option is set to ``"table"``, the ``
`` is
+    additionally wrapped inside a ```` which has one row and two
+    cells: one containing the line numbers and one containing the code.
+    Example:
+
+    .. sourcecode:: html
+
+        
+
+ + +
+
1
+            2
+
+
def foo(bar):
+              pass
+            
+
+ + (whitespace added to improve clarity). + + A list of lines can be specified using the `hl_lines` option to make these + lines highlighted (as of Pygments 0.11). + + With the `full` option, a complete HTML 4 document is output, including + the style definitions inside a ``