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 |
|---|---|
|
Preferred directory-tree fence name |
|
Explicit directory-tree alias |
|
Short directory-tree alias |
Config values¶
-
gp_highlighting_inline_literals¶gp_highlighting_inline_literals¶
Inline literal auto-highlighting mode. Use
'safe'to highlight configured commands and clear path/directory literals.- Type:
- Default:
'off'- Registered by:
Roles¶
API¶
-
sphinx_gp_highlighting.setup(app)¶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:
RegexLexerLexer 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=())¶sphinx_gp_highlighting.inline.classify_inline_literal(text, *, commands=())¶
Classify a literal that is safe to highlight automatically.
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)¶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