@ai-matrx/rich-content 0.0.0-stage → 0.2.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/CHANGELOG.md +72 -0
- package/LICENSE +21 -0
- package/README.md +61 -2
- 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/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 +134 -4
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remark plugin: renders a markdown page-break directive as a visible
|
|
3
|
+
* "Page break" divider — the on-screen half of the print system's page break.
|
|
4
|
+
*
|
|
5
|
+
* The grammar is NOT defined here. It is `isBreakLine` (page OR section break) from
|
|
6
|
+
* `@ai-matrx/print/directives` — the same function the print converters use,
|
|
7
|
+
* so what previews as a page break is exactly what prints as one:
|
|
8
|
+
*
|
|
9
|
+
* <!-- pagebreak --> (canonical) \pagebreak \newpage
|
|
10
|
+
* <!-- newpage --> <div style="page-break-after: always"></div>
|
|
11
|
+
*
|
|
12
|
+
* Screen and paper must agree line for line, so the rules mirror the printer:
|
|
13
|
+
* - Only TOP-LEVEL lines are directives (the printer reads lines; a `> \newpage`
|
|
14
|
+
* or `- \newpage` is a quote/list item there, so it is one here too).
|
|
15
|
+
* - A directive is judged on its RAW source line (so an escaped `\\newpage`
|
|
16
|
+
* stays text, as it does on paper), for both shapes it can take in the AST:
|
|
17
|
+
* an `html` node (comment / `<div>` on its own line) or a `paragraph`
|
|
18
|
+
* (`\newpage`, or a `<div …>` the chat preprocessing escaped to entities).
|
|
19
|
+
* - `isolatePageBreakLines` runs on the SOURCE before parsing, so a directive
|
|
20
|
+
* written directly under a line of text becomes its own block instead of
|
|
21
|
+
* melting into that paragraph (the printer breaks there; so must we).
|
|
22
|
+
*
|
|
23
|
+
* Code spans and fences are never touched: they are `code` / `inlineCode`
|
|
24
|
+
* nodes, and the isolation pass skips fenced regions.
|
|
25
|
+
*
|
|
26
|
+
* The divider carries the `matrx-page-break` class (the print package's class)
|
|
27
|
+
* so a browser print of the page breaks there too — see the print rule at the
|
|
28
|
+
* end of `app/globals.css`.
|
|
29
|
+
*/
|
|
30
|
+
interface MdastNode {
|
|
31
|
+
type: string;
|
|
32
|
+
value?: string;
|
|
33
|
+
children?: MdastNode[];
|
|
34
|
+
data?: Record<string, unknown>;
|
|
35
|
+
position?: {
|
|
36
|
+
start: {
|
|
37
|
+
offset?: number;
|
|
38
|
+
};
|
|
39
|
+
end: {
|
|
40
|
+
offset?: number;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
[key: string]: unknown;
|
|
44
|
+
}
|
|
45
|
+
interface SourceFile {
|
|
46
|
+
value?: unknown;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Give every directive line its own block: blank lines around it, outside
|
|
50
|
+
* fenced code. Pure and idempotent; returns the input untouched when there is
|
|
51
|
+
* no directive (the common case costs one scan).
|
|
52
|
+
*/
|
|
53
|
+
export declare function isolatePageBreakLines(source: string): string;
|
|
54
|
+
export default function remarkMatrxPageBreak(): (tree: MdastNode, file?: SourceFile) => void;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PAGE_BREAK_CLASS,
|
|
3
|
+
PAGE_BREAK_LABEL,
|
|
4
|
+
isBreakLine
|
|
5
|
+
} from "@ai-matrx/print/directives";
|
|
6
|
+
import { fenceLineKinds } from "@ai-matrx/content-ir/source";
|
|
7
|
+
function isolatePageBreakLines(source) {
|
|
8
|
+
if (!source) return source;
|
|
9
|
+
const lines = source.split("\n");
|
|
10
|
+
const kinds = fenceLineKinds(source);
|
|
11
|
+
let changed = false;
|
|
12
|
+
const out = [];
|
|
13
|
+
for (const [i, line] of lines.entries()) {
|
|
14
|
+
if (kinds[i] === "prose" && isBreakLine(line)) {
|
|
15
|
+
if (out.length > 0 && (out[out.length - 1] ?? "").trim() !== "") out.push("");
|
|
16
|
+
out.push(line, "");
|
|
17
|
+
changed = true;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
out.push(line);
|
|
21
|
+
}
|
|
22
|
+
return changed ? out.join("\n") : source;
|
|
23
|
+
}
|
|
24
|
+
const RULE_CLASS = [
|
|
25
|
+
"h-0",
|
|
26
|
+
"flex-1",
|
|
27
|
+
"border-t-2",
|
|
28
|
+
"border-dashed",
|
|
29
|
+
"border-muted-foreground/40"
|
|
30
|
+
];
|
|
31
|
+
function pageBreakNode() {
|
|
32
|
+
const rule = {
|
|
33
|
+
type: "element",
|
|
34
|
+
tagName: "span",
|
|
35
|
+
properties: { className: RULE_CLASS, ariaHidden: "true" },
|
|
36
|
+
children: []
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
type: "paragraph",
|
|
40
|
+
children: [],
|
|
41
|
+
data: {
|
|
42
|
+
hName: "div",
|
|
43
|
+
hProperties: {
|
|
44
|
+
className: [
|
|
45
|
+
PAGE_BREAK_CLASS,
|
|
46
|
+
"not-prose",
|
|
47
|
+
"my-8",
|
|
48
|
+
"flex",
|
|
49
|
+
"items-center",
|
|
50
|
+
"gap-3",
|
|
51
|
+
"select-none"
|
|
52
|
+
],
|
|
53
|
+
role: "separator",
|
|
54
|
+
ariaLabel: PAGE_BREAK_LABEL,
|
|
55
|
+
dataMatrxPageBreak: ""
|
|
56
|
+
},
|
|
57
|
+
hChildren: [
|
|
58
|
+
rule,
|
|
59
|
+
{
|
|
60
|
+
type: "element",
|
|
61
|
+
tagName: "span",
|
|
62
|
+
properties: {
|
|
63
|
+
className: [
|
|
64
|
+
"text-[10px]",
|
|
65
|
+
"font-semibold",
|
|
66
|
+
"uppercase",
|
|
67
|
+
"tracking-[0.08em]",
|
|
68
|
+
"text-muted-foreground"
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
children: [{ type: "text", value: PAGE_BREAK_LABEL }]
|
|
72
|
+
},
|
|
73
|
+
{ ...rule }
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function rawSource(node, file) {
|
|
79
|
+
const source = typeof file?.value === "string" ? file.value : null;
|
|
80
|
+
const start = node.position?.start.offset;
|
|
81
|
+
const end = node.position?.end.offset;
|
|
82
|
+
if (source === null || start === void 0 || end === void 0) return null;
|
|
83
|
+
return source.slice(start, end);
|
|
84
|
+
}
|
|
85
|
+
function decodeTagEntities(text) {
|
|
86
|
+
return text.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, '"');
|
|
87
|
+
}
|
|
88
|
+
function isDirectiveNode(node, file) {
|
|
89
|
+
if (node.type !== "html" && node.type !== "paragraph") return false;
|
|
90
|
+
const raw = rawSource(node, file);
|
|
91
|
+
if (raw !== null) return isBreakLine(decodeTagEntities(raw));
|
|
92
|
+
if (node.type === "html") return isBreakLine(node.value ?? "");
|
|
93
|
+
if (!node.children?.length || !node.children.every((c) => c.type === "text")) return false;
|
|
94
|
+
return isBreakLine(node.children.map((c) => c.value ?? "").join(""));
|
|
95
|
+
}
|
|
96
|
+
function remarkMatrxPageBreak() {
|
|
97
|
+
return (tree, file) => {
|
|
98
|
+
const children = tree.children;
|
|
99
|
+
if (!children) return;
|
|
100
|
+
for (let i = 0; i < children.length; i++) {
|
|
101
|
+
if (isDirectiveNode(children[i], file)) children[i] = pageBreakNode();
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export {
|
|
106
|
+
remarkMatrxPageBreak as default,
|
|
107
|
+
isolatePageBreakLines
|
|
108
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* rehype-safe-raw-html — render a curated allow-list of raw HTML tags that
|
|
3
|
+
* models commonly emit (inline `<img>`, `<table>`…) WITHOUT opening the door to
|
|
4
|
+
* XSS and WITHOUT the whole-tree serialize/reparse that `rehype-raw` does.
|
|
5
|
+
*
|
|
6
|
+
* Why not `rehype-raw`? It re-serializes the entire hast tree and reparses it,
|
|
7
|
+
* which round-trips our custom `matrx-variable` element (its `data-name` prop
|
|
8
|
+
* can be renamed away → variables vanish) and the pre-KaTeX `<span class=math>`
|
|
9
|
+
* nodes. This plugin instead visits ONLY `raw` nodes (the raw-HTML strings
|
|
10
|
+
* react-markdown leaves in the tree because it runs with `allowDangerousHtml`),
|
|
11
|
+
* parses each in isolation, sanitizes the result against a tight schema, and
|
|
12
|
+
* splices the safe elements back in. Element nodes already in the tree
|
|
13
|
+
* (matrx-variable, math, links, images from the block splitter) are never
|
|
14
|
+
* touched.
|
|
15
|
+
*
|
|
16
|
+
* Must run BEFORE react-markdown's internal `raw`→text transform (which turns
|
|
17
|
+
* any surviving raw node into literal text) and BEFORE `rehype-katex` (whose
|
|
18
|
+
* rendered output must not be sanitized). Placement in `rehypePlugins` handles
|
|
19
|
+
* the first; being listed before rehype-katex handles the second.
|
|
20
|
+
*
|
|
21
|
+
* Scope: `<div>` and the `style` attribute are intentionally EXCLUDED — inline
|
|
22
|
+
* layout HTML (flex/grid via `style`) is a separate, higher-risk concern.
|
|
23
|
+
*
|
|
24
|
+
* The parsed/sanitized elements are rendered by the SAME `components` overrides
|
|
25
|
+
* in BasicMarkdownContent as markdown-native tags — so a raw `<table>` gets our
|
|
26
|
+
* bordered table styling and a raw `<img>` gets the inline-flow image treatment
|
|
27
|
+
* for free.
|
|
28
|
+
*/
|
|
29
|
+
import { type Schema } from "hast-util-sanitize";
|
|
30
|
+
import type { Root } from "hast";
|
|
31
|
+
declare module "hast" {
|
|
32
|
+
interface Data {
|
|
33
|
+
/**
|
|
34
|
+
* Set on `<table>` elements this plugin parses from raw HTML. The admin
|
|
35
|
+
* table-render-path diagnostic in BasicMarkdownContent uses it to STAY
|
|
36
|
+
* QUIET for HTML tables — they were never markdown pipe tables and are
|
|
37
|
+
* correctly rendered by the GFM component path, so "not promoted to a
|
|
38
|
+
* table block" is expected, not a defect. Lives on `data` (not
|
|
39
|
+
* `properties`) so it never becomes a DOM attribute.
|
|
40
|
+
*/
|
|
41
|
+
matrxRawHtmlTable?: boolean;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Tags a model may emit as raw HTML that we render. Kept in sync with the
|
|
46
|
+
* pre-escape gate in BasicMarkdownContent (`preprocessContent`) — a tag left
|
|
47
|
+
* un-escaped there must be allowed here, or it renders as literal text.
|
|
48
|
+
* Deliberately excludes `div` (layout container — Case 4) and any scripting or
|
|
49
|
+
* embedding tags (`script`, `style`, `iframe`, `object`, `embed`, `form`…).
|
|
50
|
+
*/
|
|
51
|
+
export declare const ALLOWED_RAW_HTML_TAGS: ReadonlySet<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Sanitization schema for raw-HTML subtrees. Any tag not listed is dropped, any
|
|
54
|
+
* attribute not listed is stripped (so `onerror`, `onclick`, inline `style`,
|
|
55
|
+
* etc. never survive), and `src`/`href` are restricted to safe protocols so
|
|
56
|
+
* `javascript:` URLs cannot execute. `style` is intentionally omitted.
|
|
57
|
+
*/
|
|
58
|
+
export declare const RAW_HTML_SCHEMA: Schema;
|
|
59
|
+
export default function rehypeSafeRawHtml(): (tree: Root) => void;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { visit } from "unist-util-visit";
|
|
2
|
+
import { fromHtml } from "hast-util-from-html";
|
|
3
|
+
import { sanitize } from "hast-util-sanitize";
|
|
4
|
+
function isRawNode(node) {
|
|
5
|
+
return typeof node === "object" && node !== null && node.type === "raw" && typeof node.value === "string";
|
|
6
|
+
}
|
|
7
|
+
const ALLOWED_RAW_HTML_TAGS = /* @__PURE__ */ new Set([
|
|
8
|
+
// media
|
|
9
|
+
"img",
|
|
10
|
+
// links + breaks + rules
|
|
11
|
+
"a",
|
|
12
|
+
"br",
|
|
13
|
+
"hr",
|
|
14
|
+
// inline text semantics
|
|
15
|
+
"span",
|
|
16
|
+
"p",
|
|
17
|
+
"strong",
|
|
18
|
+
"b",
|
|
19
|
+
"em",
|
|
20
|
+
"i",
|
|
21
|
+
"u",
|
|
22
|
+
"s",
|
|
23
|
+
"del",
|
|
24
|
+
"ins",
|
|
25
|
+
"sup",
|
|
26
|
+
"sub",
|
|
27
|
+
"mark",
|
|
28
|
+
"kbd",
|
|
29
|
+
"abbr",
|
|
30
|
+
"small",
|
|
31
|
+
"code",
|
|
32
|
+
"pre",
|
|
33
|
+
// lists + quotes + headings
|
|
34
|
+
"ul",
|
|
35
|
+
"ol",
|
|
36
|
+
"li",
|
|
37
|
+
"blockquote",
|
|
38
|
+
"h1",
|
|
39
|
+
"h2",
|
|
40
|
+
"h3",
|
|
41
|
+
"h4",
|
|
42
|
+
"h5",
|
|
43
|
+
"h6",
|
|
44
|
+
// tables
|
|
45
|
+
"table",
|
|
46
|
+
"thead",
|
|
47
|
+
"tbody",
|
|
48
|
+
"tfoot",
|
|
49
|
+
"tr",
|
|
50
|
+
"th",
|
|
51
|
+
"td",
|
|
52
|
+
"caption",
|
|
53
|
+
"colgroup",
|
|
54
|
+
"col",
|
|
55
|
+
"figure",
|
|
56
|
+
"figcaption",
|
|
57
|
+
// collapsible sections (styled by the core's details/summary elements)
|
|
58
|
+
"details",
|
|
59
|
+
"summary"
|
|
60
|
+
]);
|
|
61
|
+
const RAW_HTML_SCHEMA = {
|
|
62
|
+
tagNames: Array.from(ALLOWED_RAW_HTML_TAGS),
|
|
63
|
+
attributes: {
|
|
64
|
+
img: ["src", "alt", "title", "width", "height", "loading"],
|
|
65
|
+
a: ["href", "title", "target", "rel"],
|
|
66
|
+
th: ["colSpan", "rowSpan", "scope", "align"],
|
|
67
|
+
td: ["colSpan", "rowSpan", "headers", "align"],
|
|
68
|
+
col: ["span", "width"],
|
|
69
|
+
colgroup: ["span"],
|
|
70
|
+
abbr: ["title"],
|
|
71
|
+
details: ["open"],
|
|
72
|
+
"*": ["align"]
|
|
73
|
+
},
|
|
74
|
+
protocols: {
|
|
75
|
+
href: ["http", "https", "mailto", "tel"],
|
|
76
|
+
src: ["http", "https"]
|
|
77
|
+
},
|
|
78
|
+
// Drop these outright (element + subtree) if they ever appear.
|
|
79
|
+
strip: ["script", "style", "iframe", "object", "embed", "form", "input"],
|
|
80
|
+
// Keep author ids untouched (no clobber prefix rewriting).
|
|
81
|
+
clobberPrefix: "",
|
|
82
|
+
clobber: [],
|
|
83
|
+
allowComments: false,
|
|
84
|
+
allowDoctypes: false
|
|
85
|
+
};
|
|
86
|
+
const VOID_TAGS = /* @__PURE__ */ new Set(["br", "hr", "img", "col"]);
|
|
87
|
+
const OPENING_TAG = /^<([a-zA-Z][\w-]*)(?:\s[^<>]*)?>$/;
|
|
88
|
+
function pairInlineTag(node, index, parent) {
|
|
89
|
+
const open = OPENING_TAG.exec(node.value.trim());
|
|
90
|
+
if (!open) return false;
|
|
91
|
+
const tag = (open[1] ?? "").toLowerCase();
|
|
92
|
+
if (!ALLOWED_RAW_HTML_TAGS.has(tag) || VOID_TAGS.has(tag)) return false;
|
|
93
|
+
const closer = new RegExp(`^</${tag}\\s*>$`, "i");
|
|
94
|
+
let depth = 0;
|
|
95
|
+
for (let j = index + 1; j < parent.children.length; j++) {
|
|
96
|
+
const sibling = parent.children[j];
|
|
97
|
+
if (!isRawNode(sibling)) continue;
|
|
98
|
+
const value = sibling.value.trim();
|
|
99
|
+
const again = OPENING_TAG.exec(value);
|
|
100
|
+
if (again && (again[1] ?? "").toLowerCase() === tag) depth++;
|
|
101
|
+
else if (closer.test(value)) {
|
|
102
|
+
if (depth > 0) {
|
|
103
|
+
depth--;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const shell = sanitize(fromHtml(`${node.value}</${tag}>`, { fragment: true }), RAW_HTML_SCHEMA);
|
|
107
|
+
const element = shell.children.length === 1 ? shell.children[0] : null;
|
|
108
|
+
if (!element || element.type !== "element" || element.tagName !== tag) return false;
|
|
109
|
+
element.children = parent.children.slice(index + 1, j);
|
|
110
|
+
parent.children.splice(index, j - index + 1, element);
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
function rehypeSafeRawHtml() {
|
|
117
|
+
return (tree) => {
|
|
118
|
+
visit(tree, (node, index, parent) => {
|
|
119
|
+
if (!isRawNode(node) || !parent || typeof index !== "number") return;
|
|
120
|
+
if (pairInlineTag(node, index, parent)) return index;
|
|
121
|
+
const fragment = fromHtml(node.value, { fragment: true });
|
|
122
|
+
const clean = sanitize(fragment, RAW_HTML_SCHEMA);
|
|
123
|
+
visit(clean, "element", (el) => {
|
|
124
|
+
if (el.tagName !== "table") return;
|
|
125
|
+
if (!el.data) {
|
|
126
|
+
el.data = { position: {} };
|
|
127
|
+
}
|
|
128
|
+
el.data.matrxRawHtmlTable = true;
|
|
129
|
+
});
|
|
130
|
+
const safeChildren = clean.children;
|
|
131
|
+
parent.children.splice(index, 1, ...safeChildren);
|
|
132
|
+
return index;
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
export {
|
|
137
|
+
ALLOWED_RAW_HTML_TAGS,
|
|
138
|
+
RAW_HTML_SCHEMA,
|
|
139
|
+
rehypeSafeRawHtml as default
|
|
140
|
+
};
|
package/dist/display/markdown-classification/processors/bock-processors/parse-markdown-table.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MarkdownTableData } from "../../../types.js";
|
|
2
|
+
type NormalizedTableData = Array<{
|
|
3
|
+
[key: string]: string;
|
|
4
|
+
}>;
|
|
5
|
+
export declare const parseMarkdownTable: (content: string, isStreamActive?: boolean) => {
|
|
6
|
+
markdown: MarkdownTableData | null;
|
|
7
|
+
data: NormalizedTableData | null;
|
|
8
|
+
};
|
|
9
|
+
export declare const parseMarkdownTables: (content: string) => Array<{
|
|
10
|
+
markdown: MarkdownTableData | null;
|
|
11
|
+
data: NormalizedTableData | null;
|
|
12
|
+
startIndex: number;
|
|
13
|
+
}>;
|
|
14
|
+
export {};
|
package/dist/display/markdown-classification/processors/bock-processors/parse-markdown-table.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { unwrapCodeSpans } from "@ai-matrx/content-ir/source";
|
|
2
|
+
import {
|
|
3
|
+
continuesTable,
|
|
4
|
+
findTableEnd,
|
|
5
|
+
findTableStart,
|
|
6
|
+
isGfmDelimiterRow,
|
|
7
|
+
rowCells,
|
|
8
|
+
tableContainerIndent,
|
|
9
|
+
tableStartsAt
|
|
10
|
+
} from "../utils/gfm-table-lines.js";
|
|
11
|
+
const tableCache = /* @__PURE__ */ new Map();
|
|
12
|
+
const analyzeTableCompletion = (content, isStreamActive = false) => {
|
|
13
|
+
const lines = content.split("\n").filter((line) => line.trim().length > 0);
|
|
14
|
+
const tableStartIndex = findTableStart(lines);
|
|
15
|
+
if (tableStartIndex === -1) {
|
|
16
|
+
return { isComplete: false, completeRows: [], bufferRow: [], totalRows: 0, completeRowCount: 0 };
|
|
17
|
+
}
|
|
18
|
+
const tableLines = lines.slice(tableStartIndex);
|
|
19
|
+
if (tableLines.length < 3) {
|
|
20
|
+
return { isComplete: false, completeRows: [], bufferRow: [], totalRows: 0, completeRowCount: 0 };
|
|
21
|
+
}
|
|
22
|
+
const dataLines = tableLines.slice(2);
|
|
23
|
+
const completeRows = [];
|
|
24
|
+
let bufferRow = [];
|
|
25
|
+
let totalRows = 0;
|
|
26
|
+
const processRow = rowCells;
|
|
27
|
+
const container = tableContainerIndent(lines, tableStartIndex);
|
|
28
|
+
for (let i = 0; i < dataLines.length; i++) {
|
|
29
|
+
const line = dataLines[i].trim();
|
|
30
|
+
if (continuesTable(dataLines[i], container)) {
|
|
31
|
+
totalRows++;
|
|
32
|
+
const row = processRow(line);
|
|
33
|
+
const isCompleteRow = line.endsWith("|") || i < dataLines.length - 1;
|
|
34
|
+
if (isCompleteRow) {
|
|
35
|
+
completeRows.push(row);
|
|
36
|
+
} else if (isStreamActive) {
|
|
37
|
+
bufferRow = row;
|
|
38
|
+
} else {
|
|
39
|
+
completeRows.push(row);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const isComplete = !isStreamActive || bufferRow.length === 0;
|
|
44
|
+
return {
|
|
45
|
+
isComplete,
|
|
46
|
+
completeRows,
|
|
47
|
+
bufferRow,
|
|
48
|
+
totalRows,
|
|
49
|
+
completeRowCount: completeRows.length
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
const parseMarkdownTable = (content, isStreamActive = false) => {
|
|
53
|
+
try {
|
|
54
|
+
const tableState = analyzeTableCompletion(content, isStreamActive);
|
|
55
|
+
const contentHash = `${tableState.completeRowCount}-${tableState.isComplete}`;
|
|
56
|
+
const cacheKey = `table-${contentHash}`;
|
|
57
|
+
const cached = tableCache.get(cacheKey);
|
|
58
|
+
const lines = content.split("\n").filter((line) => line.trim().length > 0);
|
|
59
|
+
const tableStartIndex = findTableStart(lines);
|
|
60
|
+
if (tableStartIndex === -1) return { markdown: null, data: null };
|
|
61
|
+
const tableLines = lines.slice(tableStartIndex);
|
|
62
|
+
if (tableLines.length < 3) return { markdown: null, data: null };
|
|
63
|
+
const separatorLine = tableLines[1].trim();
|
|
64
|
+
if (!isGfmDelimiterRow(separatorLine) || !tableStartsAt(lines, tableStartIndex)) {
|
|
65
|
+
if (!isStreamActive && true) {
|
|
66
|
+
console.warn("Invalid table separator format:", separatorLine);
|
|
67
|
+
}
|
|
68
|
+
return { markdown: null, data: null };
|
|
69
|
+
}
|
|
70
|
+
const processRow = rowCells;
|
|
71
|
+
const headers = processRow(tableLines[0]);
|
|
72
|
+
if (headers.length === 0) return { markdown: null, data: null };
|
|
73
|
+
let rowsToProcess;
|
|
74
|
+
if (isStreamActive) {
|
|
75
|
+
rowsToProcess = tableState.completeRows;
|
|
76
|
+
} else {
|
|
77
|
+
rowsToProcess = tableLines.slice(2).map(processRow).filter((row) => row.some((cell) => cell.length > 0));
|
|
78
|
+
}
|
|
79
|
+
if (rowsToProcess.length === 0) return { markdown: null, data: null };
|
|
80
|
+
const hasValidStructure = rowsToProcess.every(
|
|
81
|
+
(row) => row.length > 0 && row.length <= Math.max(headers.length * 2, 10)
|
|
82
|
+
);
|
|
83
|
+
if (!hasValidStructure) {
|
|
84
|
+
if (!isStreamActive && true) {
|
|
85
|
+
console.warn("Table structure validation failed - inconsistent row lengths");
|
|
86
|
+
}
|
|
87
|
+
return { markdown: null, data: null };
|
|
88
|
+
}
|
|
89
|
+
const cleanText = (text) => {
|
|
90
|
+
return unwrapCodeSpans(text).replace(/\*\*([^*]+)\*\*/g, "$1").replace(/\*([^*]+)\*/g, "$1").replace(/(?<![A-Za-z0-9])_([^_\n]+?)_(?![A-Za-z0-9])/g, "$1").replace(/\[([^\]]+)\]\(([^)]+)\)/g, "$1|$2").replace(/#{1,6}\s*/g, "").trim();
|
|
91
|
+
};
|
|
92
|
+
const normalizedData = rowsToProcess.map((row) => {
|
|
93
|
+
const rowData = {};
|
|
94
|
+
headers.forEach((header, index) => {
|
|
95
|
+
const cleanHeader = cleanText(header);
|
|
96
|
+
rowData[cleanHeader] = index < row.length ? cleanText(row[index]) : "";
|
|
97
|
+
});
|
|
98
|
+
return rowData;
|
|
99
|
+
});
|
|
100
|
+
const result = {
|
|
101
|
+
markdown: { headers, rows: rowsToProcess },
|
|
102
|
+
data: normalizedData
|
|
103
|
+
};
|
|
104
|
+
if (isStreamActive) {
|
|
105
|
+
tableCache.set(cacheKey, {
|
|
106
|
+
markdown: result.markdown,
|
|
107
|
+
data: result.data,
|
|
108
|
+
hash: contentHash
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
|
+
} catch (error) {
|
|
113
|
+
return { markdown: null, data: null };
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const parseMarkdownTables = (content) => {
|
|
117
|
+
try {
|
|
118
|
+
const lines = content.split("\n");
|
|
119
|
+
const tables = [];
|
|
120
|
+
let currentIndex = 0;
|
|
121
|
+
while (currentIndex < lines.length) {
|
|
122
|
+
const globalStartIndex = findTableStart(lines, currentIndex);
|
|
123
|
+
if (globalStartIndex === -1) break;
|
|
124
|
+
const tableLines = lines.slice(globalStartIndex, findTableEnd(lines, globalStartIndex));
|
|
125
|
+
if (tableLines.length < 3) {
|
|
126
|
+
currentIndex = globalStartIndex + 1;
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (!tableStartsAt(lines, globalStartIndex)) {
|
|
130
|
+
currentIndex = globalStartIndex + 1;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
const processRow = rowCells;
|
|
134
|
+
const headers = processRow(tableLines[0]);
|
|
135
|
+
if (headers.length === 0) {
|
|
136
|
+
currentIndex = globalStartIndex + 1;
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const rows = tableLines.slice(2).map(processRow).filter((row) => row.some((cell) => cell.length > 0));
|
|
140
|
+
const tableLength = tableLines.length;
|
|
141
|
+
if (rows.length === 0) {
|
|
142
|
+
currentIndex = globalStartIndex + tableLength;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const cleanText = (text) => {
|
|
146
|
+
return unwrapCodeSpans(text).replace(/\*\*([^*]+)\*\*/g, "$1").replace(/\*([^*]+)\*/g, "$1").replace(/(?<![A-Za-z0-9])_([^_\n]+?)_(?![A-Za-z0-9])/g, "$1").replace(/\[([^\]]+)\]\(([^)]+)\)/g, "$1|$2").replace(/#{1,6}\s*/g, "").trim();
|
|
147
|
+
};
|
|
148
|
+
const normalizedData = rows.map((row) => {
|
|
149
|
+
const rowData = {};
|
|
150
|
+
headers.forEach((header, index) => {
|
|
151
|
+
const cleanHeader = cleanText(header);
|
|
152
|
+
rowData[cleanHeader] = index < row.length ? cleanText(row[index]) : "";
|
|
153
|
+
});
|
|
154
|
+
return rowData;
|
|
155
|
+
});
|
|
156
|
+
tables.push({
|
|
157
|
+
markdown: { headers, rows },
|
|
158
|
+
data: normalizedData,
|
|
159
|
+
startIndex: globalStartIndex
|
|
160
|
+
});
|
|
161
|
+
currentIndex = globalStartIndex + tableLength;
|
|
162
|
+
}
|
|
163
|
+
return tables;
|
|
164
|
+
} catch (error) {
|
|
165
|
+
return [];
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
export {
|
|
169
|
+
parseMarkdownTable,
|
|
170
|
+
parseMarkdownTables
|
|
171
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
export interface Position {
|
|
2
|
+
start: {
|
|
3
|
+
line: number;
|
|
4
|
+
column: number;
|
|
5
|
+
offset: number;
|
|
6
|
+
};
|
|
7
|
+
end: {
|
|
8
|
+
line: number;
|
|
9
|
+
column: number;
|
|
10
|
+
offset: number;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export type NodeType = 'root' | 'paragraph' | 'text' | 'strong' | 'thematicBreak' | 'heading' | 'list' | 'listItem' | 'blockquote' | 'link' | 'image' | 'code' | 'html' | 'emphasis' | 'inlineCode' | 'break' | 'delete' | 'footnote' | 'footnoteDefinition' | 'footnoteReference' | 'definition' | 'table' | 'tableRow' | 'tableCell';
|
|
14
|
+
export interface BaseAstNode {
|
|
15
|
+
type: NodeType;
|
|
16
|
+
position?: Position;
|
|
17
|
+
}
|
|
18
|
+
export interface RootNode extends BaseAstNode {
|
|
19
|
+
type: 'root';
|
|
20
|
+
children: AstNode[];
|
|
21
|
+
}
|
|
22
|
+
export interface ParagraphNode extends BaseAstNode {
|
|
23
|
+
type: 'paragraph';
|
|
24
|
+
children: AstNode[];
|
|
25
|
+
}
|
|
26
|
+
export interface TextNode extends BaseAstNode {
|
|
27
|
+
type: 'text';
|
|
28
|
+
value: string;
|
|
29
|
+
}
|
|
30
|
+
export interface StrongNode extends BaseAstNode {
|
|
31
|
+
type: 'strong';
|
|
32
|
+
children: AstNode[];
|
|
33
|
+
}
|
|
34
|
+
export interface ThematicBreakNode extends BaseAstNode {
|
|
35
|
+
type: 'thematicBreak';
|
|
36
|
+
}
|
|
37
|
+
export interface HeadingNode extends BaseAstNode {
|
|
38
|
+
type: 'heading';
|
|
39
|
+
depth: number;
|
|
40
|
+
children: AstNode[];
|
|
41
|
+
}
|
|
42
|
+
export interface ListNode extends BaseAstNode {
|
|
43
|
+
type: 'list';
|
|
44
|
+
ordered: boolean;
|
|
45
|
+
start: number | null;
|
|
46
|
+
spread: boolean;
|
|
47
|
+
children: AstNode[];
|
|
48
|
+
}
|
|
49
|
+
export interface ListItemNode extends BaseAstNode {
|
|
50
|
+
type: 'listItem';
|
|
51
|
+
spread: boolean;
|
|
52
|
+
checked: boolean | null;
|
|
53
|
+
children: AstNode[];
|
|
54
|
+
}
|
|
55
|
+
export interface BlockquoteNode extends BaseAstNode {
|
|
56
|
+
type: 'blockquote';
|
|
57
|
+
children: AstNode[];
|
|
58
|
+
}
|
|
59
|
+
export interface LinkNode extends BaseAstNode {
|
|
60
|
+
type: 'link';
|
|
61
|
+
url: string;
|
|
62
|
+
title?: string | null;
|
|
63
|
+
children: AstNode[];
|
|
64
|
+
}
|
|
65
|
+
export interface ImageNode extends BaseAstNode {
|
|
66
|
+
type: 'image';
|
|
67
|
+
url: string;
|
|
68
|
+
title?: string | null;
|
|
69
|
+
alt?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface CodeNode extends BaseAstNode {
|
|
72
|
+
type: 'code';
|
|
73
|
+
value: string;
|
|
74
|
+
lang?: string | null;
|
|
75
|
+
meta?: string | null;
|
|
76
|
+
}
|
|
77
|
+
export interface HtmlNode extends BaseAstNode {
|
|
78
|
+
type: 'html';
|
|
79
|
+
value: string;
|
|
80
|
+
}
|
|
81
|
+
export interface EmphasisNode extends BaseAstNode {
|
|
82
|
+
type: 'emphasis';
|
|
83
|
+
children: AstNode[];
|
|
84
|
+
}
|
|
85
|
+
export interface InlineCodeNode extends BaseAstNode {
|
|
86
|
+
type: 'inlineCode';
|
|
87
|
+
value: string;
|
|
88
|
+
}
|
|
89
|
+
export interface BreakNode extends BaseAstNode {
|
|
90
|
+
type: 'break';
|
|
91
|
+
}
|
|
92
|
+
export interface DeleteNode extends BaseAstNode {
|
|
93
|
+
type: 'delete';
|
|
94
|
+
children: AstNode[];
|
|
95
|
+
}
|
|
96
|
+
export interface TableNode extends BaseAstNode {
|
|
97
|
+
type: 'table';
|
|
98
|
+
align?: Array<'left' | 'right' | 'center' | null>;
|
|
99
|
+
children: AstNode[];
|
|
100
|
+
}
|
|
101
|
+
export interface TableRowNode extends BaseAstNode {
|
|
102
|
+
type: 'tableRow';
|
|
103
|
+
children: AstNode[];
|
|
104
|
+
}
|
|
105
|
+
export interface TableCellNode extends BaseAstNode {
|
|
106
|
+
type: 'tableCell';
|
|
107
|
+
children: AstNode[];
|
|
108
|
+
}
|
|
109
|
+
export interface DefinitionNode extends BaseAstNode {
|
|
110
|
+
type: 'definition';
|
|
111
|
+
identifier: string;
|
|
112
|
+
label?: string;
|
|
113
|
+
url: string;
|
|
114
|
+
title?: string | null;
|
|
115
|
+
}
|
|
116
|
+
export type AstNode = RootNode | ParagraphNode | TextNode | StrongNode | ThematicBreakNode | HeadingNode | ListNode | ListItemNode | BlockquoteNode | LinkNode | ImageNode | CodeNode | HtmlNode | EmphasisNode | InlineCodeNode | BreakNode | DeleteNode | TableNode | TableRowNode | TableCellNode | DefinitionNode;
|
|
117
|
+
export declare function isRoot(node: AstNode): node is RootNode;
|
|
118
|
+
export declare function hasChildren(node: AstNode): node is AstNode & {
|
|
119
|
+
children: AstNode[];
|
|
120
|
+
};
|