Skip to main content

Sphinx extension adding a directive for a parsed code-block

Project description

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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinx_parsed_codeblock-1.0.0.tar.gz (46.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sphinx_parsed_codeblock-1.0.0-py3-none-any.whl (33.5 kB view details)

Uploaded Python 3

File details

Details for the file sphinx_parsed_codeblock-1.0.0.tar.gz.

File metadata

  • Download URL: sphinx_parsed_codeblock-1.0.0.tar.gz
  • Upload date:
  • Size: 46.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for sphinx_parsed_codeblock-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c53dcd4ebacbb001bd579788487e13020f792b145b164cfc684e126e74468232
MD5 7e179d8e95521db95fb3108279813969
BLAKE2b-256 3a0d884aeb8b5a77d8cdb7654207d6797760515e7ed9bc9c63d64c1da3a9054e

See more details on using hashes here.

File details

Details for the file sphinx_parsed_codeblock-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sphinx_parsed_codeblock-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4e64efe3dddadfce952f994df6065cd5ee9faec0f3fafe396e3f4420b53f7f37
MD5 f3d95d550a4ecebcfc0bbb29150436a7
BLAKE2b-256 f4fb7007207ae460d4bbba3d3c12006ce6909ef43ebfe52b0203044eb4354712

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page