summaryrefslogtreecommitdiff
path: root/pygments/__init__.py
diff options
context:
space:
mode:
authorJean Abou Samra <jean@abou-samra.fr>2023-03-30 22:02:41 +0200
committerJean Abou Samra <jean@abou-samra.fr>2023-03-30 22:02:41 +0200
commit09c8a31039366b03c3b7e117ee998eaa43f9c7dc (patch)
tree5e3048353ed6f630752ec4ee5b3ffa8c37ef7644 /pygments/__init__.py
parentc664784df695536d119c1eb13b3578458e1317f0 (diff)
downloadpygments-git-09c8a31039366b03c3b7e117ee998eaa43f9c7dc.tar.gz
Use autodoc a bit more
Diffstat (limited to 'pygments/__init__.py')
-rw-r--r--pygments/__init__.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/pygments/__init__.py b/pygments/__init__.py
index 7078c45d..afd36682 100644
--- a/pygments/__init__.py
+++ b/pygments/__init__.py
@@ -34,7 +34,9 @@ __all__ = ['lex', 'format', 'highlight']
def lex(code, lexer):
"""
- Lex ``code`` with ``lexer`` and return an iterable of tokens.
+ Lex `code` with the `lexer` (must be a `Lexer` instance)
+ and return an iterable of tokens. Currently, this only calls
+ `lexer.get_tokens()`.
"""
try:
return lexer.get_tokens(code)
@@ -49,11 +51,12 @@ def lex(code, lexer):
def format(tokens, formatter, outfile=None): # pylint: disable=redefined-builtin
"""
- Format a tokenlist ``tokens`` with the formatter ``formatter``.
+ 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.
+ 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.
"""
try:
if not outfile:
@@ -73,10 +76,7 @@ def format(tokens, formatter, outfile=None): # pylint: disable=redefined-builti
def highlight(code, lexer, formatter, outfile=None):
"""
- Lex ``code`` with ``lexer`` and format it with the formatter ``formatter``.
-
- 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.
+ This is the most high-level highlighting function. It combines `lex` and
+ `format` in one function.
"""
return format(lex(code, lexer), formatter, outfile)