Skip to main content

MkDocs plugin that renders pages with Stripe's Markdoc instead of Python-Markdown

Project description

mkdocs-markdoc

An MkDocs plugin that completely replaces the default Python-Markdown renderer with Stripe's Markdoc. Every .md page in your docs site is parsed and rendered by Markdoc's HTML renderer — no React required.


How it works

MkDocs  ──on_page_markdown──▶  plugin.py  ──stdin──▶  markdoc_runner.js
                                                              │
                         HTML string  ◀──stdout──────────────┘

The Python plugin hooks into on_page_markdown, pipes the raw Markdown to a bundled Node.js script via subprocess, and returns the HTML string that MkDocs injects into the theme template.


Prerequisites

Requirement Minimum version
Python 3.9
MkDocs 1.5
Node.js 18 LTS
npm 8

Installation

1 — Install the Python package

# From the repo root (editable/development install)
pip install -e .

# Or once published to PyPI
pip install mkdocs-markdoc

2 — Install the Node.js Markdoc library

The @markdoc/markdoc npm package must be resolvable by Node.js when it runs the bundled markdoc_runner.js script. Install it in one of these locations (Node's module resolution will find it):

# Option A – global install (simplest for local dev / CI)
npm install -g @markdoc/markdoc

# Option B – local install in your docs project root
cd /path/to/your/docs-project
npm install @markdoc/markdoc

3 — Enable the plugin in mkdocs.yml

# mkdocs.yml
site_name: My Docs

plugins:
  - markdoc          # ← add this; remove or comment out the default 'search'
                     #   plugin only if you no longer need it

Note: MkDocs' built-in search plugin is independent of the Markdown renderer and can be kept alongside markdoc:

plugins:
  - search
  - markdoc

Configuration options

All options are optional.

plugins:
  - markdoc:
      # Path to the Node.js executable.
      # Default: "node"  (resolved via $PATH)
      node_path: /usr/local/bin/node

      # Path to a JS or JSON file that exports a Markdoc config object.
      # When omitted, Markdoc uses its built-in defaults (standard Markdown
      # nodes, no custom tags or functions).
      markdoc_config: docs/markdoc.config.js

      # Milliseconds to wait for the Node subprocess before raising an error.
      # Default: 30000  (30 seconds)
      timeout: 30000

Example markdoc.config.js

// docs/markdoc.config.js
const { nodes, Tag } = require("@markdoc/markdoc");

module.exports = {
  tags: {
    callout: {
      render: "div",
      attributes: {
        type: { type: String, default: "note" },
      },
    },
  },
  nodes: {
    // Override the default heading to add anchor IDs
    heading: {
      ...nodes.heading,
      render: "h1",
    },
  },
};

Running the docs locally

mkdocs serve

Caveats & trade-offs

  • Markdoc syntax differs from CommonMark. Markdoc is a superset of Markdown, but some edge-cases render differently. Review the Markdoc syntax reference when migrating an existing docs site.
  • Node.js subprocess overhead. Each page spawns (and immediately exits) one Node process. For large sites with hundreds of pages the build time will increase compared to the native Python-Markdown renderer. If this becomes a bottleneck, consider batching pages in a future version.
  • MkDocs extensions are bypassed. Because we skip Python-Markdown entirely, any markdown_extensions: listed in mkdocs.yml will have no effect. Equivalent behaviour must be implemented via Markdoc tags/nodes/functions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mkdocs_markdoc-0.1.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mkdocs_markdoc-0.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file mkdocs_markdoc-0.1.0.tar.gz.

File metadata

  • Download URL: mkdocs_markdoc-0.1.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mkdocs_markdoc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2a170879ca32b848fd60c5780baa258e3680bb69a48824afd46241c501c2b7c9
MD5 61915955e8ba0656110645b210f5c802
BLAKE2b-256 f188db649b5a2c7f044453f13d663f83e650f29010323ef980781418f6b8b9fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for mkdocs_markdoc-0.1.0.tar.gz:

Publisher: publish.yml on jwoglom/mkdocs-markdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mkdocs_markdoc-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mkdocs_markdoc-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mkdocs_markdoc-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9c3221652a36b5364916ee3ef1b860cfcd90a81a9c337f5083e04360b0a524da
MD5 a8ca85bd93214fb89f90c87d9104794a
BLAKE2b-256 e1c7165b82683c28f069e0eb3c7cae3d1b45e72f72131c01bc1fd994bc446980

See more details on using hashes here.

Provenance

The following attestation bundles were made for mkdocs_markdoc-0.1.0-py3-none-any.whl:

Publisher: publish.yml on jwoglom/mkdocs-markdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page