CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-myst-nb

A Jupyter Notebook Sphinx reader built on top of the MyST markdown parser.

Pending
Overview
Eval results
Files

cli.mddocs/

Command Line Interface

Complete command-line interface for project creation, notebook conversion, and document generation across multiple output formats. The CLI provides standalone tools for MyST-NB functionality outside of Sphinx.

Capabilities

Project Creation

Command-line tool for creating new MyST-NB projects with proper structure and configuration.

def quickstart(args: list[str] | None = None) -> None:
    """
    Create a new MyST-NB project with basic structure and configuration.
    
    Parameters:
    - args: Optional command-line arguments list
    
    Creates directory structure, configuration files, and example notebooks.
    """

CLI Entry Point: mystnb-quickstart

Notebook Conversion

Convert MyST markdown files to Jupyter notebook format.

def md_to_nb(args: list[str] | None = None) -> None:
    """
    Convert MyST markdown to Jupyter notebook format.
    
    Parameters:
    - args: Optional command-line arguments list
    
    Converts .md files with notebook content to .ipynb format
    while preserving cell structure and metadata.
    """

CLI Entry Point: mystnb-to-jupyter

Docutils Output Commands

Direct document generation using docutils backend for various output formats.

HTML Output

def cli_html(argv: list[str] | None = None) -> None:
    """
    Generate HTML output from notebook using docutils.
    
    Parameters:
    - argv: Command-line arguments for HTML generation
    
    Processes notebook and generates standalone HTML document.
    """

CLI Entry Point: mystnb-docutils-html

HTML5 Output

def cli_html5(argv: list[str] | None = None):
    """
    Generate HTML5 output from notebook using docutils.
    
    Parameters:
    - argv: Command-line arguments for HTML5 generation
    
    Processes notebook and generates HTML5 document with modern features.
    """

CLI Entry Point: mystnb-docutils-html5

LaTeX Output

def cli_latex(argv: list[str] | None = None):
    """
    Generate LaTeX output from notebook using docutils.
    
    Parameters:
    - argv: Command-line arguments for LaTeX generation
    
    Processes notebook and generates LaTeX document suitable for PDF compilation.
    """

CLI Entry Point: mystnb-docutils-latex

XML Output

def cli_xml(argv: list[str] | None = None):
    """
    Generate XML output from notebook using docutils.
    
    Parameters:
    - argv: Command-line arguments for XML generation
    
    Processes notebook and generates structured XML document.
    """

CLI Entry Point: mystnb-docutils-xml

Pseudo-XML Output

def cli_pseudoxml(argv: list[str] | None = None):
    """
    Generate pseudo-XML output from notebook using docutils.
    
    Parameters:
    - argv: Command-line arguments for pseudo-XML generation
    
    Processes notebook and generates pseudo-XML for debugging document structure.
    """

CLI Entry Point: mystnb-docutils-pseudoxml

Usage Examples

Project Quickstart

# Create a new MyST-NB project
mystnb-quickstart

# Interactive prompts will ask for:
# - Project name
# - Author name  
# - Initial configuration options
# - Example notebook creation

This creates a directory structure like:

my-project/
├── conf.py
├── index.md
├── notebooks/
│   └── example.ipynb
└── _build/

Notebook Conversion

# Convert MyST markdown to notebook
mystnb-to-jupyter my-notebook.md my-notebook.ipynb

# Convert with execution
mystnb-to-jupyter --execute my-notebook.md my-notebook.ipynb

# Convert multiple files
mystnb-to-jupyter notebooks/*.md --output-dir converted/

HTML Generation

# Generate HTML from notebook
mystnb-docutils-html notebook.ipynb output.html

# Generate with custom CSS
mystnb-docutils-html --stylesheet-path custom.css notebook.ipynb output.html

# Generate HTML5 with modern features
mystnb-docutils-html5 --math-output=mathjax notebook.ipynb output.html

LaTeX/PDF Generation

# Generate LaTeX
mystnb-docutils-latex notebook.ipynb output.tex

# Generate with custom document class
mystnb-docutils-latex --documentclass=article notebook.ipynb output.tex

# Process with pdflatex
mystnb-docutils-latex notebook.ipynb output.tex && pdflatex output.tex

XML and Debug Output

# Generate structured XML
mystnb-docutils-xml notebook.ipynb output.xml

# Generate pseudo-XML for debugging
mystnb-docutils-pseudoxml notebook.ipynb debug.xml

Batch Processing

# Process multiple notebooks to HTML
for notebook in notebooks/*.ipynb; do
    mystnb-docutils-html "$notebook" "html/$(basename "$notebook" .ipynb).html"
done

# Convert all markdown notebooks
find . -name "*.md" -type f -exec mystnb-to-jupyter {} {}.ipynb \;

Configuration Options

Most CLI commands accept standard docutils options:

# Common options across commands
--config-file CONFIG_FILE     # Use custom configuration
--output-encoding ENCODING    # Set output encoding
--language LANGUAGE           # Set document language
--title TITLE                 # Set document title
--stylesheet-path PATH        # Custom stylesheet
--template TEMPLATE           # Custom template

# MyST-NB specific options
--execution-mode MODE         # Set execution mode
--execution-timeout SECONDS   # Set execution timeout
--remove-code-source          # Hide source code
--remove-code-outputs         # Hide outputs

Integration with Build Systems

# In Makefile
html:
    find notebooks/ -name "*.ipynb" -exec mystnb-docutils-html {} docs/{}.html \;

# In GitHub Actions
- name: Generate documentation
  run: |
    for nb in notebooks/*.ipynb; do
      mystnb-docutils-html "$nb" "docs/$(basename "$nb" .ipynb).html"
    done

Error Handling

CLI commands provide detailed error reporting:

# Check syntax and execution
mystnb-to-jupyter --validate notebook.md

# Generate with error reporting
mystnb-docutils-html --traceback notebook.ipynb output.html

The CLI tools integrate with MyST-NB's configuration system and provide the same functionality as the Sphinx extension in standalone form, making them suitable for custom build pipelines and automated processing workflows.

Install with Tessl CLI

npx tessl i tessl/pypi-myst-nb

docs

cli.md

configuration.md

docutils.md

execution.md

glue.md

index.md

reading-processing.md

rendering.md

sphinx-extension.md

tile.json