Skip to content

PROJECT: myst-lint - MyST Markdown Linting Tool #268

Open

Description

@mmcky

Summary

A standalone MyST Markdown linting tool that validates syntax and provides deterministic error detection for MyST documents. This tool would support the translation sync pipeline and can be used independently for quality assurance across all QuantEcon lecture repositories.

Background

During evaluation of the action-translation-sync tool (v0.6.0), human reviewer @HumphreyYang identified markdown syntax errors in translator output that were not caught:

  • Missing space after #### in headings (e.g., ####Title instead of #### Title)
  • Incorrect code block delimiters
  • Math block delimiter mismatches

While we have added LLM-based syntax checking to prompts as a first line of defense, a deterministic linting tool would provide:

  1. 100% reliable detection (vs ~90% from LLM)
  2. No API costs
  3. Fast validation
  4. CI/pre-commit integration

Proposed Solution

Build myst-lint as a standalone tool that wraps markdownlint (5.3M monthly downloads, actively maintained) with MyST-specific extensions.

Architecture

┌─────────────────────────────────────────────────────────────┐
│                       myst-lint                              │
├─────────────────────────────────────────────────────────────┤
│                                                              │
│  ┌─────────────────┐   ┌─────────────────────────────────┐  │
│  │  markdownlint   │ + │  MyST Custom Rules (optional)   │  │
│  │  (core rules)   │   │  - directive validation         │  │
│  │  - MD018 (ATX)  │   │  - role validation              │  │
│  │  - MD031 (code) │   │  - math delimiter matching      │  │
│  │  - MD040 (lang) │   │  - code-cell validation         │  │
│  └─────────────────┘   └─────────────────────────────────┘  │
│                                                              │
├─────────────────────────────────────────────────────────────┤
│  CLI: myst-lint <file.md> [options]                         │
│  API: import { lintMyST } from "myst-lint"                  │
└─────────────────────────────────────────────────────────────┘

Integration Points

Source Repo ──► [myst-lint] ──► Valid input guaranteed
                    │
                    ▼
                Translator ──► [myst-lint] ──► Block sync if errors
                                    │
                                    ▼
Target Repo PR ◄── Sync ◄── Valid translated content
        │
        └──► [Evaluator] ──► Failsafe LLM check (advisory)
  1. Source validation: Lint English source before translation (assume valid input)
  2. Output validation: Lint translator output before sync (catch translator-introduced errors)
  3. CI integration: Pre-commit hooks for lecture repositories
  4. Evaluator failsafe: LLM-based check as backup (already implemented)

Core markdownlint Rules (Built-in)

These rules work out of the box with MyST:

Rule Description Catches
MD018 No space after hash on ATX heading ####Title → error
MD031 Fenced code blocks surrounded by blank lines Structure issues
MD040 Fenced code blocks should have language Missing language spec
MD047 Files should end with single newline Formatting

MyST Custom Rules (Phase 2)

Extend markdownlint with MyST-specific validation:

Rule Description
myst-directive-known Validate {directive-name} is recognized
myst-directive-options Check :option: value syntax
myst-role-syntax Validate {role}\target`` format
myst-math-delimiters Check $$ pairs are balanced
myst-code-cell-tags Validate code-cell tag syntax

Implementation Plan

Phase 1: Core Tool (MVP)

  • Wrap markdownlint with MyST-friendly config
  • Disable rules that conflict with MyST syntax
  • CLI and programmatic API
  • Integration with action-translation-sync

Phase 2: MyST Custom Rules

  • Implement directive/role validation
  • Math delimiter checking
  • Code-cell validation

Phase 3: CI Integration

  • Pre-commit hooks
  • GitHub Actions workflow
  • VS Code extension recommendations

Technical Details

Base Package: markdownlint v0.39.0

  • 5.3M monthly downloads
  • Actively maintained (last release Oct 2025)
  • Supports custom rules via micromark parser
  • Works with MyST out of the box (no false positives on directives)

