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.
28 lines (27 loc) • 1.01 kB
TypeScript
import type { AST } from "./nodes.js";
import type { Options } from "./options.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
*/
export declare function parseMarkdown(markdown: string, options?: Options): AST;