UNPKG

@textlint/markdown-to-ast

Version:
38 lines • 1.7 kB
/** * CommonMark + GFM (table, strikethrough, task list, autolink literal, footnote) + frontmatter parser. * * Design: data-oriented * * - The parser does not create intermediate objects (tokens, events, mdast nodes). * - Nodes live in a flat pool that is "struct of arrays": each field is a typed array, and a node is an index. * Tree links(parent, first child, next sibling...) are indexes too. * - Variable length data is stored in side tables: `seg*`(lines of leaf blocks) and `side`(decoded strings). * - Most of string values are not copied while parsing. They are sliced from the source at the end. * - The pool is reused between `parse()` calls, so parsing allocates almost nothing but the result. * * Phases: * * 1. block phase: scan lines and build block nodes. Leaf blocks keep their lines as segments. * 2. inline phase: parse segments of Paragraph/Header/TableCell into inline nodes. * 3. emit phase: walk the pool once and create TxtAST nodes directly. */ import type { TxtDocumentNode } from "@textlint/ast-node-types"; /** * Options of `parse`. * Each option enables an extension that changes how a syntax is recognized. */ export type ParseOptions = { /** * Recognize emphasis, strong emphasis, and strikethrough next to CJK punctuation, * as the CommonMark CJK-friendly Amendments define. * https://github.com/tats-u/markdown-cjk-friendly/blob/main/specification.md * @default false */ cjkFriendlyEmphasis?: boolean; }; /** * Parse Markdown text to TxtAST. * `text` should not include BOM. */ export declare function parseMarkdown(text: string, options?: ParseOptions): TxtDocumentNode; //# sourceMappingURL=parser.d.ts.map