//#region src/types.d.ts type MarkdownProcessorMode = 'static' | 'streaming'; type PreprocessStepName = 'code' | 'html' | 'footnote' | 'strong' | 'emphasis' | 'delete' | 'taskList' | 'link' | 'table' | 'inlineMath' | 'math'; type PreprocessStep = (content: string, options?: PreprocessContext) => string; type PreprocessSteps = Partial>; interface MarkdownProcessorOptions { normalize?: (content: string) => string; preprocess?: (content: string, options?: PreprocessContext) => string; preprocessSteps?: PreprocessSteps; parseMarkdownIntoBlocks?: (content: string) => string[]; } interface PreprocessContext { singleDollarTextMath?: boolean; } interface MarkdownProcessorRunOptions { mode?: MarkdownProcessorMode; preprocessContext?: PreprocessContext; } interface MarkdownProcessorResult { normalizedContent: string; blocks: string[]; contents: string[]; } //#endregion //#region src/preprocess/code.d.ts /** * Fix unclosed code syntax in streaming markdown * * Handles two types of code syntax: * 1. Inline code: `code` (single backticks) * 2. Code blocks: ```language\ncode\n``` (triple backticks) * * Only processes the last paragraph (content after the last blank line) for inline code. * Code blocks can span multiple paragraphs, so they are processed globally. * * @param content - Markdown content (potentially incomplete in stream mode) * @returns Content with auto-completed code syntax if needed * * @example * fixCode('Hello `world') * // Returns: 'Hello `world`' * * @example * fixCode('```javascript\nconst x = 1') * // Returns: '```javascript\nconst x = 1\n```' * * @example * fixCode('`') * // Returns: '' (no completion, ` has no content) * * @example * fixCode('```') * // Returns: '```' (no completion, code block has no content) */ declare function fixCode(content: string): string; //#endregion //#region src/preprocess/delete.d.ts /** * Fix unclosed strikethrough (~~) syntax in streaming markdown * * Only processes the last paragraph (content after the last blank line). * This respects Markdown's rule that ~~ cannot span across paragraphs. * * @param content - Markdown content (potentially incomplete in stream mode) * @returns Content with auto-completed ~~ if needed * * @example * fixDelete('Hello ~~world') * // Returns: 'Hello ~~world~~' * * @example * fixDelete('Para1 ~~deleted~~\n\nPara2 ~~text') * // Returns: 'Para1 ~~deleted~~\n\nPara2 ~~text~~' * * @example * fixDelete('List item\n\n~~') * // Returns: 'List item\n\n~~' (no completion, ~~ has no content) */ declare function fixDelete(content: string): string; //#endregion //#region src/preprocess/emphasis.d.ts /** * Fix unclosed emphasis (* or _) syntax in streaming markdown * * Only processes the last paragraph (content after the last blank line). * This respects Markdown's rule that emphasis cannot span across paragraphs. */ declare function fixEmphasis(content: string): string; //#endregion //#region src/preprocess/footnote.d.ts /** * Remove incomplete footnote references ([^...]) in streaming markdown * * Processes the entire content to remove footnote references that don't have * corresponding definitions. This is necessary because footnote references can * appear anywhere in the document, while definitions typically appear at the end. * * A footnote reference is considered incomplete if there's no corresponding * footnote definition ([^...]:) in the entire content. * * @param content - Markdown content (potentially incomplete in stream mode) * @returns Content with incomplete footnote references removed * * @example * fixFootnote('Text [^1] and [^2]') * // Returns: 'Text [^1] and [^2]' (if [^1]: and [^2]: exist) * // Returns: 'Text and ' (if definitions don't exist) * * @example * fixFootnote('Para1 [^1]\n\nPara2 [^2]') * // Removes [^1] and [^2] if their definitions don't exist * * @example * fixFootnote('```\n[^1]\n```\n\nText [^1]') * // Code block content is ignored, only processes Text [^1] */ declare function fixFootnote(content: string): string; //#endregion //#region src/preprocess/html.d.ts /** * Remove trailing unclosed HTML-like fragments in stream mode. * * This prevents incomplete HTML from being emitted as plain text before the * parser can recognize it as an HTML node. */ declare function fixHtml(content: string): string; //#endregion //#region src/preprocess/inline-math.d.ts /** * Fix unclosed inline math ($$) syntax in streaming markdown * * Only processes the last paragraph (content after the last blank line). * This respects Markdown's rule that inline math cannot span across paragraphs. * * Note: This function only handles inline math ($$...$$). Block math ($$ on separate lines) * is handled by subsequent preprocess steps and should not be completed here. * * @param content - Markdown content (potentially incomplete in stream mode) * @returns Content with auto-completed $$ if needed * * @example * fixInlineMath('The formula is $$x = 1') * // Returns: 'The formula is $$x = 1$$' * * @example * fixInlineMath('Para1 $$x$$\n\nPara2 $$y') * // Returns: 'Para1 $$x$$\n\nPara2 $$y$$' * * @example * fixInlineMath('$$\nE = mc^2') * // Returns: '$$\nE = mc^2' (no completion, this is block math) * * @example * fixInlineMath('$$\n') * // Returns: '$$\n' (no completion, this is block math) */ declare function fixInlineMath(content: string): string; //#endregion //#region src/preprocess/link.d.ts /** * Fix unclosed link/image syntax in streaming markdown * * Link syntax: [text](url "title") * Image syntax: ![alt](url "title") * * Only processes the last paragraph (content after the last blank line). * This respects Markdown's rule that links cannot span across paragraphs. * * @param content - Markdown content (potentially incomplete in stream mode) * @returns Content with auto-completed link/image syntax if needed * * @example * fixLink('[Google](https://www.goo') * // Returns: '[Google](https://www.goo)' * * @example * fixLink('[text](') * // Returns: '[text]()' * * @example * fixLink('[text]') * // Returns: '[text]()' * * @example * fixLink('[text') * // Returns: '[text]()' * * @example * fixLink('![alt](https://image.png') * // Returns: '![alt](https://image.png)' * * @example * fixLink('Text [') * // Returns: 'Text ' * // Removes trailing standalone [ without content * * @example * fixLink('Text [\n') * // Returns: 'Text ' * // Removes trailing standalone bracket and trailing newline */ declare function fixLink(content: string): string; //#endregion //#region src/preprocess/math.d.ts /** * Fix unclosed block math ($$) syntax in streaming markdown * * Block math is defined as $$ delimiters on separate lines: * $$ * E = mc^2 * $$ * * This function processes the entire content (not just last paragraph) * because block math can span multiple paragraphs. * * @param content - Markdown content (potentially incomplete in stream mode) * @returns Content with auto-completed block math if needed * * @example * fixMath('$$\nE = mc^2') * // Returns: '$$\nE = mc^2\n$$' * * @example * fixMath('$$\nE = mc^2\n$$') * // Returns: '$$\nE = mc^2\n$$' (no change) */ declare function fixMath(content: string): string; //#endregion //#region src/preprocess/strong.d.ts /** * Fix unclosed strong (** or __) syntax in streaming markdown * * Only processes the last paragraph (content after the last blank line). * This respects Markdown's rule that strong formatting cannot span across paragraphs. * * @param content - Markdown content (potentially incomplete in stream mode) * @returns Content with auto-completed ** or __ if needed * * @example * fixStrong('Hello **world') * // Returns: 'Hello **world**' * * @example * fixStrong('Hello __world') * // Returns: 'Hello __world__' * * @example * fixStrong('Para1 **bold**\n\nPara2 **text') * // Returns: 'Para1 **bold**\n\nPara2 **text**' * * @example * fixStrong('List item\n\n**') * // Returns: 'List item\n\n**' (no completion, ** has no content) */ declare function fixStrong(content: string, options?: Pick): string; //#endregion //#region src/preprocess/table.d.ts /** * Fix incomplete table syntax in streaming markdown * * Handles markdown tables by detecting the header row and ensuring * a separator row exists. Only processes the last paragraph for streaming. * * Table format: * | Header 1 | Header 2 | * | -------- | -------- | * | Cell 1 | Cell 2 | * * @param content - Markdown content (potentially incomplete in stream mode) * @returns Content with auto-completed table separator if needed * * @example * fixTable('| a | b |\n') * // Returns: '| a | b |\n| --- | --- |' * * @example * fixTable('| a | b |\n| ---') * // Returns: '| a | b |\n| --- | --- |' * * @example * fixTable('| a | b |\n| --- | --- |') * // Returns: '| a | b |\n| --- | --- |' (no change, already complete) */ declare function fixTable(content: string): string; //#endregion //#region src/preprocess/task-list.d.ts /** * Fix incomplete task list syntax in streaming markdown * * Removes standalone `-` that appears on the last line without `[ ]` or `[x]` syntax. * Also removes incomplete task list items like `- [` that are being typed incrementally. * This prevents AST parsing jitter when task list items are being typed incrementally. * Also handles quote blocks (lines starting with `>`) to prevent leaving `> ` which could * cause the previous line to be misparsed as a heading. * * @param content - Markdown content (potentially incomplete in stream mode) * @returns Content with standalone `-` or incomplete `- [` removed from the last line if incomplete * * @example * fixTaskList('- [ ] Task 1\n-') * // Returns: '- [ ] Task 1\n' * * @example * fixTaskList('- [ ] Task 1\n- [x] Task 2\n-') * // Returns: '- [ ] Task 1\n- [x] Task 2\n' * * @example * fixTaskList('- [ ] Task 1\n - [') * // Returns: '- [ ] Task 1\n' * * @example * fixTaskList('> **Note**: Here\'s a quote with tasks:\n\n> -') * // Returns: '> **Note**: Here\'s a quote with tasks:\n\n' */ declare function fixTaskList(content: string): string; //#endregion //#region src/preprocess/vendored/markdown-utils.d.ts declare function preprocessLaTeX(content: string): string; //#endregion //#region src/preprocess/vendored/parse-blocks.d.ts declare function parseMarkdownIntoBlocks(markdown: string): string[]; //#endregion //#region src/preprocess/pattern.d.ts declare const crlfPattern: RegExp; declare const trailingBackticksPattern: RegExp; declare const codeBlockPattern: RegExp; declare const singleBacktickPattern: RegExp; declare const tripleBacktickPattern: RegExp; declare const inlineCodePattern: RegExp; declare const trailingWhitespacePattern: RegExp; declare const doubleAsteriskPattern: RegExp; declare const singleAsteriskPattern: RegExp; declare const doubleUnderscorePattern: RegExp; declare const singleUnderscorePattern: RegExp; declare const doubleTildePattern: RegExp; declare const singleDollarPattern: RegExp; declare const doubleDollarPattern: RegExp; declare const inlineBracketMathPattern: RegExp; declare const blockBracketMathPattern: RegExp; declare const parenMathPattern: RegExp; declare const inlineDollarMathPattern: RegExp; declare const dollarPlaceholderPattern: RegExp; declare const incompleteBracketPattern: RegExp; declare const incompleteLinkTextPattern: RegExp; declare const incompleteUrlPattern: RegExp; declare const incompleteFootnoteRefPattern: RegExp; declare const trailingStandaloneBracketPattern: RegExp; declare const standaloneBracketPattern: RegExp; declare const footnoteDefPattern: RegExp; declare const footnoteRefPattern: RegExp; declare const footnoteDefLinePattern: RegExp; declare const footnoteDefLabelPattern: RegExp; declare const footnoteRefLabelPattern: RegExp; declare const pipePattern: RegExp; declare const tableRowPattern: RegExp; declare const separatorPattern: RegExp; declare const standaloneDashPattern: RegExp; declare const dashWithSpacePattern: RegExp; declare const taskListPattern: RegExp; declare const incompleteTaskListPattern: RegExp; declare const quoteStandaloneDashPattern: RegExp; declare const quoteTaskListPattern: RegExp; declare const quoteIncompleteTaskListPattern: RegExp; declare const trailingStandaloneDashWithNewlinesPattern: RegExp; declare const linkImagePattern: RegExp; declare const linkImageUrlSuffixPattern: RegExp; declare const incompleteLinkImageUrlPattern: RegExp; declare const incompleteLinkImageUrlSuffixPattern: RegExp; declare const standaloneUrlPattern: RegExp; declare const htmlTagPattern: RegExp; //#endregion //#region src/preprocess/index.d.ts declare function proprocessContent(content: string): string; declare function normalize(content: string): string; declare const DEFAULT_PREPROCESS_STEPS: { code: typeof fixCode; html: typeof fixHtml; footnote: typeof fixFootnote; strong: typeof fixStrong; emphasis: typeof fixEmphasis; delete: typeof fixDelete; taskList: typeof fixTaskList; link: typeof fixLink; table: typeof fixTable; inlineMath: typeof fixInlineMath; math: typeof fixMath; }; declare function preprocess(content: string, options?: PreprocessContext, steps?: PreprocessSteps): string; //#endregion //#region src/processor.d.ts declare class MarkdownProcessor { private readonly options; constructor(options?: MarkdownProcessorOptions); normalize(content: string): string; preprocess(content: string, options?: PreprocessContext): string; parseMarkdownIntoBlocks(content: string): string[]; processMarkdown(content: string, options?: MarkdownProcessorRunOptions): MarkdownProcessorResult; } //#endregion //#region src/utils.d.ts declare function flow(fns: Array<(arg: T) => T>): (arg: T) => T; declare function checkMathSyntax(content: string, singleDollarEnabled?: boolean): boolean; //#endregion export { DEFAULT_PREPROCESS_STEPS, MarkdownProcessor, MarkdownProcessorMode, MarkdownProcessorOptions, MarkdownProcessorResult, MarkdownProcessorRunOptions, PreprocessContext, PreprocessStep, PreprocessStepName, PreprocessSteps, blockBracketMathPattern, checkMathSyntax, codeBlockPattern, crlfPattern, dashWithSpacePattern, dollarPlaceholderPattern, doubleAsteriskPattern, doubleDollarPattern, doubleTildePattern, doubleUnderscorePattern, fixCode, fixDelete, fixEmphasis, fixFootnote, fixHtml, fixInlineMath, fixLink, fixMath, fixStrong, fixTable, fixTaskList, flow, footnoteDefLabelPattern, footnoteDefLinePattern, footnoteDefPattern, footnoteRefLabelPattern, footnoteRefPattern, htmlTagPattern, incompleteBracketPattern, incompleteFootnoteRefPattern, incompleteLinkImageUrlPattern, incompleteLinkImageUrlSuffixPattern, incompleteLinkTextPattern, incompleteTaskListPattern, incompleteUrlPattern, inlineBracketMathPattern, inlineCodePattern, inlineDollarMathPattern, linkImagePattern, linkImageUrlSuffixPattern, normalize, parenMathPattern, parseMarkdownIntoBlocks, pipePattern, preprocess, preprocessLaTeX, proprocessContent, quoteIncompleteTaskListPattern, quoteStandaloneDashPattern, quoteTaskListPattern, separatorPattern, singleAsteriskPattern, singleBacktickPattern, singleDollarPattern, singleUnderscorePattern, standaloneBracketPattern, standaloneDashPattern, standaloneUrlPattern, tableRowPattern, taskListPattern, trailingBackticksPattern, trailingStandaloneBracketPattern, trailingStandaloneDashWithNewlinesPattern, trailingWhitespacePattern, tripleBacktickPattern };