CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-myst-parser

An extended CommonMark compliant parser, with bridges to docutils and Sphinx

Pending
Overview
Eval results
Files

cli-tools.mddocs/

CLI Tools

Command-line utilities for MyST document processing, including HTML, LaTeX, XML output generation, heading anchor extraction, and inventory management.

Capabilities

Anchor Extraction

Extract and display heading anchors from MyST documents, useful for link validation and cross-reference management.

def print_anchors(args=None) -> None:
    """
    CLI command to print heading anchors from MyST files.
    
    Scans MyST documents and extracts all heading anchors,
    displaying them in a format suitable for cross-reference validation.
    
    Args:
        args: Command-line arguments (optional, uses sys.argv if None)
    """

Command-line usage:

# Extract anchors from single file
myst-anchors document.md

# Extract anchors from multiple files
myst-anchors docs/*.md

# Output format: filename:line:anchor
# example.md:5:section-header
# example.md:12:subsection-title

Usage example:

from myst_parser.cli import print_anchors
import sys

# Programmatic usage
sys.argv = ['myst-anchors', 'example.md']
print_anchors()

# Or with explicit args
print_anchors(['example.md', '--format=json'])

Inventory Management

Comprehensive inventory management for Sphinx cross-reference integration, supporting loading, conversion, and manipulation of inventory data.

def inventory_cli(inputs: None | list[str] = None) -> None:
    """
    Command line interface for fetching and parsing an inventory.
    
    Provides functionality for loading, parsing, and filtering Sphinx
    inventory files for cross-reference integration.
    
    Args:
        inputs: Optional list of command-line arguments
    """

Command-line usage:

# Load and display inventory
myst-inv load https://docs.python.org/3/objects.inv

# Convert inventory format
myst-inv convert --input objects.inv --output inventory.json

# Validate inventory
myst-inv validate objects.inv

# Search inventory
myst-inv search --query "dict" objects.inv

Usage example:

from myst_parser.inventory import inventory_cli
import sys

# Load inventory programmatically
sys.argv = ['myst-inv', 'load', 'objects.inv']
inventory_cli()

# Convert inventory format
sys.argv = ['myst-inv', 'convert', '--format', 'json', 'objects.inv']
inventory_cli()

Docutils Output Formats

Comprehensive set of docutils-based output generators supporting multiple formats including HTML, LaTeX, XML, and pseudoXML.

def cli_html(argv: list[str] | None = None) -> None:
    """
    Cmdline entrypoint for converting MyST to HTML.
    
    Args:
        argv: Command-line arguments list
    """

def cli_html5(argv: list[str] | None = None) -> None:
    """
    Cmdline entrypoint for converting MyST to HTML5.
    
    Args:
        argv: Command-line arguments list
    """

def cli_html5_demo(argv: list[str] | None = None) -> None:
    """
    Cmdline entrypoint for converting MyST to simple HTML5 demonstrations.
    
    This is a special case of the HTML5 writer that only outputs
    the body of the document.
    
    Args:
        argv: Command-line arguments list
    """

def cli_latex(argv: list[str] | None = None) -> None:
    """
    Cmdline entrypoint for converting MyST to LaTeX.
    
    Args:
        argv: Command-line arguments list
    """

def cli_xml(argv: list[str] | None = None) -> None:
    """
    Cmdline entrypoint for converting MyST to XML.
    
    Args:
        argv: Command-line arguments list
    """

def cli_pseudoxml(argv: list[str] | None = None) -> None:
    """
    Cmdline entrypoint for converting MyST to pseudoXML.
    
    Args:
        argv: Command-line arguments list
    """

Command-line usage:

# Generate HTML output
myst-docutils-html input.md output.html

# Generate HTML5 with modern features
myst-docutils-html5 input.md output.html

# Generate demo HTML with styling
myst-docutils-demo input.md output.html

# Generate LaTeX output
myst-docutils-latex input.md output.tex

# Generate XML for processing
myst-docutils-xml input.md output.xml

# Generate pseudoXML for debugging
myst-docutils-pseudoxml input.md output.xml

Usage example:

from myst_parser.parsers.docutils_ import cli_html, cli_latex

# Generate HTML output
cli_html(['document.md', 'output.html'])

# Generate LaTeX output with custom settings
cli_latex([
    'document.md', 
    'output.tex',
    '--documentclass=article',
    '--use-latex-citations'
])

Advanced Output Options

All CLI tools support advanced configuration options for customizing output generation and processing behavior.

# Common options for all output formats:

# Configuration file
--config config.json

# MyST extensions
--myst-enable-extensions=tasklist,deflist,substitution

# Heading anchors
--myst-heading-anchors=3

# Math rendering
--myst-dmath-double-inline

# Footnote handling
--myst-footnote-transition
--myst-footnote-sort

# HTML-specific options (myst-docutils-html, myst-docutils-html5)
--stylesheet-path=custom.css
--template=custom-template.html
--embed-stylesheet

# LaTeX-specific options (myst-docutils-latex)
--documentclass=article
--use-latex-citations
--latex-preamble=preamble.tex

# XML-specific options (myst-docutils-xml)
--xml-declaration
--encoding=utf-8

Usage examples:

# HTML with custom styling and extensions
myst-docutils-html5 \
    --myst-enable-extensions=tasklist,deflist,substitution \
    --myst-heading-anchors=3 \
    --stylesheet-path=docs.css \
    --embed-stylesheet \
    input.md output.html

# LaTeX with academic formatting
myst-docutils-latex \
    --myst-enable-extensions=amsmath,dollarmath \
    --documentclass=article \
    --use-latex-citations \
    --latex-preamble=preamble.tex \
    paper.md paper.tex

# XML for further processing
myst-docutils-xml \
    --myst-enable-extensions=substitution \
    --xml-declaration \
    --encoding=utf-8 \
    document.md document.xml

Batch Processing

All CLI tools support batch processing of multiple files and directories:

# Process multiple files
myst-docutils-html *.md

# Process directory recursively
myst-docutils-html5 --recursive docs/ output/

# Process with pattern matching
myst-docutils-latex docs/**/*.md output/

