""" pygments.formatters.html ~~~~~~~~~~~~~~~~~~~~~~~~ Formatter for HTML output. :copyright: Copyright 2006-2025 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: # Check if the color can be shortened from 6 to 3 characters color = color.upper() if (len(color) == 6 and ( color[0] == color[1] and color[2] == color[3] and color[4] == color[5])): return f'#{color[0]}{color[2]}{color[4]}' else: return f'#{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-2025 by the Pygments team. Licensed under the BSD license, see LICENSE for details. */ %(styledefs)s ''' DOC_HEADER = '''\

## %(title)s

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

## %(title)s

''' DOC_FOOTER = '''\