comrak
Version:
Comrak is an efficient, extensible, and highly configurable Markdown parser and renderer, written in Rust and compiled to WebAssembly. Portable and agnostic, it works seamlessly in any WebAssembly-friendly JS runtime.
43 lines (42 loc) • 1.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseMarkdown = parseMarkdown;
/**
* This module exposes the {@linkcode parseMarkdown} function for parsing
* Markdown from text into an abstract syntax tree ({@linkcode AST}), which can
* be further processed or manipulated and then rendered back into various
* formats such as HTML, CommonMark, or CommonMark XML using the respective
* rendering functions.
*
* @module parse
*/
const _wasm_js_1 = require("./_wasm.js");
const _internal_js_1 = require("./_internal.js");
/**
* Parses a given Markdown document into an abstract syntax tree (AST), which
* can be further processed or passed to one of the formatter functions:
*
* - {@linkcode renderHTML} - render an AST to an HTML document
* - {@linkcode renderXML} - render an AST to a CommonMark XML document
* - {@linkcode renderCommonMark} - render an AST back into CommonMark Markdown
*
* @param markdown The Markdown string to be parsed.
* @param [options] Options to customize the parsing.
* @returns The generated AST.
* @example
* ```ts
* import { parseMarkdown, renderHTML } from "@nick/comrak";
*
* const markdown = "# Hello, **world**!\n\nThis is a sample __document__.";
*
* const ast = parseMarkdown(markdown, { extension: { underline: true } });
* const html = renderHTML(ast);
*
* console.log(html);
* ```
* @category Parsing
*/
function parseMarkdown(markdown, options) {
const [opts, , , ...fns] = (0, _internal_js_1.collectOptions)(options);
return (0, _wasm_js_1.parse_document)(markdown, opts, ...fns);
}