Configuration Files

CLI tools support configuration files for consistent processing across projects:

// myst-config.json
{
    "myst_enable_extensions": [
        "tasklist",
        "deflist", 
        "substitution",
        "colon_fence"
    ],
    "myst_heading_anchors": 3,
    "myst_footnote_transition": true,
    "myst_dmath_double_inline": true,
    "html_theme": "alabaster",
    "latex_documentclass": "article"
}
# Use configuration file
myst-docutils-html5 --config myst-config.json input.md output.html

Output Validation and Debugging

Tools for validating and debugging MyST document processing:

# Validate MyST syntax
myst-docutils-pseudoxml document.md > debug.xml

# Check for parsing warnings
myst-docutils-html document.md output.html --verbose

# Validate cross-references
myst-anchors document.md --validate-refs

# Debug inventory loading
myst-inv validate --verbose objects.inv

Command Reference

Complete list of available CLI commands:

CommandPurposeModule Path
myst-anchorsExtract heading anchorsmyst_parser.cli:print_anchors
myst-invInventory managementmyst_parser.inventory:inventory_cli
myst-docutils-htmlHTML outputmyst_parser.parsers.docutils_:cli_html
myst-docutils-html5HTML5 outputmyst_parser.parsers.docutils_:cli_html5
myst-docutils-demoHTML5 demomyst_parser.parsers.docutils_:cli_html5_demo
myst-docutils-latexLaTeX outputmyst_parser.parsers.docutils_:cli_latex
myst-docutils-xmlXML outputmyst_parser.parsers.docutils_:cli_xml
myst-docutils-pseudoxmlPseudoXML outputmyst_parser.parsers.docutils_:cli_pseudoxml

Types

CLI-related type definitions:

# CLI function signature
CLIFunction = Callable[[list[str] | None], None]

# Configuration types
ConfigDict = dict[str, any]
OutputFormat = Literal["html", "html5", "latex", "xml", "pseudoxml"]

# Command result types
class CLIResult:
    """Result from CLI command execution."""
    success: bool
    output: str
    errors: list[str]

Install with Tessl CLI

npx tessl i tessl/pypi-myst-parser

docs

cli-tools.md

configuration.md

document-rendering.md

index.md

inventory-warnings.md

parsing.md

sphinx-extension.md

tile.json