Documentation 1.11.6

MDParser

This page covers MDParser, the Markdown-to-HTML class that needs no editor or viewer UI.

Construction

const parser = new MDParser({ standard: false, text: "# Default" });
Option Type Default Description
standard boolean true When true, only standard syntax is handled; see Standard Mode
text string "" Default text used when parse() gets no argument

parse()

parser.parse(text?) // => string
Input Behavior
text is a string Converts that string
text is undefined or null Converts the constructor's text
Empty string Returns "<br>" (the default text is not used)

The return value is an HTML string that may carry leading or trailing newlines. Every call runs the full pipeline; nothing is cached.

Differences from the Viewer

Item MDParser MDViewer
Default mode Standard Extended (fixed)
Hashtags Not converted Per hashtag.path
Code highlighting, Mermaid Only emits the prettyprint class and .mermaid containers; call PR.prettyPrint() / mermaid.run() yourself Run automatically after render
Copy button Emits <button class="copy"> with no handler Bound to the clipboard automatically

Environment Requirements

MDParser creates no DOM container, but still needs a browser environment:

To use it in Node.js, pair it with a DOM implementation such as jsdom and provide window.matchMedia first.

Example

const parser = new MDParser({ standard: false });
const html = parser.parse("```js\nconst a = 1;\n```");
document.querySelector("#out").innerHTML = html;
PR.prettyPrint();

Read Security before writing the output into innerHTML.

中文