Skip to main content

sphinx_parsed_codeblock

Sphinx extension adding a directive for a parsed code-block.

Intro

Have you ever tried to use markup inside a code-block? For example, to create a link from inside some code? Disappointingly, there is no such functionality in sphinx - a choice must be made between the markup (via the parsed-literal directive) and the syntax highlighting (via the code-block/sourcecode/code directive). However, with this extension, that is no longer the case! A new directive, parsed-code-block, is provided, which mixes the functionality of both, providing support for markup inside syntax-highlighted code-block.

Quickstart

The extension can be installed via pip:

pip install sphinx_parsed_codeblock

Then, by including the extension in conf.py or pyproject.toml:

extensions = ['sphinx_parsed_codeblock']

the new directive can be used anywhere in the RST documentation:

.. parsed-code-block:: yaml

    foo:
        italics: *"string"*
        bold: **12345**
        ``literal: null``
        link: :ref:`true<doc-top>`

The parsed-code-block directive is a subclass of the default code-block directive and so can be used with all the same options and arguments:

.. parsed-code-block:: yaml
    :linenos:
    :lineno-start: 5
    :emphasize-lines: 2, 4
    :caption: test
    :name: test-code-block

    foo:
        italics: *"string"*
        bold: **12345**
        ``literal: null``
        link: :ref:`true<doc-top>`

For more information, see documentation.

Functionality

This extension provides one new directive - parsed-code-block - which allows for RST markup to be used inside a syntax-highlighted code-block. All inline markup is supported:

  • italics (*italics*)
  • bold (**bold**)
  • literal (``literal``)
  • link (:ref:`link` )
  • etc.

though higher-level RST such as directives will not be parsed.

Supported Output Formats

  • HTML

For all other formats, the parsed-code-block is treated the same as parsed-literal, so output will be produced, but without syntax highlighting.

Contributing

The project is considered generally feature complete, but if anything is not working as expected, please open an issue!

Release files for sphinx-parsed-codeblock 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sphinx-parsed-codeblock 1.0.0
File Size Uploaded
sphinx_parsed_codeblock-1.0.0.tar.gz 46.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sphinx-parsed-codeblock 1.0.0
File Interpreter ABI Platform
sphinx_parsed_codeblock-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 80.4 kB

Release files / sphinx_parsed_codeblock-1.0.0.tar.gz

Download URL sphinx_parsed_codeblock-1.0.0.tar.gz
Size 46.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c53dcd4ebacbb001bd579788487e13020f792b145b164cfc684e126e74468232
BLAKE2b-256 checksum
How to use checksums
3a0d884aeb8b5a77d8cdb7654207d6797760515e7ed9bc9c63d64c1da3a9054e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release files / sphinx_parsed_codeblock-1.0.0-py3-none-any.whl

Download URL sphinx_parsed_codeblock-1.0.0-py3-none-any.whl
Size 33.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4e64efe3dddadfce952f994df6065cd5ee9faec0f3fafe396e3f4420b53f7f37
BLAKE2b-256 checksum
How to use checksums
f4fb7007207ae460d4bbba3d3c12006ce6909ef43ebfe52b0203044eb4354712
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page