Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 92ee454

Browse files
authored
Support more Python Pygments lexer aliases (felix-hilden#162)
Closes felix-hilden#160
1 parent 28b77b7 commit 92ee454

9 files changed

+100
-3
lines changed

docs/src/examples.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ Different import styles are supported, along with all Python syntax.
2323
Star imports might be particularly handy in code examples.
2424
`Doctest <https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html
2525
#doctest-blocks>`_ and console blocks using :code:`.. code:: pycon` work too.
26-
Including code via :rst:dir:`literalinclude` requires using a
27-
:code:`:language: py` parameter.
26+
Including code via :rst:dir:`literalinclude` requires using one of the following parameters:
27+
:code:`:language: python`, :code:`:language: python3`,
28+
:code:`:language: py`, :code:`:language: py3`, :code:`:language: pyi`,
29+
:code:`:language: sage`, :code:`:language: bazel`, :code:`:language: starlark`
30+
(i.e., the list of
31+
`Pygments Lexers <https://pygments.org/docs/lexers/#pygments.lexers.python.PythonLexer>`_).
32+
2833

2934
.. code:: pycon
3035

docs/src/release_notes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ These release notes are based on
88
sphinx-codeautolink adheres to
99
`Semantic Versioning <https://semver.org>`_.
1010

11+
0.16.3 (unreleased)
12+
-------------------
13+
- Add more Pygments lexer aliases in code blocks (:issue:`160`)
14+
1115
0.16.2 (2025-01-16)
1216
-------------------
1317
- Fix regression in not handling malformed return types (:issue:`159`)

src/sphinx_codeautolink/extension/block.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@
1717
from .backref import CodeExample
1818
from .directive import ConcatMarker, PrefaceMarker, SkipMarker
1919

20-
BUILTIN_BLOCKS = {"python": None, "py": None}
20+
# list from https://pygments.org/docs/lexers/#pygments.lexers.python.PythonLexer
21+
BUILTIN_BLOCKS = {
22+
"python": None,
23+
"python3": None,
24+
"py": None,
25+
"py3": None,
26+
"pyi": None,
27+
"sage": None,
28+
"bazel": None,
29+
"starlark": None,
30+
}
2131

2232

2333
@dataclass
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
test_project
2+
test_project.bar
3+
# split
4+
# split
5+
Test project
6+
============
7+
8+
.. code-block:: bazel
9+
10+
import test_project
11+
test_project.bar()
12+
13+
.. automodule:: test_project
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
test_project
2+
test_project.bar
3+
# split
4+
# split
5+
Test project
6+
============
7+
8+
.. code-block:: py3
9+
10+
import test_project
11+
test_project.bar()
12+
13+
.. automodule:: test_project
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
test_project
2+
test_project.bar
3+
# split
4+
# split
5+
Test project
6+
============
7+
8+
.. code-block:: pyi
9+
10+
import test_project
11+
test_project.bar()
12+
13+
.. automodule:: test_project
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
test_project
2+
test_project.bar
3+
# split
4+
# split
5+
Test project
6+
============
7+
8+
.. code-block:: python3
9+
10+
import test_project
11+
test_project.bar()
12+
13+
.. automodule:: test_project
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
test_project
2+
test_project.bar
3+
# split
4+
# split
5+
Test project
6+
============
7+
8+
.. code-block:: sage
9+
10+
import test_project
11+
test_project.bar()
12+
13+
.. automodule:: test_project
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
test_project
2+
test_project.bar
3+
# split
4+
# split
5+
Test project
6+
============
7+
8+
.. code-block:: starlark
9+
10+
import test_project
11+
test_project.bar()
12+
13+
.. automodule:: test_project

0 commit comments

Comments
 (0)