@ai-matrx/rich-content 0.0.0 → 0.2.3
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/CHANGELOG.md +80 -0
- package/LICENSE +1 -1
- package/README.md +58 -3
- package/dist/display/blocks/csv/CsvBlock.d.ts +10 -0
- package/dist/display/blocks/csv/CsvBlock.js +245 -0
- package/dist/display/blocks/table/parseMarkdownTable.d.ts +20 -0
- package/dist/display/blocks/table/parseMarkdownTable.js +35 -0
- package/dist/display/chat-markdown/citations/remarkMatrxCite.d.ts +33 -0
- package/dist/display/chat-markdown/citations/remarkMatrxCite.js +71 -0
- package/dist/display/chat-markdown/matrx-variables/remarkMatrxVariable.d.ts +29 -0
- package/dist/display/chat-markdown/matrx-variables/remarkMatrxVariable.js +71 -0
- package/dist/display/chat-markdown/page-break/remarkMatrxPageBreak.d.ts +55 -0
- package/dist/display/chat-markdown/page-break/remarkMatrxPageBreak.js +108 -0
- package/dist/display/chat-markdown/rehypeSafeRawHtml.d.ts +59 -0
- package/dist/display/chat-markdown/rehypeSafeRawHtml.js +140 -0
- package/dist/display/markdown-classification/processors/bock-processors/parse-markdown-table.d.ts +14 -0
- package/dist/display/markdown-classification/processors/bock-processors/parse-markdown-table.js +171 -0
- package/dist/display/markdown-classification/processors/types.d.ts +120 -0
- package/dist/display/markdown-classification/processors/types.js +10 -0
- package/dist/display/markdown-classification/processors/utils/client-blocks.d.ts +169 -0
- package/dist/display/markdown-classification/processors/utils/client-blocks.js +0 -0
- package/dist/display/markdown-classification/processors/utils/content-splitter-core.d.ts +223 -0
- package/dist/display/markdown-classification/processors/utils/content-splitter-core.js +1791 -0
- package/dist/display/markdown-classification/processors/utils/content-splitter-v2.d.ts +15 -0
- package/dist/display/markdown-classification/processors/utils/content-splitter-v2.js +19 -0
- package/dist/display/markdown-classification/processors/utils/expand-text-blocks.d.ts +9 -0
- package/dist/display/markdown-classification/processors/utils/expand-text-blocks.js +36 -0
- package/dist/display/markdown-classification/processors/utils/gfm-table-lines.d.ts +5 -0
- package/dist/display/markdown-classification/processors/utils/gfm-table-lines.js +40 -0
- package/dist/display/markdown-classification/processors/utils/gfm-table-vector-inputs.d.ts +16 -0
- package/dist/display/markdown-classification/processors/utils/gfm-table-vector-inputs.js +385 -0
- package/dist/display/markdown-classification/processors/utils/gfm-table-vectors.d.ts +43 -0
- package/dist/display/markdown-classification/processors/utils/gfm-table-vectors.js +33 -0
- package/dist/display/markdown-classification/processors/utils/table-data-parser.d.ts +9 -0
- package/dist/display/markdown-classification/processors/utils/table-data-parser.js +30 -0
- package/dist/display/markdown-classification/processors/utils/thinking-parser.d.ts +7 -0
- package/dist/display/markdown-classification/processors/utils/thinking-parser.js +70 -0
- package/dist/display/render-block.d.ts +23 -0
- package/dist/display/render-block.js +0 -0
- package/dist/display/themes.d.ts +1023 -0
- package/dist/display/themes.js +1105 -0
- package/dist/display/types.d.ts +32 -0
- package/dist/display/types.js +0 -0
- package/dist/host/ContentIrHostBoundary.d.ts +8 -0
- package/dist/host/ContentIrHostBoundary.js +15 -0
- package/dist/host/ErrorActions.d.ts +4 -0
- package/dist/host/ErrorActions.js +11 -0
- package/dist/host/NestedContent.d.ts +3 -0
- package/dist/host/NestedContent.js +12 -0
- package/dist/host/ResourcePeek.d.ts +6 -0
- package/dist/host/ResourcePeek.js +14 -0
- package/dist/host/component-registry.d.ts +2 -0
- package/dist/host/component-registry.js +25 -0
- package/dist/host/diagnostics.d.ts +2 -0
- package/dist/host/diagnostics.js +15 -0
- package/dist/host/index.d.ts +3 -0
- package/dist/host/index.js +18 -0
- package/dist/host/kind-incident.d.ts +3 -0
- package/dist/host/kind-incident.js +12 -0
- package/dist/host/kind-registry.d.ts +2 -0
- package/dist/host/kind-registry.js +35 -0
- package/dist/host/people.d.ts +3 -0
- package/dist/host/people.js +12 -0
- package/dist/host/registry.d.ts +27 -0
- package/dist/host/registry.js +55 -0
- package/dist/host/splitter-envelopes.d.ts +2 -0
- package/dist/host/splitter-envelopes.js +7 -0
- package/dist/host/tables.d.ts +6 -0
- package/dist/host/tables.js +8 -0
- package/dist/host/toast.d.ts +2 -0
- package/dist/host/toast.js +57 -0
- package/dist/host/types.d.ts +157 -0
- package/dist/host/types.js +0 -0
- package/dist/host/wikilinks.d.ts +15 -0
- package/dist/host/wikilinks.js +23 -0
- package/dist/kinds/host/route-env.d.ts +33 -0
- package/dist/kinds/host/route-env.js +16 -0
- package/dist/kinds/react/KindEscapedNotice.d.ts +14 -0
- package/dist/kinds/react/KindEscapedNotice.js +72 -0
- package/dist/kinds/react/ProvisionalKindBoundary.d.ts +19 -0
- package/dist/kinds/react/ProvisionalKindBoundary.js +17 -0
- package/dist/kinds/react/ensure-kind-renderable.d.ts +14 -0
- package/dist/kinds/react/ensure-kind-renderable.js +45 -0
- package/dist/kinds/react/kind-problems.d.ts +62 -0
- package/dist/kinds/react/kind-problems.js +134 -0
- package/dist/kinds/react/kind-route.d.ts +23 -0
- package/dist/kinds/react/kind-route.js +24 -0
- package/dist/kinds/react/loading/infer-loading-slug.d.ts +58 -0
- package/dist/kinds/react/loading/infer-loading-slug.js +100 -0
- package/dist/kinds/react/loading/kind-loading-components.d.ts +48 -0
- package/dist/kinds/react/loading/kind-loading-components.js +447 -0
- package/dist/kinds/react/loading/kind-loading-registry.d.ts +21 -0
- package/dist/kinds/react/loading/kind-loading-registry.js +62 -0
- package/dist/kinds/react/loading/kind-loading-slugs.d.ts +18 -0
- package/dist/kinds/react/loading/kind-loading-slugs.js +34 -0
- package/dist/kinds/react/loading/kind-loading.types.d.ts +79 -0
- package/dist/kinds/react/loading/kind-loading.types.js +31 -0
- package/dist/kinds/react/loading/resolve-loading-slug.d.ts +29 -0
- package/dist/kinds/react/loading/resolve-loading-slug.js +51 -0
- package/dist/kinds/react/partial-kind-route.d.ts +32 -0
- package/dist/kinds/react/partial-kind-route.js +27 -0
- package/dist/kinds/react/registry-versioned.d.ts +54 -0
- package/dist/kinds/react/registry-versioned.js +18 -0
- package/dist/kinds/react/route-at-version.d.ts +38 -0
- package/dist/kinds/react/route-at-version.js +78 -0
- package/dist/kinds/react/slot/KindSlot.d.ts +87 -0
- package/dist/kinds/react/slot/KindSlot.js +65 -0
- package/dist/kinds/react/use-registry-repaint.d.ts +6 -0
- package/dist/kinds/react/use-registry-repaint.js +36 -0
- package/dist/kinds/react/useIrNode.d.ts +9 -0
- package/dist/kinds/react/useIrNode.js +46 -0
- package/dist/kinds/react/useLiveJsonRegion.d.ts +15 -0
- package/dist/kinds/react/useLiveJsonRegion.js +84 -0
- package/dist/kinds/redux/render-block-envelope.d.ts +14 -0
- package/dist/kinds/redux/render-block-envelope.js +26 -0
- package/dist/kinds/registry/kind-correctors.d.ts +63 -0
- package/dist/kinds/registry/kind-correctors.js +94 -0
- package/dist/kinds/registry/legacy-quiz-envelope.d.ts +1 -0
- package/dist/kinds/registry/legacy-quiz-envelope.js +1 -0
- package/dist/kinds/registry/region-envelope-memo.d.ts +45 -0
- package/dist/kinds/registry/region-envelope-memo.js +94 -0
- package/dist/kinds/registry/registry-debug.d.ts +38 -0
- package/dist/kinds/registry/registry-debug.js +39 -0
- package/dist/markdown-core/MarkdownCore.d.ts +6 -0
- package/dist/markdown-core/MarkdownCore.js +32 -0
- package/dist/markdown-core/MarkdownCoreImpl.d.ts +3 -0
- package/dist/markdown-core/MarkdownCoreImpl.js +27 -0
- package/dist/markdown-core/MarkdownCoreServer.d.ts +4 -0
- package/dist/markdown-core/MarkdownCoreServer.js +26 -0
- package/dist/markdown-core/heading-anchors-context.d.ts +2 -0
- package/dist/markdown-core/heading-anchors-context.js +11 -0
- package/dist/markdown-core/heading-anchors-props.d.ts +2 -0
- package/dist/markdown-core/heading-anchors-props.js +6 -0
- package/dist/markdown-core/markdown-core-html.d.ts +3 -0
- package/dist/markdown-core/markdown-core-html.js +33 -0
- package/dist/markdown-core/markdown-core-presets.d.ts +22 -0
- package/dist/markdown-core/markdown-core-presets.js +118 -0
- package/dist/markdown-core/markdown-core-types.d.ts +43 -0
- package/dist/markdown-core/markdown-core-types.js +0 -0
- package/dist/markdown-core/math/vendor/micromark-math-math-flow.d.ts +15 -0
- package/dist/markdown-core/math/vendor/micromark-math-math-flow.js +143 -0
- package/dist/markdown-core/math/vendor/micromark-math-math-text.d.ts +24 -0
- package/dist/markdown-core/math/vendor/micromark-math-math-text.js +127 -0
- package/dist/markdown-core/math/vendor/micromark-math-syntax.d.ts +30 -0
- package/dist/markdown-core/math/vendor/micromark-math-syntax.js +15 -0
- package/dist/markdown-core/math/vendor/rehype-katex.d.ts +15 -0
- package/dist/markdown-core/math/vendor/rehype-katex.js +83 -0
- package/dist/markdown-core/math/vendor/remark-math.d.ts +9 -0
- package/dist/markdown-core/math/vendor/remark-math.js +20 -0
- package/dist/markdown-core/math-normalizer.d.ts +57 -0
- package/dist/markdown-core/math-normalizer.js +315 -0
- package/dist/markdown-core/plain-title.d.ts +2 -0
- package/dist/markdown-core/plain-title.js +1 -0
- package/dist/markdown-core/stream-heal.d.ts +2 -0
- package/dist/markdown-core/stream-heal.js +184 -0
- package/dist/markdown-core/streaming-context.d.ts +2 -0
- package/dist/markdown-core/streaming-context.js +11 -0
- package/dist/markdown-core/syntax/callout-types.d.ts +9 -0
- package/dist/markdown-core/syntax/callout-types.js +101 -0
- package/dist/markdown-core/syntax/containers.d.ts +17 -0
- package/dist/markdown-core/syntax/containers.js +353 -0
- package/dist/markdown-core/syntax/document-numbering.d.ts +52 -0
- package/dist/markdown-core/syntax/document-numbering.js +184 -0
- package/dist/markdown-core/syntax/elements/CalloutIcon.d.ts +3 -0
- package/dist/markdown-core/syntax/elements/CalloutIcon.js +41 -0
- package/dist/markdown-core/syntax/elements/CrossRef.d.ts +12 -0
- package/dist/markdown-core/syntax/elements/CrossRef.js +57 -0
- package/dist/markdown-core/syntax/elements/CsvFence.d.ts +4 -0
- package/dist/markdown-core/syntax/elements/CsvFence.js +18 -0
- package/dist/markdown-core/syntax/elements/DetailsElements.d.ts +12 -0
- package/dist/markdown-core/syntax/elements/DetailsElements.js +38 -0
- package/dist/markdown-core/syntax/elements/DocumentNumbering.d.ts +20 -0
- package/dist/markdown-core/syntax/elements/DocumentNumbering.js +37 -0
- package/dist/markdown-core/syntax/elements/DocumentPropertiesPanel.d.ts +4 -0
- package/dist/markdown-core/syntax/elements/DocumentPropertiesPanel.js +46 -0
- package/dist/markdown-core/syntax/elements/InDocAnchor.d.ts +11 -0
- package/dist/markdown-core/syntax/elements/InDocAnchor.js +87 -0
- package/dist/markdown-core/syntax/elements/MarkdownSourceEdit.d.ts +24 -0
- package/dist/markdown-core/syntax/elements/MarkdownSourceEdit.js +28 -0
- package/dist/markdown-core/syntax/elements/MatrxTabs.d.ts +10 -0
- package/dist/markdown-core/syntax/elements/MatrxTabs.js +59 -0
- package/dist/markdown-core/syntax/elements/MentionChip.d.ts +7 -0
- package/dist/markdown-core/syntax/elements/MentionChip.js +69 -0
- package/dist/markdown-core/syntax/elements/NestedBody.d.ts +3 -0
- package/dist/markdown-core/syntax/elements/NestedBody.js +13 -0
- package/dist/markdown-core/syntax/elements/TableOfContents.d.ts +5 -0
- package/dist/markdown-core/syntax/elements/TableOfContents.js +44 -0
- package/dist/markdown-core/syntax/elements/TaskCheckbox.d.ts +7 -0
- package/dist/markdown-core/syntax/elements/TaskCheckbox.js +63 -0
- package/dist/markdown-core/syntax/elements/WikiEmbed.d.ts +7 -0
- package/dist/markdown-core/syntax/elements/WikiEmbed.js +68 -0
- package/dist/markdown-core/syntax/elements/WikiLink.d.ts +10 -0
- package/dist/markdown-core/syntax/elements/WikiLink.js +114 -0
- package/dist/markdown-core/syntax/elements/core-syntax-elements.d.ts +22 -0
- package/dist/markdown-core/syntax/elements/core-syntax-elements.js +70 -0
- package/dist/markdown-core/syntax/elements/find-in-document.d.ts +3 -0
- package/dist/markdown-core/syntax/elements/find-in-document.js +20 -0
- package/dist/markdown-core/syntax/elements/wiki-target.d.ts +5 -0
- package/dist/markdown-core/syntax/elements/wiki-target.js +8 -0
- package/dist/markdown-core/syntax/frontmatter.d.ts +26 -0
- package/dist/markdown-core/syntax/frontmatter.js +72 -0
- package/dist/markdown-core/syntax/gfm-cell-pipes.d.ts +11 -0
- package/dist/markdown-core/syntax/gfm-cell-pipes.js +4 -0
- package/dist/markdown-core/syntax/inline-syntax.d.ts +26 -0
- package/dist/markdown-core/syntax/inline-syntax.js +163 -0
- package/dist/markdown-core/syntax/linear-scan.d.ts +46 -0
- package/dist/markdown-core/syntax/linear-scan.js +129 -0
- package/dist/markdown-core/syntax/mdast-helpers.d.ts +48 -0
- package/dist/markdown-core/syntax/mdast-helpers.js +48 -0
- package/dist/markdown-core/syntax/mentions.d.ts +2 -0
- package/dist/markdown-core/syntax/mentions.js +42 -0
- package/dist/markdown-core/syntax/names.d.ts +6 -0
- package/dist/markdown-core/syntax/names.js +18 -0
- package/dist/markdown-core/syntax/prepare-syntax-source.d.ts +1 -0
- package/dist/markdown-core/syntax/prepare-syntax-source.js +78 -0
- package/dist/markdown-core/syntax/rehype-matrx-syntax.d.ts +9 -0
- package/dist/markdown-core/syntax/rehype-matrx-syntax.js +180 -0
- package/dist/markdown-core/syntax/remark-inline-only.d.ts +23 -0
- package/dist/markdown-core/syntax/remark-inline-only.js +25 -0
- package/dist/markdown-core/syntax/remark-matrx-syntax.d.ts +7 -0
- package/dist/markdown-core/syntax/remark-matrx-syntax.js +351 -0
- package/dist/markdown-core/syntax/remark-table-code-pipes.d.ts +7 -0
- package/dist/markdown-core/syntax/remark-table-code-pipes.js +23 -0
- package/dist/markdown-core/syntax/stream-heal-syntax.d.ts +2 -0
- package/dist/markdown-core/syntax/stream-heal-syntax.js +108 -0
- package/dist/markdown-core/syntax/task-source.d.ts +10 -0
- package/dist/markdown-core/syntax/task-source.js +34 -0
- package/dist/markdown-core/syntax/useDocumentProperties.d.ts +3 -0
- package/dist/markdown-core/syntax/useDocumentProperties.js +8 -0
- package/dist/math-vendor-LICENSE-NOTICE.md +18 -0
- package/dist/styles.css +0 -0
- package/dist/utils/addressWithoutNavigating.d.ts +68 -0
- package/dist/utils/addressWithoutNavigating.js +60 -0
- package/dist/utils/client-lazy.d.ts +13 -0
- package/dist/utils/client-lazy.js +24 -0
- package/dist/utils/decision-options.d.ts +21 -0
- package/dist/utils/decision-options.js +32 -0
- package/dist/utils/gfm-lexer.d.ts +5 -0
- package/dist/utils/gfm-lexer.js +10 -0
- package/dist/utils/json.d.ts +63 -0
- package/dist/utils/json.js +22 -0
- package/dist/utils/plain-title.d.ts +25 -0
- package/dist/utils/plain-title.js +51 -0
- package/dist/utils/table-source.d.ts +62 -0
- package/dist/utils/table-source.js +191 -0
- package/dist/utils/youtube.d.ts +52 -0
- package/dist/utils/youtube.js +137 -0
- package/package.json +132 -5
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content Splitter V2 — the CLIENT entry of the production block splitter.
|
|
3
|
+
*
|
|
4
|
+
* The splitter itself lives in content-splitter-core.ts (environment-neutral). This entry binds
|
|
5
|
+
* the HOST's kind-envelope hooks (`configureRichContent({ splitterEnvelopes })`; matrx-frontend
|
|
6
|
+
* binds its kind registry), so complete JSON / fence / XML regions carry the canonical
|
|
7
|
+
* content-IR envelope on `metadata.__ir`. A bare host splits with NO_SPLITTER_ENVELOPES: the
|
|
8
|
+
* same blocks, no envelope metadata. The server rich-content level imports the core directly.
|
|
9
|
+
*/
|
|
10
|
+
import { type SplitterBlock, type SplitterEnvelopes } from "./content-splitter-core.js";
|
|
11
|
+
export * from "./content-splitter-core.js";
|
|
12
|
+
/** The envelope hooks every client split uses: the host's, else none. */
|
|
13
|
+
export declare function clientSplitterEnvelopes(): SplitterEnvelopes;
|
|
14
|
+
export declare const splitContentIntoBlocksV2: (mdContent: string) => SplitterBlock[];
|
|
15
|
+
export declare function recoverEmbeddedKindJsonBlocks(input: SplitterBlock[]): SplitterBlock[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { hostSplitterEnvelopes } from "../../../../host/splitter-envelopes.js";
|
|
2
|
+
import {
|
|
3
|
+
NO_SPLITTER_ENVELOPES,
|
|
4
|
+
recoverEmbeddedKindJsonBlocksWith,
|
|
5
|
+
splitContentIntoBlocksWith
|
|
6
|
+
} from "./content-splitter-core.js";
|
|
7
|
+
export * from "./content-splitter-core.js";
|
|
8
|
+
function clientSplitterEnvelopes() {
|
|
9
|
+
return hostSplitterEnvelopes() ?? NO_SPLITTER_ENVELOPES;
|
|
10
|
+
}
|
|
11
|
+
const splitContentIntoBlocksV2 = (mdContent) => splitContentIntoBlocksWith(mdContent, clientSplitterEnvelopes());
|
|
12
|
+
function recoverEmbeddedKindJsonBlocks(input) {
|
|
13
|
+
return recoverEmbeddedKindJsonBlocksWith(input, clientSplitterEnvelopes());
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
clientSplitterEnvelopes,
|
|
17
|
+
recoverEmbeddedKindJsonBlocks,
|
|
18
|
+
splitContentIntoBlocksV2
|
|
19
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RenderBlock } from "../../../render-block.js";
|
|
2
|
+
/**
|
|
3
|
+
* Re-run the V2 splitter on `text` blocks so embedded tables, code fences,
|
|
4
|
+
* etc. promote to typed blocks. The unified-slots streaming path already does
|
|
5
|
+
* this for `render_block` rows with type "text"; the processedBlocks /
|
|
6
|
+
* hasClientBlocks fast path did not — which left tables as plain GFM markdown
|
|
7
|
+
* inside BasicMarkdownContent instead of StreamingTableRenderer.
|
|
8
|
+
*/
|
|
9
|
+
export declare function expandTextBlocksInList(blocks: RenderBlock[]): RenderBlock[];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { splitContentIntoBlocksV2 } from "./content-splitter-v2.js";
|
|
2
|
+
function expandTextBlocksInList(blocks) {
|
|
3
|
+
const out = [];
|
|
4
|
+
for (const block of blocks) {
|
|
5
|
+
if (block.type === "text" && block.content?.trim()) {
|
|
6
|
+
try {
|
|
7
|
+
const sub = splitContentIntoBlocksV2(block.content);
|
|
8
|
+
const shouldExpand = sub.length > 1 || sub.length === 1 && sub[0].type !== "text";
|
|
9
|
+
if (shouldExpand) {
|
|
10
|
+
let lastReasoningIdx = -1;
|
|
11
|
+
for (let j = sub.length - 1; j >= 0; j--) {
|
|
12
|
+
if (sub[j].type === "reasoning" || sub[j].type === "thinking") {
|
|
13
|
+
lastReasoningIdx = j;
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
sub.forEach((piece, j) => {
|
|
18
|
+
const isReasoningPiece = piece.type === "reasoning" || piece.type === "thinking";
|
|
19
|
+
out.push({
|
|
20
|
+
...piece,
|
|
21
|
+
content: piece.content ?? "",
|
|
22
|
+
isStreamingBlock: isReasoningPiece && j !== lastReasoningIdx ? false : block.isStreamingBlock
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
} catch {
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
out.push(block);
|
|
31
|
+
}
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
expandTextBlocksInList
|
|
36
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE GFM table rule and its streaming line helpers live in `@ai-matrx/content-ir/source`
|
|
3
|
+
* (chat-package-move P14); kept for its many app importers.
|
|
4
|
+
*/
|
|
5
|
+
export { continuesTable, findTableEnd, findTableStart, isGfmDelimiterRow, isPipeLedRow, lineIndent, opensTable, rowCells, splitRowSegments, startsHtmlBlock, startsPipelessTable, tableContainerIndent, tableStartsAt, unescapeCellPipes, findWholeTableStart, startsLikeTableRow, isGrowingDelimiterRow, trailingTableStart, } from "@ai-matrx/content-ir/source";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
continuesTable,
|
|
3
|
+
findTableEnd,
|
|
4
|
+
findTableStart,
|
|
5
|
+
isGfmDelimiterRow,
|
|
6
|
+
isPipeLedRow,
|
|
7
|
+
lineIndent,
|
|
8
|
+
opensTable,
|
|
9
|
+
rowCells,
|
|
10
|
+
splitRowSegments,
|
|
11
|
+
startsHtmlBlock,
|
|
12
|
+
startsPipelessTable,
|
|
13
|
+
tableContainerIndent,
|
|
14
|
+
tableStartsAt,
|
|
15
|
+
unescapeCellPipes,
|
|
16
|
+
findWholeTableStart,
|
|
17
|
+
startsLikeTableRow,
|
|
18
|
+
isGrowingDelimiterRow,
|
|
19
|
+
trailingTableStart
|
|
20
|
+
} from "@ai-matrx/content-ir/source";
|
|
21
|
+
export {
|
|
22
|
+
continuesTable,
|
|
23
|
+
findTableEnd,
|
|
24
|
+
findTableStart,
|
|
25
|
+
findWholeTableStart,
|
|
26
|
+
isGfmDelimiterRow,
|
|
27
|
+
isGrowingDelimiterRow,
|
|
28
|
+
isPipeLedRow,
|
|
29
|
+
lineIndent,
|
|
30
|
+
opensTable,
|
|
31
|
+
rowCells,
|
|
32
|
+
splitRowSegments,
|
|
33
|
+
startsHtmlBlock,
|
|
34
|
+
startsLikeTableRow,
|
|
35
|
+
startsPipelessTable,
|
|
36
|
+
tableContainerIndent,
|
|
37
|
+
tableStartsAt,
|
|
38
|
+
trailingTableStart,
|
|
39
|
+
unescapeCellPipes
|
|
40
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const DOCUMENT_INPUTS: ReadonlyArray<{
|
|
2
|
+
name: string;
|
|
3
|
+
text: string;
|
|
4
|
+
}>;
|
|
5
|
+
/** Tag names: which CommonMark reads as an HTML BLOCK (content-ir isHtmlBlockTagName). */
|
|
6
|
+
export declare const HTML_TAG_NAME_INPUTS: readonly string[];
|
|
7
|
+
export declare const ROW_INPUTS: readonly string[];
|
|
8
|
+
export declare const CELL_INPUTS: readonly string[];
|
|
9
|
+
export declare const TABLE_INPUTS: readonly string[];
|
|
10
|
+
export declare const TABLE_END_INPUTS: ReadonlyArray<{
|
|
11
|
+
lines: string[];
|
|
12
|
+
start: number;
|
|
13
|
+
}>;
|
|
14
|
+
export declare const TABLE_START_INPUTS: ReadonlyArray<string[]>;
|
|
15
|
+
/** Where a table can open at the FIRST line (header + delimiter as GFM pairs them). */
|
|
16
|
+
export declare const TABLE_OPEN_INPUTS: ReadonlyArray<string[]>;
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
const INTRO = "Here is tonight's handover for the Harbor warehouse.";
|
|
2
|
+
const OUTRO = "Omar signs off once bay B3 is re-scanned.";
|
|
3
|
+
const THREE = "Step | Task | Who\n--- | --- | ---\n1 | Drain the print queue | Tom\n2 | Swap the label printer | Ines";
|
|
4
|
+
const TWO = "Bay | Status\n:--- | ---:\nB3 | re-scan\nB4 | clear";
|
|
5
|
+
const ESCAPED = "Rule | Pattern\n--- | ---\nalerts | `err\\|warn`";
|
|
6
|
+
const PIPED = "| Rule | Pattern |\n| --- | --- |\n| alerts | `err\\|warn` |\n| audit | a \\| b |";
|
|
7
|
+
const DOCUMENT_INPUTS = [
|
|
8
|
+
{ name: "pipe-less, three columns", text: `${INTRO}
|
|
9
|
+
|
|
10
|
+
${THREE}
|
|
11
|
+
|
|
12
|
+
${OUTRO}` },
|
|
13
|
+
{ name: "pipe-less, two columns, aligned", text: `${INTRO}
|
|
14
|
+
|
|
15
|
+
${TWO}
|
|
16
|
+
|
|
17
|
+
${OUTRO}` },
|
|
18
|
+
{ name: "pipe-less, escaped pipe in code", text: `${INTRO}
|
|
19
|
+
|
|
20
|
+
${ESCAPED}
|
|
21
|
+
|
|
22
|
+
${OUTRO}` },
|
|
23
|
+
{ name: "pipe-less, right after a prose line", text: `${INTRO}
|
|
24
|
+
${THREE}
|
|
25
|
+
|
|
26
|
+
${OUTRO}` },
|
|
27
|
+
{ name: "pipe-less, table opens the message", text: `${TWO}
|
|
28
|
+
|
|
29
|
+
${OUTRO}` },
|
|
30
|
+
{ name: "pipe-led table (unchanged rule)", text: `${INTRO}
|
|
31
|
+
|
|
32
|
+
${PIPED}
|
|
33
|
+
|
|
34
|
+
${OUTRO}` },
|
|
35
|
+
{
|
|
36
|
+
name: "a list item ends a pipe-less table (verify-RC-B4 R5-1 shape)",
|
|
37
|
+
text: `${INTRO}
|
|
38
|
+
|
|
39
|
+
Step | Task | Who
|
|
40
|
+
--- | --- | ---
|
|
41
|
+
1 | Drain the print queue | Tom
|
|
42
|
+
- | Re-scan bay B3 | Omar
|
|
43
|
+
|
|
44
|
+
${OUTRO}`
|
|
45
|
+
},
|
|
46
|
+
{ name: "prose with a pipe and no delimiter row", text: `${INTRO}
|
|
47
|
+
Use a | b for either.
|
|
48
|
+
|
|
49
|
+
${OUTRO}` },
|
|
50
|
+
{ name: "header wider than its delimiter row", text: `${INTRO}
|
|
51
|
+
|
|
52
|
+
Bay | Status | Crew
|
|
53
|
+
--- | ---
|
|
54
|
+
B3 | re-scan | Omar
|
|
55
|
+
|
|
56
|
+
${OUTRO}` },
|
|
57
|
+
{ name: "list item with a pipe over a rule", text: `${INTRO}
|
|
58
|
+
|
|
59
|
+
- keep a | b
|
|
60
|
+
--- | ---
|
|
61
|
+
|
|
62
|
+
${OUTRO}` },
|
|
63
|
+
{ name: "a 'delimiter' with no dashes is not a table", text: `${INTRO}
|
|
64
|
+
|
|
65
|
+
| Bay | Status |
|
|
66
|
+
| | |
|
|
67
|
+
| B3 | re-scan |
|
|
68
|
+
|
|
69
|
+
${OUTRO}` },
|
|
70
|
+
{ name: "a pipe-less row continues a pipe-led table", text: `${INTRO}
|
|
71
|
+
|
|
72
|
+
| Bay | Status |
|
|
73
|
+
| --- | --- |
|
|
74
|
+
B3 | re-scan
|
|
75
|
+
|
|
76
|
+
${OUTRO}` },
|
|
77
|
+
// GFM spec example 202 (verify-RC-B4 R7-2): a line without a pipe is a row; a quote line ends the table.
|
|
78
|
+
{ name: "a line without a pipe continues the table (GFM 202)", text: `${INTRO}
|
|
79
|
+
|
|
80
|
+
| Bay | Status |
|
|
81
|
+
| --- | --- |
|
|
82
|
+
| B3 | re-scan |
|
|
83
|
+
B4 clear
|
|
84
|
+
|
|
85
|
+
${OUTRO}` },
|
|
86
|
+
{ name: "a quote line ends a pipe-less table", text: `${INTRO}
|
|
87
|
+
|
|
88
|
+
Zone | Temp
|
|
89
|
+
--- | ---
|
|
90
|
+
A | 4C
|
|
91
|
+
> 8C | alarm
|
|
92
|
+
|
|
93
|
+
${OUTRO}` },
|
|
94
|
+
// verify-RC-B4 round 8: a backtick run whose info string holds a backtick is a code span, not a fence (CommonMark 4.5).
|
|
95
|
+
{ name: "a four-backtick code span row continues the table", text: `${INTRO}
|
|
96
|
+
|
|
97
|
+
Step | Task
|
|
98
|
+
--- | ---
|
|
99
|
+
1 | Drain the queue
|
|
100
|
+
${"````"} code ${"````"} | b
|
|
101
|
+
|
|
102
|
+
${OUTRO}` },
|
|
103
|
+
// verify-RC-B4 round 9: an HTML block start (CommonMark 4.6, conditions 2, 6, 7) and indented code end a table.
|
|
104
|
+
{ name: "an HTML comment ends the table", text: `${INTRO}
|
|
105
|
+
|
|
106
|
+
| Bay | Status |
|
|
107
|
+
| --- | --- |
|
|
108
|
+
| B3 | re-scan |
|
|
109
|
+
<!-- shift note -->
|
|
110
|
+
|
|
111
|
+
${OUTRO}` },
|
|
112
|
+
{ name: "a block tag ends the table", text: `${INTRO}
|
|
113
|
+
|
|
114
|
+
| Bay | Status |
|
|
115
|
+
| --- | --- |
|
|
116
|
+
| B3 | re-scan |
|
|
117
|
+
</details>
|
|
118
|
+
|
|
119
|
+
${OUTRO}` },
|
|
120
|
+
{ name: "a closing tag alone on its line ends the table", text: `${INTRO}
|
|
121
|
+
|
|
122
|
+
| Bay | Status |
|
|
123
|
+
| --- | --- |
|
|
124
|
+
| B3 | re-scan |
|
|
125
|
+
</artifact>
|
|
126
|
+
|
|
127
|
+
${OUTRO}` },
|
|
128
|
+
{ name: "a tag with text after it is a row", text: `${INTRO}
|
|
129
|
+
|
|
130
|
+
| Bay | Status |
|
|
131
|
+
| --- | --- |
|
|
132
|
+
| B3 | re-scan |
|
|
133
|
+
<span>B4</span> clear
|
|
134
|
+
|
|
135
|
+
${OUTRO}` },
|
|
136
|
+
{ name: "an indented line ends the table", text: `${INTRO}
|
|
137
|
+
|
|
138
|
+
| Bay | Status |
|
|
139
|
+
| --- | --- |
|
|
140
|
+
| B3 | re-scan |
|
|
141
|
+
B4 clear
|
|
142
|
+
|
|
143
|
+
${OUTRO}` },
|
|
144
|
+
{ name: "a pipe-led header wider than its delimiter is no table", text: `${INTRO}
|
|
145
|
+
|
|
146
|
+
| Bay | Status |
|
|
147
|
+
|---|
|
|
148
|
+
| B3 | re-scan |
|
|
149
|
+
|
|
150
|
+
${OUTRO}` },
|
|
151
|
+
{ name: "a header with no pipe over |---| is a one-column table", text: `${INTRO}
|
|
152
|
+
|
|
153
|
+
Notes
|
|
154
|
+
|---|
|
|
155
|
+
Dock B closed
|
|
156
|
+
|
|
157
|
+
${OUTRO}` },
|
|
158
|
+
{ name: "a table under a list item's text is that item's text", text: `${INTRO}
|
|
159
|
+
|
|
160
|
+
- Dock B is closed tonight
|
|
161
|
+
| Bay | Status |
|
|
162
|
+
| --- | --- |
|
|
163
|
+
| B3 | re-scan |
|
|
164
|
+
|
|
165
|
+
${OUTRO}` },
|
|
166
|
+
// verify-RC-B4 round 9: an HTML block tag is HTML (GFM), never a custom XML container;
|
|
167
|
+
// an ASCII tree needs dash connectors; a custom XML container keeps its block.
|
|
168
|
+
{ name: "an unclosed <div> line ends at the blank line", text: `${INTRO}
|
|
169
|
+
|
|
170
|
+
<div>
|
|
171
|
+
|
|
172
|
+
${OUTRO}` },
|
|
173
|
+
{ name: "a closed <section> container is one block", text: `${INTRO}
|
|
174
|
+
|
|
175
|
+
<section>
|
|
176
|
+
Bay B3 re-scan.
|
|
177
|
+
</section>
|
|
178
|
+
|
|
179
|
+
${OUTRO}` },
|
|
180
|
+
{ name: "an ASCII tree with dash connectors is a tree", text: `${INTRO}
|
|
181
|
+
|
|
182
|
+
harbor
|
|
183
|
+
|-- docks
|
|
184
|
+
| |-- B3
|
|
185
|
+
| +-- B4
|
|
186
|
+
+-- yard
|
|
187
|
+
|
|
188
|
+
${OUTRO}` },
|
|
189
|
+
{ name: "a footnote definition under a row ends the table", text: `${INTRO}
|
|
190
|
+
|
|
191
|
+
| Bay | Count |
|
|
192
|
+
| --- | --- |
|
|
193
|
+
| A1 | 12 |
|
|
194
|
+
[^1]: counted Monday
|
|
195
|
+
| A2 | 9 |
|
|
196
|
+
|
|
197
|
+
${OUTRO}` },
|
|
198
|
+
{ name: "a custom XML container keeps its block", text: `${INTRO}
|
|
199
|
+
|
|
200
|
+
<shift_note>
|
|
201
|
+
Bay B3 re-scan.
|
|
202
|
+
</shift_note>
|
|
203
|
+
|
|
204
|
+
${OUTRO}` }
|
|
205
|
+
];
|
|
206
|
+
const HTML_TAG_NAME_INPUTS = [
|
|
207
|
+
"div",
|
|
208
|
+
"DIV",
|
|
209
|
+
"section",
|
|
210
|
+
"details",
|
|
211
|
+
"dl",
|
|
212
|
+
"dt",
|
|
213
|
+
"dd",
|
|
214
|
+
"h3",
|
|
215
|
+
"script",
|
|
216
|
+
"textarea",
|
|
217
|
+
"search",
|
|
218
|
+
"span",
|
|
219
|
+
"artifact",
|
|
220
|
+
"widget",
|
|
221
|
+
"thinking",
|
|
222
|
+
"shift_note",
|
|
223
|
+
"h7",
|
|
224
|
+
"divx"
|
|
225
|
+
];
|
|
226
|
+
const ROW_INPUTS = [
|
|
227
|
+
"a | b",
|
|
228
|
+
"| a | b |",
|
|
229
|
+
"| a \\| b | c |",
|
|
230
|
+
"| `x\\|y` | z |",
|
|
231
|
+
"a \\\\| b",
|
|
232
|
+
"a \\\\\\| b | c",
|
|
233
|
+
"|x|",
|
|
234
|
+
"| a | b",
|
|
235
|
+
"--- | :-: | --:",
|
|
236
|
+
"",
|
|
237
|
+
"|",
|
|
238
|
+
"| | |"
|
|
239
|
+
];
|
|
240
|
+
const CELL_INPUTS = [
|
|
241
|
+
"`err\\|warn`",
|
|
242
|
+
"a \\| b",
|
|
243
|
+
"plain",
|
|
244
|
+
"\\\\\\|",
|
|
245
|
+
"`a \\| b` and err\\|warn"
|
|
246
|
+
];
|
|
247
|
+
const TABLE_INPUTS = [
|
|
248
|
+
THREE,
|
|
249
|
+
TWO,
|
|
250
|
+
ESCAPED,
|
|
251
|
+
PIPED,
|
|
252
|
+
"Bay | Status\n--- | ---\n | \nB4 | clear",
|
|
253
|
+
"| Bay | Status |\n| | |\n| B3 | re-scan |",
|
|
254
|
+
// verify-RC-B4 round 9: a trailing lone `|` is an empty row GFM shows, not dropped.
|
|
255
|
+
"| Bay | Status |\n| --- | --- |\n| B3 | re-scan |\n |"
|
|
256
|
+
];
|
|
257
|
+
const HANDOVER = ["| Bay | Status |", "| --- | --- |", "| B3 | re-scan |"];
|
|
258
|
+
const after = (line) => ({ lines: [...HANDOVER, line, "Omar signs off."], start: 0 });
|
|
259
|
+
const TABLE_END_INPUTS = [
|
|
260
|
+
after("<script>"),
|
|
261
|
+
// 1
|
|
262
|
+
after("<PRE"),
|
|
263
|
+
// 1, end of line
|
|
264
|
+
after("<textarea>notes"),
|
|
265
|
+
// 1, text after
|
|
266
|
+
after("<!-- shift note -->"),
|
|
267
|
+
// 2
|
|
268
|
+
after("<?php echo 1 ?>"),
|
|
269
|
+
// 3
|
|
270
|
+
after("<!DOCTYPE html>"),
|
|
271
|
+
// 4
|
|
272
|
+
after("<!-x | b"),
|
|
273
|
+
// not 4: no letter after <!
|
|
274
|
+
after("<![CDATA[ raw ]]>"),
|
|
275
|
+
// 5
|
|
276
|
+
after("<![CDATA | b"),
|
|
277
|
+
// not 5
|
|
278
|
+
after("<div>"),
|
|
279
|
+
// 6
|
|
280
|
+
after("</details>"),
|
|
281
|
+
// 6
|
|
282
|
+
after("<div>moved to B4"),
|
|
283
|
+
// 6, text after
|
|
284
|
+
after(" <section>"),
|
|
285
|
+
// 6, 3 spaces
|
|
286
|
+
after("</artifact>"),
|
|
287
|
+
// 7
|
|
288
|
+
after('<artifact id="1">'),
|
|
289
|
+
// 7
|
|
290
|
+
after("<br />"),
|
|
291
|
+
// 7
|
|
292
|
+
after("<a :b>"),
|
|
293
|
+
// 7
|
|
294
|
+
after("<span>B4</span> clear"),
|
|
295
|
+
// not 7: text after the tag
|
|
296
|
+
after("<a b=>"),
|
|
297
|
+
// not 7: no attribute value
|
|
298
|
+
after("<x:y>"),
|
|
299
|
+
// not 7: a colon in the name
|
|
300
|
+
after(" | B4 | clear |"),
|
|
301
|
+
// indented code
|
|
302
|
+
after(" | B4 | clear |"),
|
|
303
|
+
// a tab
|
|
304
|
+
after(" B4"),
|
|
305
|
+
// a space then a tab
|
|
306
|
+
after(" | B4 | clear |"),
|
|
307
|
+
// 3 spaces: a row
|
|
308
|
+
after("|"),
|
|
309
|
+
// a lone pipe: an empty row
|
|
310
|
+
after("[^1]: counted Monday"),
|
|
311
|
+
// a footnote definition ends the table (R9-1)
|
|
312
|
+
after("[1]: https://harbor.example/bays"),
|
|
313
|
+
// a link reference definition is a row
|
|
314
|
+
{ lines: ["- item", "", " | a | b |", " |---|---|", " | 1 | 2 |", " | 3 | 4 |"], start: 2 },
|
|
315
|
+
{ lines: ["- item", "", " | a | b |", " |---|---|", " | 1 | 2 |", " | 3 | 4 |"], start: 2 },
|
|
316
|
+
{ lines: ["- item", " | a | b |", " |---|---|", " | 1 | 2 |", " | 3 | 4 |"], start: 1 },
|
|
317
|
+
{ lines: ["1. item", " - sub", "", " | a | b |", " |---|---|", " | 1 | 2 |", " | 3 | 4 |"], start: 3 },
|
|
318
|
+
{ lines: [" | a | b |", " |---|---|", " | 1 | 2 |", " | 3 | 4 |"], start: 0 }
|
|
319
|
+
];
|
|
320
|
+
const ROWS = ["| Bay | Status |", "|---|---|", "| B3 | re-scan |"];
|
|
321
|
+
const under = (...above) => [...above, ...ROWS];
|
|
322
|
+
const nested = (by, ...above) => [...above, ...ROWS.map((row) => by + row)];
|
|
323
|
+
const TABLE_START_INPUTS = [
|
|
324
|
+
under("- Dock B is closed tonight"),
|
|
325
|
+
under("- Dock B is closed tonight", ""),
|
|
326
|
+
under("- Dock B is closed tonight", " and reopens at six"),
|
|
327
|
+
nested(" ", "- Dock B is closed tonight"),
|
|
328
|
+
under("1. Drain the print queue"),
|
|
329
|
+
nested(" ", "1. Drain the print queue"),
|
|
330
|
+
nested(" ", "1. Drain the print queue"),
|
|
331
|
+
under("> Omar signs off"),
|
|
332
|
+
under("> Omar signs off", ""),
|
|
333
|
+
under("- Dock B is closed tonight", "# Bays"),
|
|
334
|
+
under("- Dock B is closed tonight", "---"),
|
|
335
|
+
under("- Docks", " - B is closed"),
|
|
336
|
+
under("Tonight's bays:"),
|
|
337
|
+
under("- Dock B", "", " closed until six"),
|
|
338
|
+
under("-"),
|
|
339
|
+
// verify-RC-B4 round 9 (R9-5): a table never opens inside an HTML block.
|
|
340
|
+
under("<details>"),
|
|
341
|
+
under("<div>"),
|
|
342
|
+
under("<span>"),
|
|
343
|
+
under("text <b>B3</b> first"),
|
|
344
|
+
under("<!-- shift note -->"),
|
|
345
|
+
under("<script>x<\/script>"),
|
|
346
|
+
under("<details>", ""),
|
|
347
|
+
under("Tonight's bays:", "<span>"),
|
|
348
|
+
under("<div>", "hello"),
|
|
349
|
+
under("</div>"),
|
|
350
|
+
under("<!DOCTYPE html>"),
|
|
351
|
+
// verify-RC-B4 round 16 ruling — THE ONE DELIBERATE GFM DEVIATION: a block whose
|
|
352
|
+
// element every sanitizer strips ends at its own line (content-ir
|
|
353
|
+
// opensStrippedHtmlBlock), so a table right under it opens; GFM would keep it raw.
|
|
354
|
+
under('<link rel="canonical" href="https://harbor.example/bays" />'),
|
|
355
|
+
under("<nav>"),
|
|
356
|
+
under("<nav>", "Tonight's bays:"),
|
|
357
|
+
under("</header>")
|
|
358
|
+
];
|
|
359
|
+
const TABLE_OPEN_INPUTS = [
|
|
360
|
+
["Notes", "|---|", "Dock B closed"],
|
|
361
|
+
// no pipe in the header: a one-column table
|
|
362
|
+
["| Notes", "| -", "| Dock B closed"],
|
|
363
|
+
// one pipe
|
|
364
|
+
["| Bay | Status |", "|---|", "| B3 | re-scan |"],
|
|
365
|
+
// header wider than its delimiter
|
|
366
|
+
["| Bay |", "|---|---|", "| B3 |"],
|
|
367
|
+
// header narrower than its delimiter
|
|
368
|
+
["| Bay | Status |", "- | -", "| B3 | re-scan |"],
|
|
369
|
+
// a list item is no delimiter
|
|
370
|
+
["Bay | Status", "- | -", "B3 | re-scan"],
|
|
371
|
+
["Bay | Status", "-|-", "B3 | re-scan"],
|
|
372
|
+
// no space after the dash: a delimiter
|
|
373
|
+
[" | Bay | Status |", " |---|---|", " | B3 | re-scan |"]
|
|
374
|
+
// indented code
|
|
375
|
+
];
|
|
376
|
+
export {
|
|
377
|
+
CELL_INPUTS,
|
|
378
|
+
DOCUMENT_INPUTS,
|
|
379
|
+
HTML_TAG_NAME_INPUTS,
|
|
380
|
+
ROW_INPUTS,
|
|
381
|
+
TABLE_END_INPUTS,
|
|
382
|
+
TABLE_INPUTS,
|
|
383
|
+
TABLE_OPEN_INPUTS,
|
|
384
|
+
TABLE_START_INPUTS
|
|
385
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export interface GfmTableVectors {
|
|
2
|
+
rows: Array<{
|
|
3
|
+
line: string;
|
|
4
|
+
cells: string[];
|
|
5
|
+
}>;
|
|
6
|
+
cellPipes: Array<{
|
|
7
|
+
cell: string;
|
|
8
|
+
display: string;
|
|
9
|
+
}>;
|
|
10
|
+
tables: Array<{
|
|
11
|
+
table: string;
|
|
12
|
+
headers: string[];
|
|
13
|
+
rows: string[][];
|
|
14
|
+
} | {
|
|
15
|
+
table: string;
|
|
16
|
+
notATable: true;
|
|
17
|
+
}>;
|
|
18
|
+
documents: Array<{
|
|
19
|
+
name: string;
|
|
20
|
+
text: string;
|
|
21
|
+
blocks: Array<[string, string]>;
|
|
22
|
+
}>;
|
|
23
|
+
/** Where a table that opens at `start` ends (index just past its last row). */
|
|
24
|
+
tableEnds: Array<{
|
|
25
|
+
lines: string[];
|
|
26
|
+
start: number;
|
|
27
|
+
end: number;
|
|
28
|
+
}>;
|
|
29
|
+
/** Whether a table opens at the candidate header (the third line from the end). */
|
|
30
|
+
tableStarts: Array<{
|
|
31
|
+
lines: string[];
|
|
32
|
+
index: number;
|
|
33
|
+
opens: boolean;
|
|
34
|
+
}>;
|
|
35
|
+
/** Raw HTML tags the renderer keeps (rehypeSafeRawHtml) — the Python list must equal it. */
|
|
36
|
+
rawHtmlTags: string[];
|
|
37
|
+
/** Tag names CommonMark reads as an HTML block (content-ir isHtmlBlockTagName). */
|
|
38
|
+
htmlBlockTagNames: Array<{
|
|
39
|
+
name: string;
|
|
40
|
+
isBlock: boolean;
|
|
41
|
+
}>;
|
|
42
|
+
}
|
|
43
|
+
export declare function computeGfmTableVectors(): GfmTableVectors;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { rowCells } from "../../../../utils/table-source.js";
|
|
2
|
+
import { unescapeCellPipes } from "../../../../markdown-core/syntax/gfm-cell-pipes.js";
|
|
3
|
+
import { parseMarkdownTable } from "../../../blocks/table/parseMarkdownTable.js";
|
|
4
|
+
import { splitContentIntoBlocksV2 } from "./content-splitter-v2.js";
|
|
5
|
+
import { findTableEnd, tableStartsAt } from "./gfm-table-lines.js";
|
|
6
|
+
import { isHtmlBlockTagName } from "@ai-matrx/content-ir/source";
|
|
7
|
+
import { ALLOWED_RAW_HTML_TAGS } from "../../../chat-markdown/rehypeSafeRawHtml.js";
|
|
8
|
+
import { CELL_INPUTS, DOCUMENT_INPUTS, HTML_TAG_NAME_INPUTS, ROW_INPUTS, TABLE_END_INPUTS, TABLE_INPUTS, TABLE_OPEN_INPUTS, TABLE_START_INPUTS } from "./gfm-table-vector-inputs.js";
|
|
9
|
+
function computeGfmTableVectors() {
|
|
10
|
+
return {
|
|
11
|
+
rows: ROW_INPUTS.map((line) => ({ line, cells: rowCells(line) })),
|
|
12
|
+
cellPipes: CELL_INPUTS.map((cell) => ({ cell, display: unescapeCellPipes(cell) })),
|
|
13
|
+
tables: TABLE_INPUTS.map((table) => {
|
|
14
|
+
const parsed = parseMarkdownTable(table);
|
|
15
|
+
return parsed ? { table, headers: parsed.headers, rows: parsed.rows } : { table, notATable: true };
|
|
16
|
+
}),
|
|
17
|
+
documents: DOCUMENT_INPUTS.map(({ name, text }) => ({
|
|
18
|
+
name,
|
|
19
|
+
text,
|
|
20
|
+
blocks: splitContentIntoBlocksV2(text).filter((block) => block.content.trim()).map((block) => [block.type, block.content.trim()])
|
|
21
|
+
})),
|
|
22
|
+
tableEnds: TABLE_END_INPUTS.map(({ lines, start }) => ({ lines: [...lines], start, end: findTableEnd(lines, start) })),
|
|
23
|
+
tableStarts: [
|
|
24
|
+
...TABLE_START_INPUTS.map((lines) => ({ lines: [...lines], index: lines.length - 3, opens: tableStartsAt(lines, lines.length - 3) })),
|
|
25
|
+
...TABLE_OPEN_INPUTS.map((lines) => ({ lines: [...lines], index: 0, opens: tableStartsAt(lines, 0) }))
|
|
26
|
+
],
|
|
27
|
+
rawHtmlTags: [...ALLOWED_RAW_HTML_TAGS].sort(),
|
|
28
|
+
htmlBlockTagNames: HTML_TAG_NAME_INPUTS.map((name) => ({ name, isBlock: isHtmlBlockTagName(name) }))
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
computeGfmTableVectors
|
|
33
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { MarkdownTableData } from "../../../types.js";
|
|
2
|
+
type NormalizedTableData = Array<{
|
|
3
|
+
[key: string]: string;
|
|
4
|
+
}>;
|
|
5
|
+
export declare const parseMarkdownTable: (content: string) => {
|
|
6
|
+
markdown: MarkdownTableData | null;
|
|
7
|
+
data: NormalizedTableData | null;
|
|
8
|
+
};
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { parseMarkdownTable as parseCanonicalTable } from "../../../blocks/table/parseMarkdownTable.js";
|
|
2
|
+
import { findTableEnd, findWholeTableStart } from "./gfm-table-lines.js";
|
|
3
|
+
const parseMarkdownTable = (content) => {
|
|
4
|
+
try {
|
|
5
|
+
const lines = content.split("\n");
|
|
6
|
+
const tableStartIndex = findWholeTableStart(lines);
|
|
7
|
+
if (tableStartIndex === -1) return { markdown: null, data: null };
|
|
8
|
+
const tableLines = lines.slice(tableStartIndex, findTableEnd(lines, tableStartIndex));
|
|
9
|
+
if (tableLines.length < 3) return { markdown: null, data: null };
|
|
10
|
+
const parsed = parseCanonicalTable(tableLines.join("\n"));
|
|
11
|
+
if (!parsed || parsed.headers.length === 0 || parsed.rows.length === 0) return { markdown: null, data: null };
|
|
12
|
+
const { headers, rows } = parsed;
|
|
13
|
+
const normalizedData = rows.map((row) => {
|
|
14
|
+
const rowData = {};
|
|
15
|
+
headers.forEach((header, index) => {
|
|
16
|
+
rowData[header] = index < row.length ? row[index] : "";
|
|
17
|
+
});
|
|
18
|
+
return rowData;
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
markdown: { headers, rows },
|
|
22
|
+
data: normalizedData
|
|
23
|
+
};
|
|
24
|
+
} catch (error) {
|
|
25
|
+
return { markdown: null, data: null };
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
export {
|
|
29
|
+
parseMarkdownTable
|
|
30
|
+
};
|