Reference

sphinx_gp_highlighting/__init__.py.

Registered surface

Copyable config snippet

extensions = [
    "sphinx_gp_highlighting",
]

Lexers

sphinx-gp-highlighting registers these Pygments aliases:

Alias

Purpose

tree

Preferred directory-tree fence name

directory-tree

Explicit directory-tree alias

dir-tree

Short directory-tree alias

Config values

gp_highlighting_inline_literals
config env
config env
gp_highlighting_inline_literals

Inline literal auto-highlighting mode. Use 'safe' to highlight configured commands and clear path/directory literals.

Type:

str

Default:

'off'

Registered by:

sphinx_gp_highlighting.setup()

gp_highlighting_inline_commands
config env
config env
gp_highlighting_inline_commands

Command names eligible for safe inline literal highlighting when gp_highlighting_inline_literals is 'safe'.

Type:

list | tuple

Default:

[]

Registered by:

sphinx_gp_highlighting.setup()

Roles

:cmd:
role
role
:cmd:

Role for inline shell commands.

class:

class_option

:path:
role
role
:path:

Role for inline filesystem paths.

class:

class_option

:dir:
role
role
:dir:

Role for inline filesystem directories.

class:

class_option

API

sphinx_gp_highlighting.setup(app)
function[source]
function[source]
sphinx_gp_highlighting.setup(app)

Register the package lexers with Sphinx.

Parameters:

app (Sphinx) – Sphinx application instance.

Returns:

Extension metadata with version and parallel-build flags.

Return type:

ExtensionMetadata

Examples

>>> from sphinx_gp_highlighting import setup
>>> callable(setup)
True
class sphinx_gp_highlighting.lexers.DirectoryTreeLexer
class sphinx_gp_highlighting.lexers.DirectoryTreeLexer

Bases: RegexLexer

Lexer for tree(1)-style directory listings.

The lexer targets documentation snippets that show project layouts with box-drawing connectors. It deliberately uses standard Pygments token types so existing Sphinx styles can colour the output without package-specific token CSS.

Examples

>>> from pygments.token import Token
>>> lexer = DirectoryTreeLexer()
>>> source = '''\
... root
... └── pyproject.toml  # config
... '''
>>> tokens = list(lexer.get_tokens(source))
>>> (Token.Punctuation, '└──') in tokens
True
>>> (Token.Name, 'pyproject.toml') in tokens
True
>>> (Token.Comment.Single, '# config') in tokens
True
sphinx_gp_highlighting.inline.classify_inline_literal(text, *, commands=())
function[source]
function[source]
sphinx_gp_highlighting.inline.classify_inline_literal(text, *, commands=())

Classify a literal that is safe to highlight automatically.

Parameters:
  • text (str) – Literal text.

  • commands (iterable of str) – Command names eligible for bare command highlighting.

Returns:

The safe literal kind, or None when the text should remain an ordinary inline literal.

Return type:

InlineLiteralKind | None

Examples

>>> classify_inline_literal("tmuxp freeze my-session", commands=["tmuxp"])
'command'
>>> classify_inline_literal("~/.config/tmuxp/")
'dir'
>>> classify_inline_literal("module_name") is None
True
sphinx_gp_highlighting.inline.build_highlighted_literal(text, kind)
function[source]
function[source]
sphinx_gp_highlighting.inline.build_highlighted_literal(text, kind)

Build a literal node with package highlighting classes.

Parameters:
  • text (str) – Literal text.

  • kind (InlineLiteralKind) – Highlighting kind.

Returns:

Literal node ready for the Sphinx HTML writer.

Return type:

nodes.literal

Examples

>>> node = build_highlighted_literal("tmuxp freeze my-session", "command")
>>> node["language"]
'bash'
>>> "gp-sphinx-highlighting-inline--kind-command" in node["classes"]
True
>>> "language" in build_highlighted_literal("~/.config/tmuxp/", "dir")
False