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.2.0.tar.gz (12.3 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.2.0-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mkdocs_markdoc-0.2.0.tar.gz
  • Upload date:
  • Size: 12.3 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.2.0.tar.gz
Algorithm Hash digest
SHA256 3bd107e007341968e5bd9bc70bd1428294dd849c6148378687803384696b52ff
MD5 f2baad4238ac3037be5b4838bedee7c5
BLAKE2b-256 ddc54cfd98aefc9f6b45cd44775b53339577e950ce861b6314f0abd56169a066

See more details on using hashes here.

Provenance

The following attestation bundles were made for mkdocs_markdoc-0.2.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: mkdocs_markdoc-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.9 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9787f6bd52709dc4ad6972945381fd46699316b672756b889a4d333a59866ef7
MD5 c955e05f0d251708301039e100afc3da
BLAKE2b-256 e88aa74c95a93a3038036889d316612fde05182d37dc57b591b0602ea79026c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for mkdocs_markdoc-0.2.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