Table Of Contents
sphinx-inlinecode
sphinx-inlinecode
is a Sphinx extension that embeds source code blocks directly into your documentation as a dropdown.
Example
- sphinx_inlinecode.get_code_block(qualname, obj, highlighter)[source]View on GitHub
Parses and highlights the source code lines of the provided object
- Parameters:
- Returns:
the highlighted and fully formatted HTML codeblock to insert
- Return type:
Unlike sphinx.ext.viewcode
, source code blocks will also be added for property
and cached_property
entries
Installation
To install sphinx-inlinecode
via pip:
pip install sphinx-inlinecode
Configuration
Add the extension to your conf.py
extensions = [
"sphinx_inlinecode",
]
sphinx_inlinecode
package
- sphinx_inlinecode.BAD_OBJTYPES = ('attribute', 'data', 'decorator')
Object types that can’t have code blocks inserted
- sphinx_inlinecode.add_static_path(app)[source]View on GitHub
Add the path for the
_static
folder
- sphinx_inlinecode.add_source_code(app, exception)[source]View on GitHub
Inserts source code blocks into documentation entries.
- sphinx_inlinecode.parse_py_domain(app)[source]View on GitHub
Parses all Python objects in the package from the
BuildEnvironment
- sphinx_inlinecode.add_code_blocks(file, objects, highlighter)[source]View on GitHub
Inserts source code blocks into the provided HTML file and writes the output.
- sphinx_inlinecode.get_target(viewcode_link)[source]View on GitHub
Parses the fully qualified object name from the viewcode internal reference
- Parameters:
viewcode_link (Tag) – the viewcode internal reference
- Returns:
the fully qualified name of the referenced object
- Return type:
- sphinx_inlinecode.get_code_block(qualname, obj, highlighter)[source]View on GitHub
Parses and highlights the source code lines of the provided object
- Parameters:
- Returns:
the highlighted and fully formatted HTML codeblock to insert
- Return type:
- sphinx_inlinecode.wrap_code_block(code_block)[source]View on GitHub
Wraps the given code block inside a
<details>
HTML element- Parameters:
code_block (str) – HTML of the code block to wrap
- Returns:
the wrapped code block
- Return type: