Automate Markdown Render Verification and PDF Export From the CLI

Install mdview-cli to open a Markdown file from your terminal, check whether its Mermaid diagrams render, share a saved document, or export a PDF. The command is mdv.

uv tool install mdview-cli
mdv open README.md

mdv open renders in your browser without uploading the file or asking for an account. For a temporary link you can send to someone, use mdv preview README.md instead. That command uploads the file and creates a share link, so use it only for content you intend to share. If you want the formatted text to stay inside your terminal, use a terminal Markdown reader.

Task Command What happens
Check the current file for broken diagrams mdv verify docs/architecture.md Checks a temporary private copy on mdview.io without editing your file.
Keep one saved document updated mdv sync docs/architecture.md --no-fix Updates the saved copy and checks rendering without automatically rewriting diagrams.
Give reviewers a stable link mdv share docs/architecture.md Publishes the synced document. Later syncs update that share.
Export the checked revision mdv pdf docs/architecture.md --no-sync Exports the last synced revision without uploading later local edits.

These four commands require a CLI token. For the full list of commands and options, see the package reference.

[Diagram]

When This Workflow Is Useful

CLI verification is useful whenever Markdown is generated faster than a person can inspect every revision.

Common examples include:

The important distinction is that mdview.io becomes a verification target, not just a place to paste the finished result. Your generator writes Markdown; mdview.io checks what the rendered document will actually do.

Set Up a Repeatable Verification Workflow

You do not need to assemble the automation yourself. The quickest way to adopt it is:

  1. Sign in to mdview.io.
  2. Open the CLI Usage section of the Dashboard and generate a CLI token.
  3. Install the CLI and save the token when prompted:
uv tool install mdview-cli
mdv keys set
  1. Run the same command after every agent edit:
mdv sync docs/architecture.md --no-fix

The first sync creates a private saved document. Later syncs update it. The command checks every Mermaid diagram in the production PDF renderer. Exit code 0 means the check passed, and 1 means a diagram failed to render. Treat any nonzero exit as a failed check. Keep --no-fix if you want to review source changes yourself. Plain mdv sync can repair diagrams and write the fixes back into your file.

Once the sync passes, choose the output you need:

# Optional: publish a stable link for reviewers
mdv share docs/architecture.md

# Export the last synced revision
mdv pdf docs/architecture.md --no-sync
  1. Copy the URL of this article and send it to your coding agent with the prompt below.
Adopt the mdview.io CLI iteration workflow described in this article:
https://mdview.io/s/automate-markdown-render-verification-cli

After every edit to the generated Markdown, run:
mdv sync PATH_TO_DOCUMENT --no-fix

Treat a nonzero exit as a failed iteration. Read the reported diagram errors,
correct the source, and run the same command again. Use `mdv fix PATH_TO_DOCUMENT`
only when I explicitly approve an automated rewrite. Export the PDF only after
`mdv sync` passes. In CI, provide MDVIEW_TOKEN as a secret; never commit it.

The CLI remembers the document ID outside your repository, so the agent only needs the file path. In CI, use mdv verify PATH_TO_DOCUMENT for a rendering gate that does not modify the source or leave a saved document. Supply MDVIEW_TOKEN through your CI system's secret store. Verification sends the file to mdview.io for rendering, so use it only when that is acceptable for the document.

API Reference for Custom Integrations

The mdv commands above are the recommended workflow. The remaining curl examples are the low-level API reference for custom integrations. In CI, store the CLI token in an environment variable instead of placing it directly in a script:

export MDVIEW_TOKEN="mdv1_..."

The examples also use curl and jq.

Step 1: Create the Document Once

Create a saved document and retain its ID:

MDVIEW_DOC_ID=$(
  curl -fsS -X POST https://mdview.io/api/documents \
    -H "Authorization: Bearer $MDVIEW_TOKEN" \
    -H "Content-Type: application/json" \
    --data '{"title":"Architecture","content":"# Architecture"}' \
  | jq -r '.id'
)

echo "$MDVIEW_DOC_ID"

Do this once. Subsequent revisions should update the same document instead of creating a new one. That preserves ownership, history, and any published review URL.

If teammates need a stable browser view, publish it once:

curl -fsS -X POST \
  "https://mdview.io/api/documents/$MDVIEW_DOC_ID/share" \
  -H "Authorization: Bearer $MDVIEW_TOKEN" \
  -H "Content-Type: application/json" \
  --data '{}' | jq

The returned shortId identifies the stable /s/... URL. Updating the saved document updates what reviewers see at that same address.

Step 2: Upload Each New Revision

Suppose an agent writes its latest output to docs/architecture.md. Upload that exact file with one command:

jq -Rs '{content: .}' docs/architecture.md \
  | curl -fsS -X PUT \
      "https://mdview.io/api/documents/$MDVIEW_DOC_ID" \
      -H "Authorization: Bearer $MDVIEW_TOKEN" \
      -H "Content-Type: application/json" \
      --data @- \
  | jq

The jq -Rs step safely converts the whole file into a JSON string, including newlines and quotes.

Step 3: Verify the Rendered Result

Run the full verification endpoint after an update:

curl -fsS \
  "https://mdview.io/api/documents/$MDVIEW_DOC_ID/verify" \
  -H "Authorization: Bearer $MDVIEW_TOKEN" \
  | tee verify.json \
  | jq

The verification runs in the same Chromium-based export environment used to create PDFs. A response looks like this:

{
  "renderable": false,
  "diagrams": { "total": 9, "failing": 1 },
  "tables": { "total": 3 },
  "failures": [
    {
      "index": 3,
      "fixable": true,
      "error": "Parse error on line 2",
      "snippet": "flowchart TD..."
    }
  ]
}

For a CI-friendly pass/fail result, let jq set the exit code:

curl -fsS \
  "https://mdview.io/api/documents/$MDVIEW_DOC_ID/verify" \
  -H "Authorization: Bearer $MDVIEW_TOKEN" \
  | jq -e '.renderable'

The command exits non-zero when the document contains a failing Mermaid diagram.

Step 4: Repair Broken Mermaid Diagrams

You can give the verification result back to the generating agent and ask it to revise the source. mdview.io can also run its render-validated Quick Fix pipeline over the failing diagrams:

curl -fsS -X POST \
  "https://mdview.io/api/documents/$MDVIEW_DOC_ID/fix/diagrams?apply=1" \
  -H "Authorization: Bearer $MDVIEW_TOKEN" \
  | jq

Without apply=1, the operation is a dry run and returns proposed repaired Markdown without changing the saved document.

Large repairs can reach the request deadline before every diagram has been processed. Repeat the request while the response contains "deadline_hit": true. Stop when renderable becomes true, or when deadline_hit is false and failures remain. The latter means at least one problem needs human or agent attention.

After applying a fix, fetch or otherwise reconcile the repaired source before allowing another generator update. Otherwise the next upload of the old local file will overwrite the server-side repair.

Step 5: Export the Verified PDF

Export only after verification succeeds:

curl -fsS \
  "https://mdview.io/api/documents/$MDVIEW_DOC_ID/export/pdf" \
  -H "Authorization: Bearer $MDVIEW_TOKEN" \
  -o architecture.pdf

The result is a vector PDF with selectable text. Free-plan PDF limits and branding still apply; Pro exports are clean and uncapped.

Only one Chromium export job runs at a time. If the API returns 429 export_busy, wait briefly and retry.

A Complete Verification Script

This minimal script updates a saved document, verifies it, and exports a PDF only when it passes:

#!/usr/bin/env bash
set -euo pipefail

: "${MDVIEW_TOKEN:?Set MDVIEW_TOKEN}"
: "${MDVIEW_DOC_ID:?Set MDVIEW_DOC_ID}"

MARKDOWN_FILE="${1:-docs/architecture.md}"
PDF_FILE="${2:-architecture.pdf}"
BASE="https://mdview.io/api/documents/$MDVIEW_DOC_ID"
AUTH="Authorization: Bearer $MDVIEW_TOKEN"

jq -Rs '{content: .}' "$MARKDOWN_FILE" \
  | curl -fsS -X PUT "$BASE" \
      -H "$AUTH" \
      -H "Content-Type: application/json" \
      --data @- > /dev/null

curl -fsS "$BASE/verify" -H "$AUTH" \
  | tee verify.json \
  | jq -e '.renderable' > /dev/null

curl -fsS "$BASE/export/pdf" -H "$AUTH" -o "$PDF_FILE"

echo "Verified and exported $PDF_FILE"

Run it like this:

./verify-markdown.sh docs/architecture.md build/architecture.pdf

Use the Cached Status for Polling

Full verification launches the export renderer. When a workflow only needs to ask whether the current content was already checked, use the cached status endpoint:

curl -fsS \
  "https://mdview.io/api/documents/$MDVIEW_DOC_ID/verify/status" \
  -H "Authorization: Bearer $MDVIEW_TOKEN" \
  | jq

"known": true means the status applies to the current document content. After an update, the endpoint returns "known": false until a full verification, repair, or PDF render refreshes the cache.

What “Renderable” Currently Means

The verdict is deliberately precise: renderable means every Mermaid diagram rendered in the production PDF environment. The response also reports table counts.

It is not yet a general visual-quality score. It does not promise that every page break is elegant, that a wide table is aesthetically ideal, or that headings never become orphans. Those checks still benefit from a human review of the exported PDF.

That boundary makes the result useful in automation. A pipeline gets a deterministic answer about silent diagram failures without pretending that all document design can be reduced to one boolean.

A Better Loop for AI-Generated Documentation

The traditional workflow treats rendering as the last manual step. The automated workflow moves it into the generation loop:

  1. Generate or revise Markdown.
  2. Update the same mdview.io document.
  3. Verify it in the real export renderer.
  4. Feed failures back to the agent or run Quick Fix.
  5. Repeat until renderable is true.
  6. Export the PDF and publish the stable review link.

That turns mdview.io into a verification surface for agents and CI—not merely a viewer opened after the work is supposedly finished.

Create an API token in your Dashboard, or see the complete endpoint reference and CI examples on the Agents page.