@ai-react-markdown/engine 2.8.0 → 2.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -88,13 +88,6 @@ interface Deprecation {
88
88
  * `.parse()` and `.runSync()` (or `.run()`) on it.
89
89
  */
90
90
  declare function createProcessor(options: Readonly<PipelineOptions>): Processor<Root, Root, Root$1, undefined, undefined>;
91
- /**
92
- * Wrap the markdown string in a VFile so plugins that consume `file.value`
93
- * work. Mirrors react-markdown: in dev `unreachable` throws an AssertionError
94
- * for non-string `children`; in prod it silently no-ops, leaving `file.value`
95
- * undefined and unified treating the input as empty.
96
- */
97
- declare function createFile(options: Readonly<PipelineOptions>): VFile;
98
91
 
99
92
  /**
100
93
  * The pure pipeline stages, lifted verbatim from core's Markdown.tsx
@@ -533,7 +526,8 @@ declare function advanceIncrementalParse(prev: IncrementalParseState | null, con
533
526
  declare function attributeHastChildren(mdast: Root, hast: Root$1, stopAt?: number): number[];
534
527
 
535
528
  /**
536
- * TEST/STORY helper (not exported from the package barrel): prefix
529
+ * TEST/STORY helper (exported from the package barrel for the Storybook
530
+ * streams): prefix
537
531
  * snapshots sliced at CODE-POINT granularity, so a frame boundary never
538
532
  * splits a surrogate pair. Every streaming verifier in the repo — the
539
533
  * splice-equivalence arbiter, the prefixFreeze experiment harness, and the
@@ -1296,13 +1290,6 @@ declare const defaultEnginePlugins: readonly AIMarkdownEnginePlugin[];
1296
1290
  * `tagName === 'section'` AND presence of the `dataFootnotes` property.
1297
1291
  */
1298
1292
  declare function isFootnoteSection(node: Element): boolean;
1299
- /**
1300
- * Whitespace-only text node. `mdast-util-to-hast`'s `state.wrap(content,
1301
- * true)` interleaves `\n` text nodes between (and around) the block-level
1302
- * children of an `<li>`, so any code reasoning about a list item's real
1303
- * children has to look past them.
1304
- */
1305
- declare function isWhitespaceText(c: ElementContent): boolean;
1306
1293
  /**
1307
1294
  * Index of the last child that is not a whitespace-only text node, or -1 if
1308
1295
  * there is none.
@@ -1500,24 +1487,6 @@ declare function measureStage<T>(stage: PipelineStage, fn: () => T, instanceId?:
1500
1487
  */
1501
1488
 
1502
1489
  type Schema = typeof defaultSchema;
1503
- type AttributeEntry = NonNullable<NonNullable<Schema['attributes']>[string]>[number];
1504
- /**
1505
- * Extend the allowlist for a tag's `className` attribute with extra class
1506
- * names while preserving all other default entries.
1507
- *
1508
- * `findDefinition` in hast-util-sanitize returns the *first* matching entry
1509
- * for a given property name, so appending a second `className` entry would be
1510
- * ignored. Instead, merge the allowed values into the existing entry.
1511
- *
1512
- * Edge cases:
1513
- * - `existing` is `undefined` → returns a single new `['className', ...extra]`
1514
- * - `existing` has no `className` entry → appends one with just the extras
1515
- * - `existing` has a bare-string `'className'` entry (hast-util-sanitize's
1516
- * "allow all values" form) → would be narrowed to an allow-list. This is a
1517
- * semantics change, but the current `defaultSchema.attributes.code` entry
1518
- * is always tuple-form, so this branch is defensive only.
1519
- */
1520
- declare function mergeClassNameAllowlist(existing: ReadonlyArray<AttributeEntry> | undefined, extraClassNames: readonly string[]): AttributeEntry[];
1521
1490
  declare const sanitizeSchema: Schema;
1522
1491
 
1523
1492
  /**
@@ -1728,49 +1697,6 @@ type AIMDContentPreprocessor = (content: string) => string;
1728
1697
  */
1729
1698
  declare function preprocessAIMDContent(content: string, extraPreprocessors?: AIMDContentPreprocessor[], latexPreprocessor?: AIMDContentPreprocessor): string;
1730
1699
 
1731
- /**
1732
- * LaTeX preprocessing pipeline.
1733
- *
1734
- * Normalizes raw markdown so that LaTeX expressions survive the remark/rehype
1735
- * rendering pipeline intact. The main entry point is {@link preprocessLaTeX},
1736
- * which splits content into protected regions (code blocks, inline code, HTML
1737
- * tags) and applies a sequence of transformations to the unprotected text:
1738
- *
1739
- * 1. Escape mhchem commands (`\ce`, `\pu`)
1740
- * 2. Escape currency dollar signs (e.g. `$100`, `$1,000.50`)
1741
- * 3. Convert bracket delimiters (`\[...\]`, `\(...\)`) to dollar delimiters
1742
- * 4. Escape pipes inside closed LaTeX blocks to prevent GFM table interference
1743
- * 5. Escape pipes inside unclosed LaTeX blocks (streaming partial content)
1744
- * 6. Escape underscores inside `\text{...}` commands
1745
- * 7. Convert single-dollar delimiters to double-dollar delimiters
1746
- * 8. Truncate trailing unclosed LaTeX blocks (streaming protection)
1747
- *
1748
- * Thanks to the implementations from the following repositories:
1749
- * - https://github.com/lobehub/lobe-ui/blob/master/src/hooks/useMarkdown/latex.ts
1750
- * - https://github.com/danny-avila/LibreChat/blob/main/client/src/utils/latex.ts
1751
- *
1752
- * @module preprocessors/latex
1753
- */
1754
- interface Segment {
1755
- text: string;
1756
- isCode: boolean;
1757
- }
1758
- /**
1759
- * Split content into alternating text and protected segments.
1760
- * Protected segments (isCode: true) are excluded from LaTeX processing:
1761
- * - fenced multiline code blocks: 3+ backticks or tildes at the *start of a
1762
- * line* (any indentation — container-relative limits are not modelled).
1763
- * Mid-line runs are never fence openers. INDENTED code blocks (4+ spaces
1764
- * after a blank line, outside any container) are NOT modelled: without a
1765
- * container model they cannot be told from a list item's continuation
1766
- * paragraph, and protecting them would silence math in nested lists.
1767
- * Known limitation — `$` inside an indented code block may be rewritten.
1768
- * - inline code spans: a run of N backticks closed by another run of exactly
1769
- * N backticks. May span newlines. Multi-backtick forms (e.g. `` `` `x` ``)
1770
- * are supported so literal backtick characters can appear inside.
1771
- * - HTML tags (e.g. `<span>$</span>` where `$` should not be treated as LaTeX).
1772
- */
1773
- declare function splitByProtectedRegions(content: string): Segment[];
1774
1700
  /**
1775
1701
  * Main LaTeX preprocessor entry point.
1776
1702
  *
@@ -1879,4 +1805,4 @@ type RemendPreprocessorOptions = Omit<RemendOptions, 'katex' | 'inlineKatex'>;
1879
1805
  */
1880
1806
  declare function createRemendPreprocessor(options?: RemendPreprocessorOptions): AIMDContentPreprocessor;
1881
1807
 
1882
- export { type AIMDContentPreprocessor, type AIMarkdownEnginePlugin, type AIMarkdownEnginePluginName, type AdvanceOptions, type AdvanceResult, type AllowElement, type ChunkData, type Contribution, type CrossChunkHandlerOptions, DEFAULT_PAYLOAD, type DefLabelScanner, type DefLabels, type Deprecation, type EnginePluginInternals, type EnginePluginStage, type ExtractContributionsOptions, type FootnoteDef, type FreezeBoundaryOptions, type IncrementalParseState, type IncrementalStage, type LinkDef, PIPELINE_STAGES, type ParsedMarkdown, type PhantomLabels, type PipelineOptions, type PipelineStage, type RefKind, type RefRecord, type Registry, type RegistryInternal, type RehypePlugins, type RehypeRebaseHashLinksOptions, type RemarkPlugins, type RemarkRehypeOptions, type RemendPreprocessorOptions, SENTINEL_FN_CONTENT, SENTINEL_LINK_URL, SMOOTH_STREAM_PACING_PRESETS, STAGE_MEASURE_PREFIX, type SanitizeSchema, type SmoothStreamController, type SmoothStreamOptions, type SmoothStreamPacing, type SmoothStreamPacingParams, type TransformContext, type UrlAttrKey, type UrlAttrTag, type UrlTransform, advanceIncrementalParse, attributeHastChildren, buildCoreRehypePlugins, buildCoreRemarkPlugins, buildCoreRemarkRehypeOptions, buildCrossChunkHandlers, buildPhantomSuffix, buildTransform, codePointSnapshots, collectDefLabels, computeFreezeBoundary, createDefLabelScanner, createFile, createIncrementalLatexPreprocessor, createProcessor, createRegistry, createRemendPreprocessor, createSmoothStreamController, defaultEnginePlugins, defaultUrlTransform, definitionList, extendSanitizeSchema, extractContributions, extractDefBodiesFromHast, footnoteSafeId, getEnginePluginInternals, hasLoneSurrogate, highlight, isFootnoteSection, isWhitespaceText, lastMeaningfulIdx, measureStage, mergeClassNameAllowlist, normalizeForMatch, normalizeId, pangu, parseStage, phantomSuffixCloser, preprocessAIMDContent, preprocessLaTeX, rehypeFooterAdorn, rehypeRebaseHashLinks, removeComments, sanitizeCrossChunkUrl, sanitizeSchema, shortenDocumentId, smartypants, sourceIdFromFootnoteLiId, splitByProtectedRegions, subscribeStageTimings, transformStage, withDefs };
1808
+ export { type AIMDContentPreprocessor, type AIMarkdownEnginePlugin, type AIMarkdownEnginePluginName, type AdvanceOptions, type AdvanceResult, type AllowElement, type ChunkData, type Contribution, type CrossChunkHandlerOptions, DEFAULT_PAYLOAD, type DefLabelScanner, type DefLabels, type Deprecation, type EnginePluginInternals, type EnginePluginStage, type ExtractContributionsOptions, type FootnoteDef, type FreezeBoundaryOptions, type IncrementalParseState, type IncrementalStage, type LinkDef, PIPELINE_STAGES, type ParsedMarkdown, type PhantomLabels, type PipelineOptions, type PipelineStage, type RefKind, type RefRecord, type Registry, type RegistryInternal, type RehypePlugins, type RehypeRebaseHashLinksOptions, type RemarkPlugins, type RemarkRehypeOptions, type RemendPreprocessorOptions, SENTINEL_FN_CONTENT, SENTINEL_LINK_URL, SMOOTH_STREAM_PACING_PRESETS, STAGE_MEASURE_PREFIX, type SanitizeSchema, type SmoothStreamController, type SmoothStreamOptions, type SmoothStreamPacing, type SmoothStreamPacingParams, type TransformContext, type UrlAttrKey, type UrlAttrTag, type UrlTransform, advanceIncrementalParse, attributeHastChildren, buildCoreRehypePlugins, buildCoreRemarkPlugins, buildCoreRemarkRehypeOptions, buildCrossChunkHandlers, buildPhantomSuffix, buildTransform, codePointSnapshots, collectDefLabels, computeFreezeBoundary, createDefLabelScanner, createIncrementalLatexPreprocessor, createProcessor, createRegistry, createRemendPreprocessor, createSmoothStreamController, defaultEnginePlugins, defaultUrlTransform, definitionList, extendSanitizeSchema, extractContributions, extractDefBodiesFromHast, footnoteSafeId, getEnginePluginInternals, hasLoneSurrogate, highlight, isFootnoteSection, lastMeaningfulIdx, measureStage, normalizeForMatch, normalizeId, pangu, parseStage, phantomSuffixCloser, preprocessAIMDContent, preprocessLaTeX, rehypeFooterAdorn, rehypeRebaseHashLinks, removeComments, sanitizeCrossChunkUrl, sanitizeSchema, shortenDocumentId, smartypants, sourceIdFromFootnoteLiId, subscribeStageTimings, transformStage, withDefs };
package/dist/index.d.ts CHANGED
@@ -88,13 +88,6 @@ interface Deprecation {
88
88
  * `.parse()` and `.runSync()` (or `.run()`) on it.
89
89
  */
90
90
  declare function createProcessor(options: Readonly<PipelineOptions>): Processor<Root, Root, Root$1, undefined, undefined>;
91
- /**
92
- * Wrap the markdown string in a VFile so plugins that consume `file.value`
93
- * work. Mirrors react-markdown: in dev `unreachable` throws an AssertionError
94
- * for non-string `children`; in prod it silently no-ops, leaving `file.value`
95
- * undefined and unified treating the input as empty.
96
- */
97
- declare function createFile(options: Readonly<PipelineOptions>): VFile;
98
91
 
99
92
  /**
100
93
  * The pure pipeline stages, lifted verbatim from core's Markdown.tsx
@@ -533,7 +526,8 @@ declare function advanceIncrementalParse(prev: IncrementalParseState | null, con
533
526
  declare function attributeHastChildren(mdast: Root, hast: Root$1, stopAt?: number): number[];
534
527
 
535
528
  /**
536
- * TEST/STORY helper (not exported from the package barrel): prefix
529
+ * TEST/STORY helper (exported from the package barrel for the Storybook
530
+ * streams): prefix
537
531
  * snapshots sliced at CODE-POINT granularity, so a frame boundary never
538
532
  * splits a surrogate pair. Every streaming verifier in the repo — the
539
533
  * splice-equivalence arbiter, the prefixFreeze experiment harness, and the
@@ -1296,13 +1290,6 @@ declare const defaultEnginePlugins: readonly AIMarkdownEnginePlugin[];
1296
1290
  * `tagName === 'section'` AND presence of the `dataFootnotes` property.
1297
1291
  */
1298
1292
  declare function isFootnoteSection(node: Element): boolean;
1299
- /**
1300
- * Whitespace-only text node. `mdast-util-to-hast`'s `state.wrap(content,
1301
- * true)` interleaves `\n` text nodes between (and around) the block-level
1302
- * children of an `<li>`, so any code reasoning about a list item's real
1303
- * children has to look past them.
1304
- */
1305
- declare function isWhitespaceText(c: ElementContent): boolean;
1306
1293
  /**
1307
1294
  * Index of the last child that is not a whitespace-only text node, or -1 if
1308
1295
  * there is none.
@@ -1500,24 +1487,6 @@ declare function measureStage<T>(stage: PipelineStage, fn: () => T, instanceId?:
1500
1487
  */
1501
1488
 
1502
1489
  type Schema = typeof defaultSchema;
1503
- type AttributeEntry = NonNullable<NonNullable<Schema['attributes']>[string]>[number];
1504
- /**
1505
- * Extend the allowlist for a tag's `className` attribute with extra class
1506
- * names while preserving all other default entries.
1507
- *
1508
- * `findDefinition` in hast-util-sanitize returns the *first* matching entry
1509
- * for a given property name, so appending a second `className` entry would be
1510
- * ignored. Instead, merge the allowed values into the existing entry.
1511
- *
1512
- * Edge cases:
1513
- * - `existing` is `undefined` → returns a single new `['className', ...extra]`
1514
- * - `existing` has no `className` entry → appends one with just the extras
1515
- * - `existing` has a bare-string `'className'` entry (hast-util-sanitize's
1516
- * "allow all values" form) → would be narrowed to an allow-list. This is a
1517
- * semantics change, but the current `defaultSchema.attributes.code` entry
1518
- * is always tuple-form, so this branch is defensive only.
1519
- */
1520
- declare function mergeClassNameAllowlist(existing: ReadonlyArray<AttributeEntry> | undefined, extraClassNames: readonly string[]): AttributeEntry[];
1521
1490
  declare const sanitizeSchema: Schema;
1522
1491
 
1523
1492
  /**
@@ -1728,49 +1697,6 @@ type AIMDContentPreprocessor = (content: string) => string;
1728
1697
  */
1729
1698
  declare function preprocessAIMDContent(content: string, extraPreprocessors?: AIMDContentPreprocessor[], latexPreprocessor?: AIMDContentPreprocessor): string;
1730
1699
 
1731
- /**
1732
- * LaTeX preprocessing pipeline.
1733
- *
1734
- * Normalizes raw markdown so that LaTeX expressions survive the remark/rehype
1735
- * rendering pipeline intact. The main entry point is {@link preprocessLaTeX},
1736
- * which splits content into protected regions (code blocks, inline code, HTML
1737
- * tags) and applies a sequence of transformations to the unprotected text:
1738
- *
1739
- * 1. Escape mhchem commands (`\ce`, `\pu`)
1740
- * 2. Escape currency dollar signs (e.g. `$100`, `$1,000.50`)
1741
- * 3. Convert bracket delimiters (`\[...\]`, `\(...\)`) to dollar delimiters
1742
- * 4. Escape pipes inside closed LaTeX blocks to prevent GFM table interference
1743
- * 5. Escape pipes inside unclosed LaTeX blocks (streaming partial content)
1744
- * 6. Escape underscores inside `\text{...}` commands
1745
- * 7. Convert single-dollar delimiters to double-dollar delimiters
1746
- * 8. Truncate trailing unclosed LaTeX blocks (streaming protection)
1747
- *
1748
- * Thanks to the implementations from the following repositories:
1749
- * - https://github.com/lobehub/lobe-ui/blob/master/src/hooks/useMarkdown/latex.ts
1750
- * - https://github.com/danny-avila/LibreChat/blob/main/client/src/utils/latex.ts
1751
- *
1752
- * @module preprocessors/latex
1753
- */
1754
- interface Segment {
1755
- text: string;
1756
- isCode: boolean;
1757
- }
1758
- /**
1759
- * Split content into alternating text and protected segments.
1760
- * Protected segments (isCode: true) are excluded from LaTeX processing:
1761
- * - fenced multiline code blocks: 3+ backticks or tildes at the *start of a
1762
- * line* (any indentation — container-relative limits are not modelled).
1763
- * Mid-line runs are never fence openers. INDENTED code blocks (4+ spaces
1764
- * after a blank line, outside any container) are NOT modelled: without a
1765
- * container model they cannot be told from a list item's continuation
1766
- * paragraph, and protecting them would silence math in nested lists.
1767
- * Known limitation — `$` inside an indented code block may be rewritten.
1768
- * - inline code spans: a run of N backticks closed by another run of exactly
1769
- * N backticks. May span newlines. Multi-backtick forms (e.g. `` `` `x` ``)
1770
- * are supported so literal backtick characters can appear inside.
1771
- * - HTML tags (e.g. `<span>$</span>` where `$` should not be treated as LaTeX).
1772
- */
1773
- declare function splitByProtectedRegions(content: string): Segment[];
1774
1700
  /**
1775
1701
  * Main LaTeX preprocessor entry point.
1776
1702
  *
@@ -1879,4 +1805,4 @@ type RemendPreprocessorOptions = Omit<RemendOptions, 'katex' | 'inlineKatex'>;
1879
1805
  */
1880
1806
  declare function createRemendPreprocessor(options?: RemendPreprocessorOptions): AIMDContentPreprocessor;
1881
1807
 
1882
- export { type AIMDContentPreprocessor, type AIMarkdownEnginePlugin, type AIMarkdownEnginePluginName, type AdvanceOptions, type AdvanceResult, type AllowElement, type ChunkData, type Contribution, type CrossChunkHandlerOptions, DEFAULT_PAYLOAD, type DefLabelScanner, type DefLabels, type Deprecation, type EnginePluginInternals, type EnginePluginStage, type ExtractContributionsOptions, type FootnoteDef, type FreezeBoundaryOptions, type IncrementalParseState, type IncrementalStage, type LinkDef, PIPELINE_STAGES, type ParsedMarkdown, type PhantomLabels, type PipelineOptions, type PipelineStage, type RefKind, type RefRecord, type Registry, type RegistryInternal, type RehypePlugins, type RehypeRebaseHashLinksOptions, type RemarkPlugins, type RemarkRehypeOptions, type RemendPreprocessorOptions, SENTINEL_FN_CONTENT, SENTINEL_LINK_URL, SMOOTH_STREAM_PACING_PRESETS, STAGE_MEASURE_PREFIX, type SanitizeSchema, type SmoothStreamController, type SmoothStreamOptions, type SmoothStreamPacing, type SmoothStreamPacingParams, type TransformContext, type UrlAttrKey, type UrlAttrTag, type UrlTransform, advanceIncrementalParse, attributeHastChildren, buildCoreRehypePlugins, buildCoreRemarkPlugins, buildCoreRemarkRehypeOptions, buildCrossChunkHandlers, buildPhantomSuffix, buildTransform, codePointSnapshots, collectDefLabels, computeFreezeBoundary, createDefLabelScanner, createFile, createIncrementalLatexPreprocessor, createProcessor, createRegistry, createRemendPreprocessor, createSmoothStreamController, defaultEnginePlugins, defaultUrlTransform, definitionList, extendSanitizeSchema, extractContributions, extractDefBodiesFromHast, footnoteSafeId, getEnginePluginInternals, hasLoneSurrogate, highlight, isFootnoteSection, isWhitespaceText, lastMeaningfulIdx, measureStage, mergeClassNameAllowlist, normalizeForMatch, normalizeId, pangu, parseStage, phantomSuffixCloser, preprocessAIMDContent, preprocessLaTeX, rehypeFooterAdorn, rehypeRebaseHashLinks, removeComments, sanitizeCrossChunkUrl, sanitizeSchema, shortenDocumentId, smartypants, sourceIdFromFootnoteLiId, splitByProtectedRegions, subscribeStageTimings, transformStage, withDefs };
1808
+ export { type AIMDContentPreprocessor, type AIMarkdownEnginePlugin, type AIMarkdownEnginePluginName, type AdvanceOptions, type AdvanceResult, type AllowElement, type ChunkData, type Contribution, type CrossChunkHandlerOptions, DEFAULT_PAYLOAD, type DefLabelScanner, type DefLabels, type Deprecation, type EnginePluginInternals, type EnginePluginStage, type ExtractContributionsOptions, type FootnoteDef, type FreezeBoundaryOptions, type IncrementalParseState, type IncrementalStage, type LinkDef, PIPELINE_STAGES, type ParsedMarkdown, type PhantomLabels, type PipelineOptions, type PipelineStage, type RefKind, type RefRecord, type Registry, type RegistryInternal, type RehypePlugins, type RehypeRebaseHashLinksOptions, type RemarkPlugins, type RemarkRehypeOptions, type RemendPreprocessorOptions, SENTINEL_FN_CONTENT, SENTINEL_LINK_URL, SMOOTH_STREAM_PACING_PRESETS, STAGE_MEASURE_PREFIX, type SanitizeSchema, type SmoothStreamController, type SmoothStreamOptions, type SmoothStreamPacing, type SmoothStreamPacingParams, type TransformContext, type UrlAttrKey, type UrlAttrTag, type UrlTransform, advanceIncrementalParse, attributeHastChildren, buildCoreRehypePlugins, buildCoreRemarkPlugins, buildCoreRemarkRehypeOptions, buildCrossChunkHandlers, buildPhantomSuffix, buildTransform, codePointSnapshots, collectDefLabels, computeFreezeBoundary, createDefLabelScanner, createIncrementalLatexPreprocessor, createProcessor, createRegistry, createRemendPreprocessor, createSmoothStreamController, defaultEnginePlugins, defaultUrlTransform, definitionList, extendSanitizeSchema, extractContributions, extractDefBodiesFromHast, footnoteSafeId, getEnginePluginInternals, hasLoneSurrogate, highlight, isFootnoteSection, lastMeaningfulIdx, measureStage, normalizeForMatch, normalizeId, pangu, parseStage, phantomSuffixCloser, preprocessAIMDContent, preprocessLaTeX, rehypeFooterAdorn, rehypeRebaseHashLinks, removeComments, sanitizeCrossChunkUrl, sanitizeSchema, shortenDocumentId, smartypants, sourceIdFromFootnoteLiId, subscribeStageTimings, transformStage, withDefs };
@@ -48,7 +48,6 @@ __export(src_exports, {
48
48
  collectDefLabels: () => collectDefLabels,
49
49
  computeFreezeBoundary: () => computeFreezeBoundary,
50
50
  createDefLabelScanner: () => createDefLabelScanner,
51
- createFile: () => createFile,
52
51
  createIncrementalLatexPreprocessor: () => createIncrementalLatexPreprocessor,
53
52
  createProcessor: () => createProcessor,
54
53
  createRegistry: () => createRegistry,
@@ -65,10 +64,8 @@ __export(src_exports, {
65
64
  hasLoneSurrogate: () => hasLoneSurrogate,
66
65
  highlight: () => highlight,
67
66
  isFootnoteSection: () => isFootnoteSection,
68
- isWhitespaceText: () => isWhitespaceText,
69
67
  lastMeaningfulIdx: () => lastMeaningfulIdx,
70
68
  measureStage: () => measureStage,
71
- mergeClassNameAllowlist: () => mergeClassNameAllowlist,
72
69
  normalizeForMatch: () => normalizeForMatch,
73
70
  normalizeId: () => normalizeId,
74
71
  pangu: () => pangu,
@@ -84,7 +81,6 @@ __export(src_exports, {
84
81
  shortenDocumentId: () => shortenDocumentId,
85
82
  smartypants: () => smartypants,
86
83
  sourceIdFromFootnoteLiId: () => sourceIdFromFootnoteLiId,
87
- splitByProtectedRegions: () => splitByProtectedRegions,
88
84
  subscribeStageTimings: () => subscribeStageTimings,
89
85
  transformStage: () => transformStage,
90
86
  withDefs: () => withDefs
@@ -594,6 +590,7 @@ var isType7Line = (line) => {
594
590
  return i >= t.length;
595
591
  };
596
592
  var mdHtml = (b, type) => b.kind === "html" && b.type === type;
593
+ var mdType1RawText = (b) => b.kind === "html" && b.type === 1 && b.raw;
597
594
  var mdHtml25 = (b) => b.kind === "html" && b.type >= 2 && b.type <= 5;
598
595
  var commentEitherOpen = (md, p5) => mdHtml(md, 2) || p5.kind === "comment";
599
596
  var inRawTextTok = (t) => t.kind === "rawText" || t.kind === "script";
@@ -615,11 +612,13 @@ var VOID_TAGS = /* @__PURE__ */ new Set([
615
612
  "wbr"
616
613
  ]);
617
614
  var LIST_MARKER_RE = /^ {0,3}(?:[-*+]|\d{1,9}[.)])(?:[ \t]|$)/;
615
+ var CONTAINER_MARKER_RE = /^ {0,3}(?:>|(?:[-*+]|\d{1,9}[.)])[ \t]+\S)/;
618
616
  var ATX_HEADING_RE = /^#{1,6}(?:[ \t]|$)/;
619
617
  var THEMATIC_BREAK_RE = /^(?:(?:-[ \t]*){3,}|(?:\*[ \t]*){3,}|(?:_[ \t]*){3,})$/;
620
618
  var BARE_MARKER_RE = /^(?:[-*+]|\d{1,9}[.)])[ \t]*$/;
621
619
  var SETEXT_LEFTOVER_RE = /^(?:=+|--)[ \t]*$/;
622
620
  var DEF_LIST_DD_RE = /^ {0,3}:[ \t]/;
621
+ var CLOSE_TAG_ONLY_RE = /^[ \t]*<\/[A-Za-z][A-Za-z0-9-]*[ \t]*>[ \t\r]*$/;
623
622
  var FENCE_RE = /^ {0,3}(`{3,}|~{3,})/;
624
623
  var MATH_RUN_RE = /^ {0,3}(\$\$+)/;
625
624
  var TAG_OR_COMMENT_RE = /<(\/?)([A-Za-z][A-Za-z0-9-]*)(?=[\s/>])([^>]*)>|<!--|-->|--!>/g;
@@ -730,9 +729,12 @@ function freshCheckpoint(defListEnabled, mathFlow, referenceTaint) {
730
729
  prevLineWasValidDef: false,
731
730
  prevLineOpenContent: false,
732
731
  tableMaybeOpen: false,
732
+ containerMaybeOpen: false,
733
733
  paragraphHasUnpairedRun: false,
734
734
  openBracket: null,
735
735
  p5SealPending: false,
736
+ defBlockMaybeOpen: false,
737
+ fnDefResumable: false,
736
738
  phasePoisonedAt: Infinity,
737
739
  pendingTruncatedTags: [],
738
740
  pendingTruncatedCloses: [],
@@ -860,9 +862,10 @@ function processConfirmedLine(cp, ln, text) {
860
862
  }
861
863
  const isBlockStart = cp.prevLineBlank;
862
864
  if (cp.p5SealPending && !ln.blank && cp.mdBlock.kind !== "html" && !(cp.p5Tok.kind === "comment" || cp.p5Tok.kind === "bogus")) {
863
- const defShapedLine = DEF_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text);
865
+ const defShapedLine = DEF_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text) || cp.defBlockMaybeOpen || cp.fnDefResumable && !(isBlockStart && ln.indent <= 3);
864
866
  const commentOnly = ln.text.replace(/<!--[\s\S]*?-->/g, " ").replace(/<!--[\s\S]*$/, " ").replace(/[ \t\r]/g, "") === "";
865
- if (!defShapedLine && !commentOnly) {
867
+ const closeTagOnly = CLOSE_TAG_ONLY_RE.test(ln.text);
868
+ if (!defShapedLine && !commentOnly && !closeTagOnly) {
866
869
  cp.p5SealPending = false;
867
870
  }
868
871
  }
@@ -914,7 +917,7 @@ function processConfirmedLine(cp, ln, text) {
914
917
  cp.openTotal += 1;
915
918
  }
916
919
  };
917
- const definitelyInsideTable = () => (cp.tagBalance.get("table") ?? 0) > 0;
920
+ const definitelyInsideTable = () => (cp.tagBalance.get("table") ?? 0) > cp.pendingTruncatedTags.filter((t) => t === "table").length;
918
921
  const strayTablePart = (tag) => TABLE_PART_NAMES.has(tag) && !definitelyInsideTable();
919
922
  const commentOpenAtLineStart = commentEitherOpen(cp.mdBlock, cp.p5Tok);
920
923
  const bothCommentsOpenAtLineStart = mdHtml(cp.mdBlock, 2) && cp.p5Tok.kind === "comment";
@@ -936,6 +939,7 @@ function processConfirmedLine(cp, ln, text) {
936
939
  cp.prevLineWasValidDef = false;
937
940
  cp.prevLineOpenContent = false;
938
941
  cp.tableMaybeOpen = false;
942
+ cp.containerMaybeOpen = false;
939
943
  return;
940
944
  }
941
945
  if (cp.mdBlock.kind !== "math" && !rawOpenAtLineStart) {
@@ -957,6 +961,7 @@ function processConfirmedLine(cp, ln, text) {
957
961
  cp.prevLineWasValidDef = false;
958
962
  cp.prevLineOpenContent = false;
959
963
  cp.tableMaybeOpen = false;
964
+ cp.containerMaybeOpen = false;
960
965
  return;
961
966
  }
962
967
  }
@@ -973,6 +978,7 @@ function processConfirmedLine(cp, ln, text) {
973
978
  cp.prevLineWasValidDef = false;
974
979
  cp.prevLineOpenContent = false;
975
980
  cp.tableMaybeOpen = false;
981
+ cp.containerMaybeOpen = false;
976
982
  return;
977
983
  }
978
984
  const mathRun = cp.mathFlow && !rawOpenAtLineStart ? MATH_RUN_RE.exec(ln.text) : null;
@@ -995,6 +1001,7 @@ function processConfirmedLine(cp, ln, text) {
995
1001
  cp.prevLineWasValidDef = false;
996
1002
  cp.prevLineOpenContent = false;
997
1003
  cp.tableMaybeOpen = false;
1004
+ cp.containerMaybeOpen = false;
998
1005
  return;
999
1006
  }
1000
1007
  }
@@ -1043,8 +1050,10 @@ function processConfirmedLine(cp, ln, text) {
1043
1050
  cp.prevLineBlank = true;
1044
1051
  cp.prevLineWasText = false;
1045
1052
  cp.prevLineWasValidDef = false;
1053
+ cp.defBlockMaybeOpen = false;
1046
1054
  cp.prevLineOpenContent = false;
1047
1055
  cp.tableMaybeOpen = false;
1056
+ cp.containerMaybeOpen = false;
1048
1057
  return;
1049
1058
  }
1050
1059
  if (isBlockStart) {
@@ -1056,21 +1065,27 @@ function processConfirmedLine(cp, ln, text) {
1056
1065
  const tagStart = ln.indent <= 3 ? /^<\/?([A-Za-z][A-Za-z0-9-]*)/.exec(mdTrimStart(ln.text)) : null;
1057
1066
  if (tagStart) {
1058
1067
  const noRealBlockOpen = cp.mdBlock.kind !== "html";
1059
- if (noRealBlockOpen && TYPE1_START_RE.test(mdTrimStart(ln.text))) cp.mdBlock = { kind: "html", type: 1 };
1068
+ const t1 = noRealBlockOpen ? TYPE1_START_RE.exec(mdTrimStart(ln.text)) : null;
1069
+ if (t1) cp.mdBlock = { kind: "html", type: 1, raw: RAW_TEXT_ELEMENTS.has(t1[1].toLowerCase()), indent: ln.indent };
1060
1070
  if (cp.mdBlock.kind !== "html") {
1061
1071
  const t = mdTrimStart(ln.text);
1062
1072
  const t6 = TYPE6_START_RE.exec(t);
1063
1073
  const realT6 = t6 !== null && TYPE6_NAMES.has(t6[1].toLowerCase());
1064
- if (realT6 || TYPE1_START_RE.test(t) || // Type 7 cannot interrupt CONTENT (micromark's paragraph/definition
1074
+ const t1Line = TYPE1_START_RE.test(t);
1075
+ const type7Shaped = !realT6 && !t1Line && isType7Line(t);
1076
+ if (realT6 || t1Line || // Type 7 cannot interrupt CONTENT (micromark's paragraph/definition
1065
1077
  // construct — `prevLineOpenContent`, the exact interrupt input; the
1066
1078
  // old `prevLineWasText` gate refused after headings, terminator
1067
1079
  // lines and fence closes, where micromark measurably opens). The
1068
1080
  // classifier itself is exact too (isType7Line) — including closing
1069
1081
  // raw-text names (`</style>` alone is type 7, measured) and
1070
1082
  // quoted-`>` attribute values.
1071
- !cp.prevLineOpenContent && isType7Line(t)) {
1072
- if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: realT6 ? 6 : 7 };
1073
- } else if (cp.prevLineOpenContent && cp.tableMaybeOpen && isType7Line(t)) {
1083
+ !cp.prevLineOpenContent && type7Shaped) {
1084
+ if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: realT6 ? 6 : 7, indent: ln.indent };
1085
+ } else if (cp.prevLineOpenContent && cp.tableMaybeOpen && type7Shaped) {
1086
+ cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
1087
+ }
1088
+ if (type7Shaped && cp.containerMaybeOpen) {
1074
1089
  cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
1075
1090
  }
1076
1091
  }
@@ -1136,7 +1151,12 @@ function processConfirmedLine(cp, ln, text) {
1136
1151
  pos = c + 1;
1137
1152
  continue;
1138
1153
  }
1139
- if (commentOpenAtLineStart || inRawTextTok(cp.p5Tok) || mdHtml(cp.mdBlock, 1)) break;
1154
+ if (commentOpenAtLineStart || inRawTextTok(cp.p5Tok) || mdType1RawText(cp.mdBlock)) {
1155
+ if (inRawTextTok(cp.p5Tok) && cp.p5Tok.openedInline && (tailCarriesRetroactive(ln.text) || /<template(?![a-z0-9-])/i.test(ln.text))) {
1156
+ cp.phasePoisonedAt = 0;
1157
+ }
1158
+ break;
1159
+ }
1140
1160
  const pi = scanText.indexOf("<?", pos);
1141
1161
  const cd = scanText.indexOf("<![CDATA[", pos);
1142
1162
  const dm = scanText.slice(pos).search(/<![A-Za-z]/);
@@ -1153,7 +1173,7 @@ function processConfirmedLine(cp, ln, text) {
1153
1173
  pos = bogus + 2;
1154
1174
  } else if (first === cd) {
1155
1175
  rawSpans.push([cd, cd + 9]);
1156
- if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 5 };
1176
+ if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 5, indent: ln.indent };
1157
1177
  if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "bogus" };
1158
1178
  if (!isMdBlank(scanText.slice(0, cd)) || ln.indent > 3) inlineRawOpenerIdx = cd;
1159
1179
  pos = cd + 9;
@@ -1165,14 +1185,14 @@ function processConfirmedLine(cp, ln, text) {
1165
1185
  continue;
1166
1186
  }
1167
1187
  rawSpans.push([pi, pi + 2]);
1168
- if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 3 };
1188
+ if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 3, indent: ln.indent };
1169
1189
  if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "bogus" };
1170
1190
  if (!isMdBlank(scanText.slice(0, pi)) || ln.indent > 3) inlineRawOpenerIdx = pi;
1171
1191
  pos = pi + 2;
1172
1192
  } else {
1173
1193
  rawSpans.push([decl, decl + 2]);
1174
1194
  if (ln.indent <= 3 && /^doctype/i.test(scanText.slice(decl + 2))) cp.phasePoisonedAt = 0;
1175
- if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 4 };
1195
+ if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 4, indent: ln.indent };
1176
1196
  if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "bogus" };
1177
1197
  if (!isMdBlank(scanText.slice(0, decl)) || ln.indent > 3) inlineRawOpenerIdx = decl;
1178
1198
  pos = decl + 2;
@@ -1231,7 +1251,7 @@ function processConfirmedLine(cp, ln, text) {
1231
1251
  if (next.startsWith(">") || next === "->") {
1232
1252
  continue;
1233
1253
  }
1234
- if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 2 };
1254
+ if (cp.mdBlock.kind === "none") cp.mdBlock = { kind: "html", type: 2, indent: ln.indent };
1235
1255
  if (cp.p5Tok.kind === "data") cp.p5Tok = { kind: "comment" };
1236
1256
  lastCommentOpenerIdx = m.index;
1237
1257
  continue;
@@ -1373,17 +1393,37 @@ function processConfirmedLine(cp, ln, text) {
1373
1393
  openContent = false;
1374
1394
  } else if (ln.indent >= 4) {
1375
1395
  openContent = cp.prevLineOpenContent;
1376
- } else if (ATX_HEADING_RE.test(tt) || THEMATIC_BREAK_RE.test(tt) || BARE_MARKER_RE.test(tt)) {
1396
+ } else if (ATX_HEADING_RE.test(tt) || THEMATIC_BREAK_RE.test(tt)) {
1377
1397
  openContent = false;
1398
+ } else if (BARE_MARKER_RE.test(tt)) {
1399
+ openContent = tt[0] === "-" ? false : cp.prevLineOpenContent;
1378
1400
  } else if (SETEXT_LEFTOVER_RE.test(tt)) {
1379
- openContent = !cp.prevLineOpenContent;
1401
+ openContent = cp.tableMaybeOpen && cp.prevLineOpenContent ? true : !cp.prevLineOpenContent;
1380
1402
  } else {
1381
1403
  openContent = true;
1382
1404
  }
1383
1405
  cp.prevLineOpenContent = openContent;
1384
- cp.tableMaybeOpen = ln.text.includes("|") || cp.tableMaybeOpen && openContent;
1406
+ cp.tableMaybeOpen = !htmlOwnedLine && ln.text.includes("|") || cp.tableMaybeOpen && openContent;
1407
+ const containerMarker = CONTAINER_MARKER_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text) || cp.defListEnabled && DEF_LIST_DD_RE.test(ln.text);
1408
+ cp.containerMaybeOpen = openContent && (containerMarker || cp.containerMaybeOpen);
1385
1409
  }
1386
1410
  cp.prevLineWasValidDef = validLinkDef;
1411
+ cp.defBlockMaybeOpen = cp.defBlockMaybeOpen || DEF_RE.test(ln.text) || FOOTNOTE_DEF_RE.test(ln.text);
1412
+ if (FOOTNOTE_DEF_RE.test(ln.text)) cp.fnDefResumable = true;
1413
+ else if (isBlockStart && ln.indent <= 3) cp.fnDefResumable = false;
1414
+ const isBarrier = (name) => SCOPE_BARRIER_NAMES.has(name);
1415
+ const topLevelHtmlBlock = cp.mdBlock.kind === "html" && cp.mdBlock.indent === 0;
1416
+ const confirmedBarriers = cp.openStack.filter(isBarrier).length - cp.pendingTruncatedTags.filter(isBarrier).length;
1417
+ if (!topLevelHtmlBlock && confirmedBarriers > 0) {
1418
+ cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
1419
+ }
1420
+ const maskUnbacked = mdType1RawText(cp.mdBlock) && !inRawTextTok(cp.p5Tok);
1421
+ if (maskUnbacked) {
1422
+ cp.phasePoisonedAt = Math.min(cp.phasePoisonedAt, ln.start);
1423
+ if (tailCarriesRetroactive(ln.text) || /<template(?![a-z0-9-])/i.test(ln.text)) {
1424
+ cp.phasePoisonedAt = 0;
1425
+ }
1426
+ }
1387
1427
  }
1388
1428
 
1389
1429
  // src/components/incrementalParse/spliceParse.ts
@@ -1898,7 +1938,7 @@ function alignPrefixCut(prefixMdast, cutRegion, tailWrapVisible) {
1898
1938
  if (sepBuffer.length !== trailingGaps && sepBuffer.length !== trailingGaps + 1) return null;
1899
1939
  for (let j = pairIdx + 1; j < visibles.length; j++) {
1900
1940
  const v = visibles[j];
1901
- if (v.type === "html" && !/^\s*<[!?]/.test(v.value)) return null;
1941
+ if (v.type === "html" && !isExactSanitizeStrippedConstruct(v.value)) return null;
1902
1942
  }
1903
1943
  for (let i = 0; i < trailingGaps + seam; i++) {
1904
1944
  out.push({ type: "text", value: "\n" });
@@ -1948,7 +1988,7 @@ function tailLeadingTextIsHoist(tailMdastChildren, tailHastChildren) {
1948
1988
  if (!isSeparatorText(firstText)) {
1949
1989
  if (firstText.type === "text" && firstText.position === void 0 && firstVisible?.type === "html") {
1950
1990
  if (/^\s*<\/[A-Za-z][A-Za-z0-9-]*\s*>/.test(firstVisible.value)) return true;
1951
- if (isCompleteRawConstruct(firstVisible.value)) return false;
1991
+ if (isSanitizeStrippedConstruct(firstVisible.value)) return false;
1952
1992
  return null;
1953
1993
  }
1954
1994
  return false;
@@ -1964,12 +2004,26 @@ function tailLeadingTextIsHoist(tailMdastChildren, tailHastChildren) {
1964
2004
  }
1965
2005
  }
1966
2006
  if (firstVisible.type === "math") return false;
1967
- if (firstVisible.type === "html" && isCompleteRawConstruct(firstVisible.value)) return false;
2007
+ if (firstVisible.type === "html" && isSanitizeStrippedConstruct(firstVisible.value)) return false;
1968
2008
  return null;
1969
2009
  }
1970
- function isCompleteRawConstruct(value) {
2010
+ function isSanitizeStrippedConstruct(value) {
1971
2011
  const v = value.trim();
1972
- return v.startsWith("<!--") && v.endsWith("-->") || v.startsWith("<?") && v.endsWith("?>") || v.startsWith("<![CDATA[") && v.endsWith("]]>") || /^<![A-Za-z]/.test(v) && v.endsWith(">");
2012
+ return v.startsWith("<!--") && v.endsWith("-->") || v.startsWith("<?") && v.endsWith("?>") || v.startsWith("<![CDATA[") && v.endsWith("]]>") || /^<![A-Za-z]/.test(v) && !/^<!doctype/i.test(v) && v.endsWith(">");
2013
+ }
2014
+ function isExactSanitizeStrippedConstruct(value) {
2015
+ if (value.startsWith("<!--")) {
2016
+ if (value.length < 7 || !value.endsWith("-->")) return false;
2017
+ const close = value.indexOf("-->", 4);
2018
+ const bangClose = value.indexOf("--!>", 4);
2019
+ if (close !== value.length - 3) return false;
2020
+ return bangClose === -1 || bangClose > close;
2021
+ }
2022
+ if (/^<!doctype/i.test(value)) return false;
2023
+ if (value.startsWith("<?") || /^<!(?:[A-Za-z]|\[CDATA\[)/.test(value)) {
2024
+ return value.indexOf(">") === value.length - 1;
2025
+ }
2026
+ return false;
1973
2027
  }
1974
2028
  function isSeparatorText(node) {
1975
2029
  return node.type === "text" && node.position === void 0 && node.value.trim() === "";
@@ -5135,7 +5189,6 @@ function createRemendPreprocessor(options) {
5135
5189
  collectDefLabels,
5136
5190
  computeFreezeBoundary,
5137
5191
  createDefLabelScanner,
5138
- createFile,
5139
5192
  createIncrementalLatexPreprocessor,
5140
5193
  createProcessor,
5141
5194
  createRegistry,
@@ -5152,10 +5205,8 @@ function createRemendPreprocessor(options) {
5152
5205
  hasLoneSurrogate,
5153
5206
  highlight,
5154
5207
  isFootnoteSection,
5155
- isWhitespaceText,
5156
5208
  lastMeaningfulIdx,
5157
5209
  measureStage,
5158
- mergeClassNameAllowlist,
5159
5210
  normalizeForMatch,
5160
5211
  normalizeId,
5161
5212
  pangu,
@@ -5171,7 +5222,6 @@ function createRemendPreprocessor(options) {
5171
5222
  shortenDocumentId,
5172
5223
  smartypants,
5173
5224
  sourceIdFromFootnoteLiId,
5174
- splitByProtectedRegions,
5175
5225
  subscribeStageTimings,
5176
5226
  transformStage,
5177
5227
  withDefs