UNPKG

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.

60 lines (59 loc) 2.1 kB
import type { AST } from "./nodes.js"; import type { Options } from "./options.js"; /** * Parses a Markdown document into an {@linkcode AST}, rendering it back into * CommonMark format in a single step. * * This is equivalent to calling {@linkcode renderCommonMark} on the result of * the {@linkcode parseMarkdown} function. * * @param md The Markdown string to be converted. * @param [options] Options to customize the conversion. * @returns The generated CommonMark string. * @example * ```ts * import { markdownToCommonMark } from "@nick/comrak"; * import assert from "node:assert"; * * const cm = markdownToCommonMark("Hello, **_Nick_**!"); * assert.strictEqual(cm, "Hello, ***Nick***\\!\n"); * ``` * @category Conversion */ export declare function markdownToCommonMark(md: string, options?: Options): string; /** * Formats an abstract syntax tree (AST), produced by parsing a Markdown * document with the {@linkcode parseMarkdown} function, into CommonMark text. * * **Note**: This is a low-level function that is primarily intended for * advanced use cases where direct manipulation of the AST is required. If you * simply want to convert a Markdown document into CommonMark, you should * consider the single-step {@linkcode markdownToCommonMark} functioninstead. * * @param ast The AST to be formatted. * @param [options] Options to customize the formatting. * @returns The generated CommonMark string. * @see {@linkcode parseMarkdown} to parse Markdown into an {@linkcode AST}. * @example * ```ts * import { * renderCommonMark, * parseMarkdown, * type Options, * } from "@nick/comrak"; * import assert from "node:assert"; * * const options = { * extension: { * alerts: true, * footnotes: true, * }, * } satisfies Options; * * const ast = parseMarkdown("# Hello, world!\n\nHow are you?", options); * const cm = renderCommonMark(ast, options); * assert.strictEqual(cm, "# Hello, world\\!\n\nHow are you?\n"); * ``` * @category Rendering */ export declare function renderCommonMark(ast: AST, options?: Options): string;