import { Tag, Config, RenderableTreeNode } from '@markdoc/markdoc'; import { MdxJsxFlowElement } from 'mdast-util-mdx'; // ## Interfaces /** * Info associated with nodes by the ecosystem. * * This space is guaranteed to never be specified by unist or specifications * implementing unist. * But you can use it in utilities and plugins to store data. * * This type can be augmented to register custom data. * For example: * * ```ts * declare module 'unist' { * interface Data { * // `someNode.data.myId` is typed as `number | undefined` * myId?: number | undefined * } * } * ``` */ interface Data$1 {} /** * One place in a source file. */ interface Point { /** * Line in a source file (1-indexed integer). */ line: number; /** * Column in a source file (1-indexed integer). */ column: number; /** * Character in a source file (0-indexed integer). */ offset?: number | undefined; } /** * Position of a node in a source document. * * A position is a range between two points. */ interface Position { /** * Place of the first character of the parsed source region. */ start: Point; /** * Place of the first character after the parsed source region. */ end: Point; } /** * Abstract unist node. * * The syntactic unit in unist syntax trees are called nodes. * * This interface is supposed to be extended. * If you can use {@link Literal} or {@link Parent}, you should. * But for example in markdown, a `thematicBreak` (`***`), is neither literal * nor parent, but still a node. */ interface Node$1 { /** * Node type. */ type: string; /** * Info from the ecosystem. */ data?: Data$1 | undefined; /** * Position of a node in a source document. * * Nodes that are generated (not in the original source document) must not * have a position. */ position?: Position | undefined; } // ## Enumeration /** * How phrasing content is aligned * ({@link https://drafts.csswg.org/css-text/ | [CSSTEXT]}). * * * `'left'`: See the * {@link https://drafts.csswg.org/css-text/#valdef-text-align-left | left} * value of the `text-align` CSS property * * `'right'`: See the * {@link https://drafts.csswg.org/css-text/#valdef-text-align-right | right} * value of the `text-align` CSS property * * `'center'`: See the * {@link https://drafts.csswg.org/css-text/#valdef-text-align-center | center} * value of the `text-align` CSS property * * `null`: phrasing content is aligned as defined by the host environment * * Used in GFM tables. */ type AlignType = "center" | "left" | "right" | null; /** * Explicitness of a reference. * * `'shortcut'`: the reference is implicit, its identifier inferred from its * content * `'collapsed'`: the reference is explicit, its identifier inferred from its * content * `'full'`: the reference is explicit, its identifier explicitly set */ type ReferenceType = "shortcut" | "collapsed" | "full"; // ## Mixin /** * Node with a fallback. */ interface Alternative { /** * Equivalent content for environments that cannot represent the node as * intended. */ alt?: string | null | undefined; } /** * Internal relation from one node to another. * * Whether the value of `identifier` is expected to be a unique identifier or * not depends on the type of node including the Association. * An example of this is that they should be unique on {@link Definition}, * whereas multiple {@link LinkReference}s can be non-unique to be associated * with one definition. */ interface Association { /** * Relation of association. * * `identifier` is a source value: character escapes and character * references are not parsed. * * It can match another node. * * Its value must be normalized. * To normalize a value, collapse markdown whitespace (`[\t\n\r ]+`) to a space, * trim the optional initial and/or final space, and perform Unicode-aware * case-folding. */ identifier: string; /** * Relation of association, in parsed form. * * `label` is a `string` value: it works just like `title` on {@link Link} * or a `lang` on {@link Code}: character escapes and character references * are parsed. * * It can match another node. */ label?: string | null | undefined; } /** * Marker that is associated to another node. */ interface Reference extends Association { /** * Explicitness of the reference. */ referenceType: ReferenceType; } /** * Reference to resource. */ interface Resource { /** * URL to the referenced resource. */ url: string; /** * Advisory information for the resource, such as would be appropriate for * a tooltip. */ title?: string | null | undefined; } // ## Interfaces /** * Info associated with mdast nodes by the ecosystem. * * This space is guaranteed to never be specified by unist or mdast. * But you can use it in utilities and plugins to store data. * * This type can be augmented to register custom data. * For example: * * ```ts * declare module 'mdast' { * interface Data { * // `someNode.data.myId` is typed as `number | undefined` * myId?: number | undefined * } * } * ``` */ interface Data extends Data$1 {} // ## Content maps /** * Union of registered mdast nodes that can occur where block content is * expected. * * To register custom mdast nodes, add them to {@link BlockContentMap}. * They will be automatically added here. */ type BlockContent = BlockContentMap[keyof BlockContentMap]; /** * Registry of all mdast nodes that can occur where {@link BlockContent} is * expected. * * This interface can be augmented to register custom node types: * * ```ts * declare module 'mdast' { * interface BlockContentMap { * // Allow using MDX ESM nodes defined by `remark-mdx`. * mdxjsEsm: MdxjsEsm; * } * } * ``` * * For a union of all block content, see {@link RootContent}. */ interface BlockContentMap { blockquote: Blockquote; code: Code; heading: Heading; html: Html; list: List; paragraph: Paragraph; table: Table; thematicBreak: ThematicBreak; } /** * Union of registered mdast nodes that can occur where definition content is * expected. * * To register custom mdast nodes, add them to {@link DefinitionContentMap}. * They will be automatically added here. */ type DefinitionContent = DefinitionContentMap[keyof DefinitionContentMap]; /** * Registry of all mdast nodes that can occur where {@link DefinitionContent} * is expected. * * This interface can be augmented to register custom node types: * * ```ts * declare module 'mdast' { * interface DefinitionContentMap { * custom: Custom; * } * } * ``` * * For a union of all definition content, see {@link RootContent}. */ interface DefinitionContentMap { definition: Definition; footnoteDefinition: FootnoteDefinition; } /** * Union of registered mdast nodes that can occur where list content is * expected. * * To register custom mdast nodes, add them to {@link ListContentMap}. * They will be automatically added here. */ type ListContent = ListContentMap[keyof ListContentMap]; /** * Registry of all mdast nodes that can occur where {@link ListContent} * is expected. * * This interface can be augmented to register custom node types: * * ```ts * declare module 'mdast' { * interface ListContentMap { * custom: Custom; * } * } * ``` * * For a union of all list content, see {@link RootContent}. */ interface ListContentMap { listItem: ListItem; } /** * Union of registered mdast nodes that can occur where phrasing content is * expected. * * To register custom mdast nodes, add them to {@link PhrasingContentMap}. * They will be automatically added here. */ type PhrasingContent = PhrasingContentMap[keyof PhrasingContentMap]; /** * Registry of all mdast nodes that can occur where {@link PhrasingContent} * is expected. * * This interface can be augmented to register custom node types: * * ```ts * declare module 'mdast' { * interface PhrasingContentMap { * // Allow using MDX JSX (text) nodes defined by `remark-mdx`. * mdxJsxTextElement: MDXJSXTextElement; * } * } * ``` * * For a union of all phrasing content, see {@link RootContent}. */ interface PhrasingContentMap { break: Break; delete: Delete; emphasis: Emphasis; footnoteReference: FootnoteReference; html: Html; image: Image; imageReference: ImageReference; inlineCode: InlineCode; link: Link; linkReference: LinkReference; strong: Strong; text: Text; } /** * Union of registered mdast nodes that can occur in {@link Root}. * * To register custom mdast nodes, add them to {@link RootContentMap}. * They will be automatically added here. */ type RootContent = RootContentMap[keyof RootContentMap]; /** * Registry of all mdast nodes that can occur as children of {@link Root}. * * > **Note**: {@link Root} does not need to be an entire document. * > it can also be a fragment. * * This interface can be augmented to register custom node types: * * ```ts * declare module 'mdast' { * interface RootContentMap { * // Allow using toml nodes defined by `remark-frontmatter`. * toml: TOML; * } * } * ``` * * For a union of all {@link Root} children, see {@link RootContent}. */ interface RootContentMap { blockquote: Blockquote; break: Break; code: Code; definition: Definition; delete: Delete; emphasis: Emphasis; footnoteDefinition: FootnoteDefinition; footnoteReference: FootnoteReference; heading: Heading; html: Html; image: Image; imageReference: ImageReference; inlineCode: InlineCode; link: Link; linkReference: LinkReference; list: List; listItem: ListItem; paragraph: Paragraph; strong: Strong; table: Table; tableCell: TableCell; tableRow: TableRow; text: Text; thematicBreak: ThematicBreak; yaml: Yaml; } /** * Union of registered mdast nodes that can occur where row content is * expected. * * To register custom mdast nodes, add them to {@link RowContentMap}. * They will be automatically added here. */ type RowContent = RowContentMap[keyof RowContentMap]; /** * Registry of all mdast nodes that can occur where {@link RowContent} * is expected. * * This interface can be augmented to register custom node types: * * ```ts * declare module 'mdast' { * interface RowContentMap { * custom: Custom; * } * } * ``` * * For a union of all row content, see {@link RootContent}. */ interface RowContentMap { tableCell: TableCell; } /** * Union of registered mdast nodes that can occur where table content is * expected. * * To register custom mdast nodes, add them to {@link TableContentMap}. * They will be automatically added here. */ type TableContent = TableContentMap[keyof TableContentMap]; /** * Registry of all mdast nodes that can occur where {@link TableContent} * is expected. * * This interface can be augmented to register custom node types: * * ```ts * declare module 'mdast' { * interface TableContentMap { * custom: Custom; * } * } * ``` * * For a union of all table content, see {@link RootContent}. */ interface TableContentMap { tableRow: TableRow; } // ## Abstract nodes /** * Abstract mdast node that contains the smallest possible value. * * This interface is supposed to be extended if you make custom mdast nodes. * * For a union of all registered mdast literals, see {@link Literals}. */ interface Literal extends Node { /** * Plain-text value. */ value: string; } /** * Abstract mdast node. * * This interface is supposed to be extended. * If you can use {@link Literal} or {@link Parent}, you should. * But for example in markdown, a thematic break (`***`) is neither literal nor * parent, but still a node. * * To register custom mdast nodes, add them to {@link RootContentMap} and other * places where relevant (such as {@link ElementContentMap}). * * For a union of all registered mdast nodes, see {@link Nodes}. */ interface Node extends Node$1 { /** * Info from the ecosystem. */ data?: Data | undefined; } /** * Abstract mdast node that contains other mdast nodes (*children*). * * This interface is supposed to be extended if you make custom mdast nodes. * * For a union of all registered mdast parents, see {@link Parents}. */ interface Parent extends Node { /** * List of children. */ children: RootContent[]; } // ## Concrete nodes /** * Markdown block quote. */ interface Blockquote extends Parent { /** * Node type of mdast block quote. */ type: "blockquote"; /** * Children of block quote. */ children: Array; /** * Data associated with the mdast block quote. */ data?: BlockquoteData | undefined; } /** * Info associated with mdast block quote nodes by the ecosystem. */ interface BlockquoteData extends Data {} /** * Markdown break. */ interface Break extends Node { /** * Node type of mdast break. */ type: "break"; /** * Data associated with the mdast break. */ data?: BreakData | undefined; } /** * Info associated with mdast break nodes by the ecosystem. */ interface BreakData extends Data {} /** * Markdown code (flow) (block). */ interface Code extends Literal { /** * Node type of mdast code (flow). */ type: "code"; /** * Language of computer code being marked up. */ lang?: string | null | undefined; /** * Custom information relating to the node. * * If the lang field is present, a meta field can be present. */ meta?: string | null | undefined; /** * Data associated with the mdast code (flow). */ data?: CodeData | undefined; } /** * Info associated with mdast code (flow) (block) nodes by the ecosystem. */ interface CodeData extends Data {} /** * Markdown definition. */ interface Definition extends Node, Association, Resource { /** * Node type of mdast definition. */ type: "definition"; /** * Data associated with the mdast definition. */ data?: DefinitionData | undefined; } /** * Info associated with mdast definition nodes by the ecosystem. */ interface DefinitionData extends Data {} /** * Markdown GFM delete (strikethrough). */ interface Delete extends Parent { /** * Node type of mdast GFM delete. */ type: "delete"; /** * Children of GFM delete. */ children: PhrasingContent[]; /** * Data associated with the mdast GFM delete. */ data?: DeleteData | undefined; } /** * Info associated with mdast GFM delete nodes by the ecosystem. */ interface DeleteData extends Data {} /** * Markdown emphasis. */ interface Emphasis extends Parent { /** * Node type of mdast emphasis. */ type: "emphasis"; /** * Children of emphasis. */ children: PhrasingContent[]; /** * Data associated with the mdast emphasis. */ data?: EmphasisData | undefined; } /** * Info associated with mdast emphasis nodes by the ecosystem. */ interface EmphasisData extends Data {} /** * Markdown GFM footnote definition. */ interface FootnoteDefinition extends Parent, Association { /** * Node type of mdast GFM footnote definition. */ type: "footnoteDefinition"; /** * Children of GFM footnote definition. */ children: Array; /** * Data associated with the mdast GFM footnote definition. */ data?: FootnoteDefinitionData | undefined; } /** * Info associated with mdast GFM footnote definition nodes by the ecosystem. */ interface FootnoteDefinitionData extends Data {} /** * Markdown GFM footnote reference. */ interface FootnoteReference extends Association, Node { /** * Node type of mdast GFM footnote reference. */ type: "footnoteReference"; /** * Data associated with the mdast GFM footnote reference. */ data?: FootnoteReferenceData | undefined; } /** * Info associated with mdast GFM footnote reference nodes by the ecosystem. */ interface FootnoteReferenceData extends Data {} /** * Markdown heading. */ interface Heading extends Parent { /** * Node type of mdast heading. */ type: "heading"; /** * Heading rank. * * A value of `1` is said to be the highest rank and `6` the lowest. */ depth: 1 | 2 | 3 | 4 | 5 | 6; /** * Children of heading. */ children: PhrasingContent[]; /** * Data associated with the mdast heading. */ data?: HeadingData | undefined; } /** * Info associated with mdast heading nodes by the ecosystem. */ interface HeadingData extends Data {} /** * Markdown HTML. */ interface Html extends Literal { /** * Node type of mdast HTML. */ type: "html"; /** * Data associated with the mdast HTML. */ data?: HtmlData | undefined; } /** * Info associated with mdast HTML nodes by the ecosystem. */ interface HtmlData extends Data {} /** * Markdown image. */ interface Image extends Alternative, Node, Resource { /** * Node type of mdast image. */ type: "image"; /** * Data associated with the mdast image. */ data?: ImageData | undefined; } /** * Info associated with mdast image nodes by the ecosystem. */ interface ImageData extends Data {} /** * Markdown image reference. */ interface ImageReference extends Alternative, Node, Reference { /** * Node type of mdast image reference. */ type: "imageReference"; /** * Data associated with the mdast image reference. */ data?: ImageReferenceData | undefined; } /** * Info associated with mdast image reference nodes by the ecosystem. */ interface ImageReferenceData extends Data {} /** * Markdown code (text) (inline). */ interface InlineCode extends Literal { /** * Node type of mdast code (text). */ type: "inlineCode"; /** * Data associated with the mdast code (text). */ data?: InlineCodeData | undefined; } /** * Info associated with mdast code (text) (inline) nodes by the ecosystem. */ interface InlineCodeData extends Data {} /** * Markdown link. */ interface Link extends Parent, Resource { /** * Node type of mdast link. */ type: "link"; /** * Children of link. */ children: PhrasingContent[]; /** * Data associated with the mdast link. */ data?: LinkData | undefined; } /** * Info associated with mdast link nodes by the ecosystem. */ interface LinkData extends Data {} /** * Markdown link reference. */ interface LinkReference extends Parent, Reference { /** * Node type of mdast link reference. */ type: "linkReference"; /** * Children of link reference. */ children: PhrasingContent[]; /** * Data associated with the mdast link reference. */ data?: LinkReferenceData | undefined; } /** * Info associated with mdast link reference nodes by the ecosystem. */ interface LinkReferenceData extends Data {} /** * Markdown list. */ interface List extends Parent { /** * Node type of mdast list. */ type: "list"; /** * Whether the items have been intentionally ordered (when `true`), or that * the order of items is not important (when `false` or not present). */ ordered?: boolean | null | undefined; /** * The starting number of the list, when the `ordered` field is `true`. */ start?: number | null | undefined; /** * Whether one or more of the children are separated with a blank line from * its siblings (when `true`), or not (when `false` or not present). */ spread?: boolean | null | undefined; /** * Children of list. */ children: ListContent[]; /** * Data associated with the mdast list. */ data?: ListData | undefined; } /** * Info associated with mdast list nodes by the ecosystem. */ interface ListData extends Data {} /** * Markdown list item. */ interface ListItem extends Parent { /** * Node type of mdast list item. */ type: "listItem"; /** * Whether the item is a tasklist item (when `boolean`). * * When `true`, the item is complete. * When `false`, the item is incomplete. */ checked?: boolean | null | undefined; /** * Whether one or more of the children are separated with a blank line from * its siblings (when `true`), or not (when `false` or not present). */ spread?: boolean | null | undefined; /** * Children of list item. */ children: Array; /** * Data associated with the mdast list item. */ data?: ListItemData | undefined; } /** * Info associated with mdast list item nodes by the ecosystem. */ interface ListItemData extends Data {} /** * Markdown paragraph. */ interface Paragraph extends Parent { /** * Node type of mdast paragraph. */ type: "paragraph"; /** * Children of paragraph. */ children: PhrasingContent[]; /** * Data associated with the mdast paragraph. */ data?: ParagraphData | undefined; } /** * Info associated with mdast paragraph nodes by the ecosystem. */ interface ParagraphData extends Data {} /** * Document fragment or a whole document. * * Should be used as the root of a tree and must not be used as a child. */ interface Root extends Parent { /** * Node type of mdast root. */ type: "root"; /** * Data associated with the mdast root. */ data?: RootData | undefined; } /** * Info associated with mdast root nodes by the ecosystem. */ interface RootData extends Data {} /** * Markdown strong. */ interface Strong extends Parent { /** * Node type of mdast strong. */ type: "strong"; /** * Children of strong. */ children: PhrasingContent[]; /** * Data associated with the mdast strong. */ data?: StrongData | undefined; } /** * Info associated with mdast strong nodes by the ecosystem. */ interface StrongData extends Data {} /** * Markdown GFM table. */ interface Table extends Parent { /** * Node type of mdast GFM table. */ type: "table"; /** * How cells in columns are aligned. */ align?: AlignType[] | null | undefined; /** * Children of GFM table. */ children: TableContent[]; /** * Data associated with the mdast GFM table. */ data?: TableData | undefined; } /** * Info associated with mdast GFM table nodes by the ecosystem. */ interface TableData extends Data {} /** * Markdown GFM table row. */ interface TableRow extends Parent { /** * Node type of mdast GFM table row. */ type: "tableRow"; /** * Children of GFM table row. */ children: RowContent[]; /** * Data associated with the mdast GFM table row. */ data?: TableRowData | undefined; } /** * Info associated with mdast GFM table row nodes by the ecosystem. */ interface TableRowData extends Data {} /** * Markdown GFM table cell. */ interface TableCell extends Parent { /** * Node type of mdast GFM table cell. */ type: "tableCell"; /** * Children of GFM table cell. */ children: PhrasingContent[]; /** * Data associated with the mdast GFM table cell. */ data?: TableCellData | undefined; } /** * Info associated with mdast GFM table cell nodes by the ecosystem. */ interface TableCellData extends Data {} /** * Markdown text. */ interface Text extends Literal { /** * Node type of mdast text. */ type: "text"; /** * Data associated with the mdast text. */ data?: TextData | undefined; } /** * Info associated with mdast text nodes by the ecosystem. */ interface TextData extends Data {} /** * Markdown thematic break (horizontal rule). */ interface ThematicBreak extends Node { /** * Node type of mdast thematic break. */ type: "thematicBreak"; /** * Data associated with the mdast thematic break. */ data?: ThematicBreakData | undefined; } /** * Info associated with mdast thematic break nodes by the ecosystem. */ interface ThematicBreakData extends Data {} /** * Markdown YAML. */ interface Yaml extends Literal { /** * Node type of mdast YAML. */ type: "yaml"; /** * Data associated with the mdast YAML. */ data?: YamlData | undefined; } /** * Info associated with mdast YAML nodes by the ecosystem. */ interface YamlData extends Data {} type TagReplacer = Record RootContent>; /** * Converts Markdoc content to an AST (Abstract Syntax Tree) and rendered MDX * * @param content - The Markdoc content string to convert * @param markdocConfig - The Markdoc configuration object * @param replacer - An optional object containing custom tag replacers * @returns An object containing: * - parsed: The AST root node containing the parsed content * - rendered: The rendered MDX string, or null if parsing failed */ declare function convertContent({ content, markdocConfig, replacer, }: { content: string; markdocConfig: Config; replacer?: Record RootContent>; }): { parsed: Root; rendered: string | null; }; declare function generateCodeblock(node: Tag): Code; declare function generateInlineCode({ children }: { children: RenderableTreeNode[]; }): InlineCode; declare function generateOrderedList(node: Tag, tagReplacer: TagReplacer): List; declare function generateUnorderedList(node: Tag, tagReplacer: TagReplacer): List; declare function generateListItem(node: Tag, tagReplacer: TagReplacer): ListItem; declare function generateHeading(node: Tag, tagReplacer: TagReplacer): Heading; declare function generateParagraph(node: Tag, tagReplacer: TagReplacer): Paragraph; declare function generateBlockquote(node: Tag, tagReplacer: TagReplacer): Blockquote; declare function generateLink(node: Tag, tagReplacer: TagReplacer): Link; declare function generateImage(node: Tag): Image; declare function generateStrong(node: Tag, tagReplacer: TagReplacer): Strong; declare function generateEmphasis(node: Tag, tagReplacer: TagReplacer): Emphasis; declare function generateDelete(node: Tag, tagReplacer: TagReplacer): Delete; declare function generateTabs(node: Tag, tagReplacer: TagReplacer): RootContent; declare function generateTab(node: Tag, tagReplacer: TagReplacer): MdxJsxFlowElement; declare function generateTable(node: Tag, tagReplacer: TagReplacer): MdxJsxFlowElement; declare function generateTableHeader(node: Tag, tagReplacer: TagReplacer): MdxJsxFlowElement; declare function generateTableBody(node: Tag, tagReplacer: TagReplacer): MdxJsxFlowElement; declare function generateTableRow(node: Tag, tagReplacer: TagReplacer): MdxJsxFlowElement; declare function generateTableHead(node: Tag, tagReplacer: TagReplacer): MdxJsxFlowElement; declare function generateTableCell(node: Tag, tagReplacer: TagReplacer): MdxJsxFlowElement; declare function generateAccordion(node: Tag, tagReplacer: TagReplacer): RootContent; declare function generateAccordionItem(node: Tag, tagReplacer: TagReplacer): MdxJsxFlowElement; declare function generateCallout(node: Tag, tagReplacer: TagReplacer): RootContent; export { type TagReplacer, convertContent, generateAccordion, generateAccordionItem, generateBlockquote, generateCallout, generateCodeblock, generateDelete, generateEmphasis, generateHeading, generateImage, generateInlineCode, generateLink, generateListItem, generateOrderedList, generateParagraph, generateStrong, generateTab, generateTable, generateTableBody, generateTableCell, generateTableHead, generateTableHeader, generateTableRow, generateTabs, generateUnorderedList };