Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions docs/src/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ Different import styles are supported, along with all Python syntax.
Star imports might be particularly handy in code examples.
`Doctest <https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html
#doctest-blocks>`_ and console blocks using :code:`.. code:: pycon` work too.
Including code via :rst:dir:`literalinclude` requires using a
:code:`:language: py` parameter.
Including code via :rst:dir:`literalinclude` requires using one of the following parameters:
:code:`:language: python`, :code:`:language: python3`,
:code:`:language: py`, :code:`:language: py3`, :code:`:language: pyi`,
:code:`:language: sage`, :code:`:language: bazel`, :code:`:language: starlark`
(i.e., the list of
`Pygments Lexers <https://pygments.org/docs/lexers/#pygments.lexers.python.PythonLexer>`_).


.. code:: pycon

Expand Down
4 changes: 4 additions & 0 deletions docs/src/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ These release notes are based on
sphinx-codeautolink adheres to
`Semantic Versioning <https://semver.org>`_.

0.16.3 (unreleased)
-------------------
- Add more Pygments lexer aliases in code blocks (:issue:`160`)

0.16.2 (2025-01-16)
-------------------
- Fix regression in not handling malformed return types (:issue:`159`)
Expand Down
12 changes: 11 additions & 1 deletion src/sphinx_codeautolink/extension/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@
from .backref import CodeExample
from .directive import ConcatMarker, PrefaceMarker, SkipMarker

BUILTIN_BLOCKS = {"python": None, "py": None}
# list from https://pygments.org/docs/lexers/#pygments.lexers.python.PythonLexer
BUILTIN_BLOCKS = {
"python": None,
"python3": None,
"py": None,
"py3": None,
"pyi": None,
"sage": None,
"bazel": None,
"starlark": None,
}


@dataclass
Expand Down
13 changes: 13 additions & 0 deletions tests/extension/ref/pygments_lexer_code-block_bazel.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
test_project
test_project.bar
# split
# split
Test project
============

.. code-block:: bazel

import test_project
test_project.bar()

.. automodule:: test_project
13 changes: 13 additions & 0 deletions tests/extension/ref/pygments_lexer_code-block_py3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
test_project
test_project.bar
# split
# split
Test project
============

.. code-block:: py3

import test_project
test_project.bar()

.. automodule:: test_project
13 changes: 13 additions & 0 deletions tests/extension/ref/pygments_lexer_code-block_pyi.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
test_project
test_project.bar
# split
# split
Test project
============

.. code-block:: pyi

import test_project
test_project.bar()

.. automodule:: test_project
13 changes: 13 additions & 0 deletions tests/extension/ref/pygments_lexer_code-block_python3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
test_project
test_project.bar
# split
# split
Test project
============

.. code-block:: python3

import test_project
test_project.bar()

.. automodule:: test_project
13 changes: 13 additions & 0 deletions tests/extension/ref/pygments_lexer_code-block_sage.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
test_project
test_project.bar
# split
# split
Test project
============

.. code-block:: sage

import test_project
test_project.bar()

.. automodule:: test_project
13 changes: 13 additions & 0 deletions tests/extension/ref/pygments_lexer_code-block_starlark.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
test_project
test_project.bar
# split
# split
Test project
============

.. code-block:: starlark

import test_project
test_project.bar()

.. automodule:: test_project