Testing Performed:

$ echo "####NoSpaceHeading" | npx markdownlint-cli --stdin
stdin:1:1 MD018/no-missing-space-atx No space after hash on atx style heading

MyST directives ({note}, {code-cell}, etc.) are correctly ignored as valid code blocks.

Priority

MEDIUM - The LLM-based syntax checking provides good coverage now. This tool would provide deterministic guarantees and enable broader use across the organization.

Related

Activity

  1. mmcky commented on Jun 4, 2026

    @mmcky
    ContributorAuthor

    Related: #320 (PROJECT: action-code-style — deterministic black formatting of Python inside MyST {code-cell} and fenced markdown blocks).

    It shares this project's design philosophy exactly (deterministic, no API cost, fast, CI/pre-commit) but a different concern:

    Open question to settle jointly: one tool or two? black-formatting could be a separate sibling action, or a code-format pass/rule-set within myst-lint (one deterministic "MyST quality" tool with both a structure-lint and a code-format pass). Worth deciding before either is built.

  2. mmcky commented on Jun 11, 2026

    @mmcky
    ContributorAuthor

    Scope note from the style-guide consolidation program: we've decided myst-lint and the program's planned style checker (qestyle-linter) are siblings, not layers — two tools for two concerns.

    • myst-lint (this issue): is the document well-formed MyST? Malformed directives, unmatched math delimiters, missing lang tags — universal, nothing QuantEcon-specific.
    • qestyle-linter (the program): is it written in QuantEcon house style? (\top not ^T, aligned not align, etc.) — a style violation is still valid MyST.

    They coexist in CI and share at most a MyST parsing library (an implementation choice, not a product dependency). So MyST validity rules stay in scope here; QuantEcon style rules will live in the program's linter. Cross-reference: QuantEcon/project-style-guide decision D9.

  3. 1sgtpepper commented on Jun 15, 2026

    @1sgtpepper

    Hi QuantEcon team, I think SciEqLint may already cover a large part of the deterministic myst-lint layer being discussed here.

    The fit is mainly around the generated-translation workflow you’ve already described: translation output can look fine at review time but still contain structural MyST issues that only show up later in CI/Jupyter Book. SciEqLint is built for that gap: deterministic scientific Markdown/MyST checks, no API cost, GitHub annotations/SARIF, and a generated-MyST preset that can run immediately after translation output is produced.

    For this issue, #268, SciEqLint already covers many of the proposed myst-lint checks: malformed headings like ####Title, unclosed fenced blocks, unclosed math containers, missing fence info strings, malformed MyST directives/options/roles, code-cell metadata issues, heading hierarchy problems, and missing/ambiguous {ref} targets. This seems aligned with the scope note here: validate whether the document is well-formed MyST, while keeping QuantEcon house style separate.

    For QuantEcon/action-translation#4, it looks like the evaluator improvements were mostly handled, with deterministic myst-lint left as a future item. SciEqLint could provide that deterministic layer after translation output is generated, while the LLM evaluator stays focused on prose and translation quality.

    For QuantEcon/action-translation#65, SciEqLint handles MyST heading anchors like (label)= and reports missing or ambiguous generic {ref} targets. That should catch dropped-anchor cases like (jax_at_workaround)= being removed while a later {ref} still points to it, before Jupyter Book fails.

    A minimal trial would be:

    - name: Install SciEqLint
      run: python -m pip install scieqlint==1.1.0
    
    - name: Write generated MyST profile
      run: scieqlint init --preset generated-myst --path scieqlint.generated-myst.toml
    
    - name: Check generated scientific docs
      run: scieqlint check "lectures/**/*.md" --config scieqlint.generated-myst.toml --format github

    I don’t want to derail the existing direction, especially since the discussion already separates myst-lint, qestyle-linter, and action-code-style well. But if this is useful as a starting point or reusable validation layer, I’d be happy to adapt SciEqLint around QuantEcon fixtures, edge cases, or rule preferences.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions