Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
pip._vendor.pygments Namespace Reference

Namespaces

namespace  __main__
 
namespace  cmdline
 
namespace  console
 
namespace  filter
 
namespace  filters
 
namespace  formatter
 
namespace  formatters
 
namespace  lexer
 
namespace  lexers
 
namespace  modeline
 
namespace  plugin
 
namespace  regexopt
 
namespace  scanner
 
namespace  sphinxext
 
namespace  style
 
namespace  styles
 
namespace  token
 
namespace  unistring
 
namespace  util
 

Functions

 lex (code, lexer)
 
 format (tokens, formatter, outfile=None)
 
 highlight (code, lexer, formatter, outfile=None)
 

Detailed Description

    Pygments
    ~~~~~~~~

    Pygments is a syntax highlighting package written in Python.

    It is a generic syntax highlighter for general use in all kinds of software
    such as forum systems, wikis or other applications that need to prettify
    source code. Highlights are:

    * a wide range of common languages and markup formats is supported
    * special attention is paid to details, increasing quality by a fair amount
    * support for new languages and formats are added easily
    * a number of output formats, presently HTML, LaTeX, RTF, SVG, all image
      formats that PIL supports, and ANSI sequences
    * it is usable as a command-line tool and as a library
    * ... and it highlights even Brainfuck!

    The `Pygments master branch`_ is installable with ``easy_install Pygments==dev``.

    .. _Pygments master branch:
       https://github.com/pygments/pygments/archive/master.zip#egg=Pygments-dev

    :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.

Function Documentation

◆ format()

format (   tokens,
  formatter,
  outfile = None 
)
Format ``tokens`` (an iterable of tokens) with the formatter ``formatter``
(a `Formatter` instance).

If ``outfile`` is given and a valid file object (an object with a
``write`` method), the result will be written to it, otherwise it
is returned as a string.

Definition at line 52 of file __init__.py.

52def format(tokens, formatter, outfile=None): # pylint: disable=redefined-builtin
53 """
54 Format ``tokens`` (an iterable of tokens) with the formatter ``formatter``
55 (a `Formatter` instance).
56
57 If ``outfile`` is given and a valid file object (an object with a
58 ``write`` method), the result will be written to it, otherwise it
59 is returned as a string.
60 """
61 try:
62 if not outfile:
63 realoutfile = getattr(formatter, 'encoding', None) and BytesIO() or StringIO()
64 formatter.format(tokens, realoutfile)
66 else:
67 formatter.format(tokens, outfile)
68 except TypeError:
69 # Heuristic to catch a common mistake.
70 from pip._vendor.pygments.formatter import Formatter
71 if isinstance(formatter, type) and issubclass(formatter, Formatter):
72 raise TypeError('format() argument must be a formatter instance, '
73 'not a class')
74 raise
75
76
for i

References i.

Referenced by pip._vendor.pygments.highlight().

Here is the caller graph for this function:

◆ highlight()

highlight (   code,
  lexer,
  formatter,
  outfile = None 
)
This is the most high-level highlighting function. It combines `lex` and
`format` in one function.

Definition at line 77 of file __init__.py.

77def highlight(code, lexer, formatter, outfile=None):
78 """
79 This is the most high-level highlighting function. It combines `lex` and
80 `format` in one function.
81 """
82 return format(lex(code, lexer), formatter, outfile)

References pip._vendor.pygments.format(), and pip._vendor.pygments.lex().

Here is the call graph for this function:

◆ lex()

lex (   code,
  lexer 
)
Lex `code` with the `lexer` (must be a `Lexer` instance)
and return an iterable of tokens. Currently, this only calls
`lexer.get_tokens()`.

Definition at line 35 of file __init__.py.

35def lex(code, lexer):
36 """
37 Lex `code` with the `lexer` (must be a `Lexer` instance)
38 and return an iterable of tokens. Currently, this only calls
39 `lexer.get_tokens()`.
40 """
41 try:
42 return lexer.get_tokens(code)
43 except TypeError:
44 # Heuristic to catch a common mistake.
45 from pip._vendor.pygments.lexer import RegexLexer
46 if isinstance(lexer, type) and issubclass(lexer, RegexLexer):
47 raise TypeError('lex() argument must be a lexer instance, '
48 'not a class')
49 raise
50
51

References i.

Referenced by pip._vendor.pygments.highlight().

Here is the caller graph for this function: