UNPKG

remark-mdat

Version:

A remark plugin implementing the Markdown Autophagic Template (MDAT) system.

63 lines (62 loc) 2.53 kB
import type { Html, Parent } from 'mdast'; import type { JsonValue, Simplify } from 'type-fest'; /** * Structured data about a parsed comment. * Note that this is a discriminated union based on the `type` field. */ type CommentMarker = Simplify<{ /** The complete original comment, e.g. `<!-- keyword -->` */ html: string; } & ({ /** Character used to delimit closing tags, e.g. the `/` in `<!-- /keyword -->` */ closingPrefix: string; /** The first complete word in the comment */ keyword: string; /** The unique keyword prefix */ keywordPrefix: string; /** Parsed JSON object of argument string that followed the keyword, empty object if nothing passed */ options: JsonValue; /** * `open`: A mdat-style opening comment tag, e.g. `<!-- keyword -->` \ * `close`: A mdat-style closing comment tag, e.g. `<!-- /keyword -->` */ type: 'close' | 'open'; } | { /** The original text inside the comment, e.g. `<!-- content -->` */ content: string; /** * `meta`: A mdat-style generated meta comment tag \ * `native`: A normal comment that does not match the the `keywordPrefix` (if specified) */ type: 'meta' | 'native'; })>; /** * Parsed comment with additional information about the Mdast Node and its Parent. */ export type CommentMarkerNode = Simplify<CommentMarker & { /** Original Mdast HTML Node where the comment was found. */ node: Html; /** Parent of original Mdast HTML Node where the comment was found. */ parent: Parent; }>; type CommentMarkerParseOptions = { /** Character to identify closing tags, e.g. the `/` in `<!-- /keyword -->` */ closingPrefix: string; /** Prefix to require on all mdat comments, e.g. `mm-` */ keywordPrefix: string; /** Means of identifying mdat generated meta comments, e.g. `+` */ metaCommentIdentifier: string; }; /** * Parse an Mdast HTML comment node into structured data. * @returns A discriminated union of CommentMarkerNode based on comment type, or * undefined if the node is not a comment. */ export declare function parseCommentNode(node: Html, parent: Parent, options: CommentMarkerParseOptions): CommentMarkerNode | undefined; /** * Parse any comment string into structured data. * @returns A discriminated union of CommentMarker based on comment type, or * undefined if the node is not a comment. */ export declare function parseComment(text: string, options: CommentMarkerParseOptions): CommentMarker | undefined; export {};