Debian Codegraph @

doc/docs/lexers.rst

raw
1 .. -*- mode: rst -*-
2
3 ================
4 Available lexers
5 ================
6
7 This page lists all available builtin lexers and the options they take.
8
9 Currently, **all lexers** support these options:
10
11 `stripnl`
12 Strip leading and trailing newlines from the input (default: ``True``)
13
14 `stripall`
15 Strip all leading and trailing whitespace from the input (default:
16 ``False``).
17
18 `ensurenl`
19 Make sure that the input ends with a newline (default: ``True``). This
20 is required for some lexers that consume input linewise.
21
22 .. versionadded:: 1.3
23
24 `tabsize`
25 If given and greater than 0, expand tabs in the input (default: ``0``).
26
27 `encoding`
28 If given, must be an encoding name (such as ``"utf-8"``). This encoding
29 will be used to convert the input string to Unicode (if it is not already
30 a Unicode string). The default is ``"guess"``.
31
32 If this option is set to ``"guess"``, a simple UTF-8 vs. Latin-1
33 detection is used, if it is set to ``"chardet"``, the
34 `chardet library <https://chardet.github.io/>`_ is used to
35 guess the encoding of the input.
36
37 .. versionadded:: 0.6
38
39
40 The "Short Names" field lists the identifiers that can be used with the
41 `get_lexer_by_name()` function.
42
43 These lexers are builtin and can be imported from `pygments.lexers`:
44
45 .. pygmentsdoc:: lexers
46
47
48 Iterating over all lexers
49 -------------------------
50
51 .. versionadded:: 0.6
52
53 To get all lexers (both the builtin and the plugin ones), you can
54 use the `get_all_lexers()` function from the `pygments.lexers`
55 module:
56
57 .. sourcecode:: pycon
58
59 >>> from pygments.lexers import get_all_lexers
60 >>> i = get_all_lexers()
61 >>> i.next()
62 ('Diff', ('diff',), ('*.diff', '*.patch'), ('text/x-diff', 'text/x-patch'))
63 >>> i.next()
64 ('Delphi', ('delphi', 'objectpascal', 'pas', 'pascal'), ('*.pas',), ('text/x-pascal',))
65 >>> i.next()
66 ('XML+Ruby', ('xml+ruby', 'xml+erb'), (), ())
67
68 As you can see, the return value is an iterator which yields tuples
69 in the form ``(name, aliases, filetypes, mimetypes)``.