@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.
Files changed (247) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/LICENSE +21 -0
  3. package/README.md +61 -2
  4. package/dist/display/blocks/csv/CsvBlock.d.ts +10 -0
  5. package/dist/display/blocks/csv/CsvBlock.js +245 -0
  6. package/dist/display/blocks/table/parseMarkdownTable.d.ts +20 -0
  7. package/dist/display/blocks/table/parseMarkdownTable.js +35 -0
  8. package/dist/display/chat-markdown/citations/remarkMatrxCite.d.ts +33 -0
  9. package/dist/display/chat-markdown/citations/remarkMatrxCite.js +71 -0
  10. package/dist/display/chat-markdown/matrx-variables/remarkMatrxVariable.d.ts +29 -0
  11. package/dist/display/chat-markdown/matrx-variables/remarkMatrxVariable.js +71 -0
  12. package/dist/display/chat-markdown/page-break/remarkMatrxPageBreak.d.ts +55 -0
  13. package/dist/display/chat-markdown/page-break/remarkMatrxPageBreak.js +108 -0
  14. package/dist/display/chat-markdown/rehypeSafeRawHtml.d.ts +59 -0
  15. package/dist/display/chat-markdown/rehypeSafeRawHtml.js +140 -0
  16. package/dist/display/markdown-classification/processors/bock-processors/parse-markdown-table.d.ts +14 -0
  17. package/dist/display/markdown-classification/processors/bock-processors/parse-markdown-table.js +171 -0
  18. package/dist/display/markdown-classification/processors/types.d.ts +120 -0
  19. package/dist/display/markdown-classification/processors/types.js +10 -0
  20. package/dist/display/markdown-classification/processors/utils/client-blocks.d.ts +169 -0
  21. package/dist/display/markdown-classification/processors/utils/client-blocks.js +0 -0
  22. package/dist/display/markdown-classification/processors/utils/content-splitter-core.d.ts +223 -0
  23. package/dist/display/markdown-classification/processors/utils/content-splitter-core.js +1791 -0
  24. package/dist/display/markdown-classification/processors/utils/content-splitter-v2.d.ts +15 -0
  25. package/dist/display/markdown-classification/processors/utils/content-splitter-v2.js +19 -0
  26. package/dist/display/markdown-classification/processors/utils/expand-text-blocks.d.ts +9 -0
  27. package/dist/display/markdown-classification/processors/utils/expand-text-blocks.js +36 -0
  28. package/dist/display/markdown-classification/processors/utils/gfm-table-lines.d.ts +5 -0
  29. package/dist/display/markdown-classification/processors/utils/gfm-table-lines.js +40 -0
  30. package/dist/display/markdown-classification/processors/utils/gfm-table-vector-inputs.d.ts +16 -0
  31. package/dist/display/markdown-classification/processors/utils/gfm-table-vector-inputs.js +385 -0
  32. package/dist/display/markdown-classification/processors/utils/gfm-table-vectors.d.ts +43 -0
  33. package/dist/display/markdown-classification/processors/utils/gfm-table-vectors.js +33 -0
  34. package/dist/display/markdown-classification/processors/utils/table-data-parser.d.ts +9 -0
  35. package/dist/display/markdown-classification/processors/utils/table-data-parser.js +30 -0
  36. package/dist/display/markdown-classification/processors/utils/thinking-parser.d.ts +7 -0
  37. package/dist/display/markdown-classification/processors/utils/thinking-parser.js +70 -0
  38. package/dist/display/render-block.d.ts +23 -0
  39. package/dist/display/render-block.js +0 -0
  40. package/dist/display/themes.d.ts +1023 -0
  41. package/dist/display/themes.js +1105 -0
  42. package/dist/display/types.d.ts +32 -0
  43. package/dist/display/types.js +0 -0
  44. package/dist/host/ContentIrHostBoundary.d.ts +8 -0
  45. package/dist/host/ContentIrHostBoundary.js +15 -0
  46. package/dist/host/ErrorActions.d.ts +4 -0
  47. package/dist/host/ErrorActions.js +11 -0
  48. package/dist/host/NestedContent.d.ts +3 -0
  49. package/dist/host/NestedContent.js +12 -0
  50. package/dist/host/ResourcePeek.d.ts +6 -0
  51. package/dist/host/ResourcePeek.js +14 -0
  52. package/dist/host/component-registry.d.ts +2 -0
  53. package/dist/host/component-registry.js +25 -0
  54. package/dist/host/diagnostics.d.ts +2 -0
  55. package/dist/host/diagnostics.js +15 -0
  56. package/dist/host/index.d.ts +3 -0
  57. package/dist/host/index.js +18 -0
  58. package/dist/host/kind-incident.d.ts +3 -0
  59. package/dist/host/kind-incident.js +12 -0
  60. package/dist/host/kind-registry.d.ts +2 -0
  61. package/dist/host/kind-registry.js +35 -0
  62. package/dist/host/people.d.ts +3 -0
  63. package/dist/host/people.js +12 -0
  64. package/dist/host/registry.d.ts +27 -0
  65. package/dist/host/registry.js +55 -0
  66. package/dist/host/splitter-envelopes.d.ts +2 -0
  67. package/dist/host/splitter-envelopes.js +7 -0
  68. package/dist/host/tables.d.ts +6 -0
  69. package/dist/host/tables.js +8 -0
  70. package/dist/host/toast.d.ts +2 -0
  71. package/dist/host/toast.js +57 -0
  72. package/dist/host/types.d.ts +157 -0
  73. package/dist/host/types.js +0 -0
  74. package/dist/host/wikilinks.d.ts +15 -0
  75. package/dist/host/wikilinks.js +23 -0
  76. package/dist/kinds/host/route-env.d.ts +33 -0
  77. package/dist/kinds/host/route-env.js +16 -0
  78. package/dist/kinds/react/KindEscapedNotice.d.ts +14 -0
  79. package/dist/kinds/react/KindEscapedNotice.js +72 -0
  80. package/dist/kinds/react/ProvisionalKindBoundary.d.ts +19 -0
  81. package/dist/kinds/react/ProvisionalKindBoundary.js +17 -0
  82. package/dist/kinds/react/ensure-kind-renderable.d.ts +14 -0
  83. package/dist/kinds/react/ensure-kind-renderable.js +45 -0
  84. package/dist/kinds/react/kind-problems.d.ts +62 -0
  85. package/dist/kinds/react/kind-problems.js +134 -0
  86. package/dist/kinds/react/kind-route.d.ts +23 -0
  87. package/dist/kinds/react/kind-route.js +24 -0
  88. package/dist/kinds/react/loading/infer-loading-slug.d.ts +58 -0
  89. package/dist/kinds/react/loading/infer-loading-slug.js +100 -0
  90. package/dist/kinds/react/loading/kind-loading-components.d.ts +48 -0
  91. package/dist/kinds/react/loading/kind-loading-components.js +447 -0
  92. package/dist/kinds/react/loading/kind-loading-registry.d.ts +21 -0
  93. package/dist/kinds/react/loading/kind-loading-registry.js +62 -0
  94. package/dist/kinds/react/loading/kind-loading-slugs.d.ts +18 -0
  95. package/dist/kinds/react/loading/kind-loading-slugs.js +34 -0
  96. package/dist/kinds/react/loading/kind-loading.types.d.ts +79 -0
  97. package/dist/kinds/react/loading/kind-loading.types.js +31 -0
  98. package/dist/kinds/react/loading/resolve-loading-slug.d.ts +29 -0
  99. package/dist/kinds/react/loading/resolve-loading-slug.js +51 -0
  100. package/dist/kinds/react/partial-kind-route.d.ts +32 -0
  101. package/dist/kinds/react/partial-kind-route.js +27 -0
  102. package/dist/kinds/react/registry-versioned.d.ts +54 -0
  103. package/dist/kinds/react/registry-versioned.js +18 -0
  104. package/dist/kinds/react/route-at-version.d.ts +38 -0
  105. package/dist/kinds/react/route-at-version.js +78 -0
  106. package/dist/kinds/react/slot/KindSlot.d.ts +87 -0
  107. package/dist/kinds/react/slot/KindSlot.js +65 -0
  108. package/dist/kinds/react/use-registry-repaint.d.ts +6 -0
  109. package/dist/kinds/react/use-registry-repaint.js +36 -0
  110. package/dist/kinds/react/useIrNode.d.ts +9 -0
  111. package/dist/kinds/react/useIrNode.js +46 -0
  112. package/dist/kinds/react/useLiveJsonRegion.d.ts +15 -0
  113. package/dist/kinds/react/useLiveJsonRegion.js +84 -0
  114. package/dist/kinds/redux/render-block-envelope.d.ts +14 -0
  115. package/dist/kinds/redux/render-block-envelope.js +26 -0
  116. package/dist/kinds/registry/kind-correctors.d.ts +63 -0
  117. package/dist/kinds/registry/kind-correctors.js +94 -0
  118. package/dist/kinds/registry/legacy-quiz-envelope.d.ts +1 -0
  119. package/dist/kinds/registry/legacy-quiz-envelope.js +1 -0
  120. package/dist/kinds/registry/region-envelope-memo.d.ts +45 -0
  121. package/dist/kinds/registry/region-envelope-memo.js +94 -0
  122. package/dist/kinds/registry/registry-debug.d.ts +38 -0
  123. package/dist/kinds/registry/registry-debug.js +39 -0
  124. package/dist/markdown-core/MarkdownCore.d.ts +6 -0
  125. package/dist/markdown-core/MarkdownCore.js +32 -0
  126. package/dist/markdown-core/MarkdownCoreImpl.d.ts +3 -0
  127. package/dist/markdown-core/MarkdownCoreImpl.js +27 -0
  128. package/dist/markdown-core/MarkdownCoreServer.d.ts +4 -0
  129. package/dist/markdown-core/MarkdownCoreServer.js +26 -0
  130. package/dist/markdown-core/heading-anchors-context.d.ts +2 -0
  131. package/dist/markdown-core/heading-anchors-context.js +11 -0
  132. package/dist/markdown-core/heading-anchors-props.d.ts +2 -0
  133. package/dist/markdown-core/heading-anchors-props.js +6 -0
  134. package/dist/markdown-core/markdown-core-html.d.ts +3 -0
  135. package/dist/markdown-core/markdown-core-html.js +33 -0
  136. package/dist/markdown-core/markdown-core-presets.d.ts +22 -0
  137. package/dist/markdown-core/markdown-core-presets.js +118 -0
  138. package/dist/markdown-core/markdown-core-types.d.ts +43 -0
  139. package/dist/markdown-core/markdown-core-types.js +0 -0
  140. package/dist/markdown-core/math/vendor/micromark-math-math-flow.d.ts +15 -0
  141. package/dist/markdown-core/math/vendor/micromark-math-math-flow.js +143 -0
  142. package/dist/markdown-core/math/vendor/micromark-math-math-text.d.ts +24 -0
  143. package/dist/markdown-core/math/vendor/micromark-math-math-text.js +127 -0
  144. package/dist/markdown-core/math/vendor/micromark-math-syntax.d.ts +30 -0
  145. package/dist/markdown-core/math/vendor/micromark-math-syntax.js +15 -0
  146. package/dist/markdown-core/math/vendor/rehype-katex.d.ts +15 -0
  147. package/dist/markdown-core/math/vendor/rehype-katex.js +83 -0
  148. package/dist/markdown-core/math/vendor/remark-math.d.ts +9 -0
  149. package/dist/markdown-core/math/vendor/remark-math.js +20 -0
  150. package/dist/markdown-core/math-normalizer.d.ts +57 -0
  151. package/dist/markdown-core/math-normalizer.js +315 -0
  152. package/dist/markdown-core/plain-title.d.ts +2 -0
  153. package/dist/markdown-core/plain-title.js +1 -0
  154. package/dist/markdown-core/stream-heal.d.ts +2 -0
  155. package/dist/markdown-core/stream-heal.js +184 -0
  156. package/dist/markdown-core/streaming-context.d.ts +2 -0
  157. package/dist/markdown-core/streaming-context.js +11 -0
  158. package/dist/markdown-core/syntax/callout-types.d.ts +9 -0
  159. package/dist/markdown-core/syntax/callout-types.js +101 -0
  160. package/dist/markdown-core/syntax/containers.d.ts +17 -0
  161. package/dist/markdown-core/syntax/containers.js +353 -0
  162. package/dist/markdown-core/syntax/document-numbering.d.ts +52 -0
  163. package/dist/markdown-core/syntax/document-numbering.js +184 -0
  164. package/dist/markdown-core/syntax/elements/CalloutIcon.d.ts +3 -0
  165. package/dist/markdown-core/syntax/elements/CalloutIcon.js +41 -0
  166. package/dist/markdown-core/syntax/elements/CrossRef.d.ts +12 -0
  167. package/dist/markdown-core/syntax/elements/CrossRef.js +57 -0
  168. package/dist/markdown-core/syntax/elements/CsvFence.d.ts +4 -0
  169. package/dist/markdown-core/syntax/elements/CsvFence.js +18 -0
  170. package/dist/markdown-core/syntax/elements/DetailsElements.d.ts +12 -0
  171. package/dist/markdown-core/syntax/elements/DetailsElements.js +38 -0
  172. package/dist/markdown-core/syntax/elements/DocumentNumbering.d.ts +20 -0
  173. package/dist/markdown-core/syntax/elements/DocumentNumbering.js +37 -0
  174. package/dist/markdown-core/syntax/elements/DocumentPropertiesPanel.d.ts +4 -0
  175. package/dist/markdown-core/syntax/elements/DocumentPropertiesPanel.js +46 -0
  176. package/dist/markdown-core/syntax/elements/InDocAnchor.d.ts +11 -0
  177. package/dist/markdown-core/syntax/elements/InDocAnchor.js +87 -0
  178. package/dist/markdown-core/syntax/elements/MarkdownSourceEdit.d.ts +24 -0
  179. package/dist/markdown-core/syntax/elements/MarkdownSourceEdit.js +28 -0
  180. package/dist/markdown-core/syntax/elements/MatrxTabs.d.ts +10 -0
  181. package/dist/markdown-core/syntax/elements/MatrxTabs.js +59 -0
  182. package/dist/markdown-core/syntax/elements/MentionChip.d.ts +7 -0
  183. package/dist/markdown-core/syntax/elements/MentionChip.js +69 -0
  184. package/dist/markdown-core/syntax/elements/NestedBody.d.ts +3 -0
  185. package/dist/markdown-core/syntax/elements/NestedBody.js +13 -0
  186. package/dist/markdown-core/syntax/elements/TableOfContents.d.ts +5 -0
  187. package/dist/markdown-core/syntax/elements/TableOfContents.js +44 -0
  188. package/dist/markdown-core/syntax/elements/TaskCheckbox.d.ts +7 -0
  189. package/dist/markdown-core/syntax/elements/TaskCheckbox.js +63 -0
  190. package/dist/markdown-core/syntax/elements/WikiEmbed.d.ts +7 -0
  191. package/dist/markdown-core/syntax/elements/WikiEmbed.js +68 -0
  192. package/dist/markdown-core/syntax/elements/WikiLink.d.ts +10 -0
  193. package/dist/markdown-core/syntax/elements/WikiLink.js +114 -0
  194. package/dist/markdown-core/syntax/elements/core-syntax-elements.d.ts +22 -0
  195. package/dist/markdown-core/syntax/elements/core-syntax-elements.js +70 -0
  196. package/dist/markdown-core/syntax/elements/find-in-document.d.ts +3 -0
  197. package/dist/markdown-core/syntax/elements/find-in-document.js +20 -0
  198. package/dist/markdown-core/syntax/elements/wiki-target.d.ts +5 -0
  199. package/dist/markdown-core/syntax/elements/wiki-target.js +8 -0
  200. package/dist/markdown-core/syntax/frontmatter.d.ts +26 -0
  201. package/dist/markdown-core/syntax/frontmatter.js +72 -0
  202. package/dist/markdown-core/syntax/gfm-cell-pipes.d.ts +11 -0
  203. package/dist/markdown-core/syntax/gfm-cell-pipes.js +4 -0
  204. package/dist/markdown-core/syntax/inline-syntax.d.ts +26 -0
  205. package/dist/markdown-core/syntax/inline-syntax.js +163 -0
  206. package/dist/markdown-core/syntax/linear-scan.d.ts +46 -0
  207. package/dist/markdown-core/syntax/linear-scan.js +129 -0
  208. package/dist/markdown-core/syntax/mdast-helpers.d.ts +48 -0
  209. package/dist/markdown-core/syntax/mdast-helpers.js +48 -0
  210. package/dist/markdown-core/syntax/mentions.d.ts +2 -0
  211. package/dist/markdown-core/syntax/mentions.js +42 -0
  212. package/dist/markdown-core/syntax/names.d.ts +6 -0
  213. package/dist/markdown-core/syntax/names.js +18 -0
  214. package/dist/markdown-core/syntax/prepare-syntax-source.d.ts +1 -0
  215. package/dist/markdown-core/syntax/prepare-syntax-source.js +78 -0
  216. package/dist/markdown-core/syntax/rehype-matrx-syntax.d.ts +9 -0
  217. package/dist/markdown-core/syntax/rehype-matrx-syntax.js +180 -0
  218. package/dist/markdown-core/syntax/remark-inline-only.d.ts +23 -0
  219. package/dist/markdown-core/syntax/remark-inline-only.js +25 -0
  220. package/dist/markdown-core/syntax/remark-matrx-syntax.d.ts +7 -0
  221. package/dist/markdown-core/syntax/remark-matrx-syntax.js +351 -0
  222. package/dist/markdown-core/syntax/remark-table-code-pipes.d.ts +7 -0
  223. package/dist/markdown-core/syntax/remark-table-code-pipes.js +23 -0
  224. package/dist/markdown-core/syntax/stream-heal-syntax.d.ts +2 -0
  225. package/dist/markdown-core/syntax/stream-heal-syntax.js +108 -0
  226. package/dist/markdown-core/syntax/task-source.d.ts +10 -0
  227. package/dist/markdown-core/syntax/task-source.js +34 -0
  228. package/dist/markdown-core/syntax/useDocumentProperties.d.ts +3 -0
  229. package/dist/markdown-core/syntax/useDocumentProperties.js +8 -0
  230. package/dist/styles.css +0 -0
  231. package/dist/utils/addressWithoutNavigating.d.ts +68 -0
  232. package/dist/utils/addressWithoutNavigating.js +60 -0
  233. package/dist/utils/client-lazy.d.ts +13 -0
  234. package/dist/utils/client-lazy.js +24 -0
  235. package/dist/utils/decision-options.d.ts +21 -0
  236. package/dist/utils/decision-options.js +32 -0
  237. package/dist/utils/gfm-lexer.d.ts +5 -0
  238. package/dist/utils/gfm-lexer.js +10 -0
  239. package/dist/utils/json.d.ts +63 -0
  240. package/dist/utils/json.js +22 -0
  241. package/dist/utils/plain-title.d.ts +25 -0
  242. package/dist/utils/plain-title.js +51 -0
  243. package/dist/utils/table-source.d.ts +62 -0
  244. package/dist/utils/table-source.js +191 -0
  245. package/dist/utils/youtube.d.ts +52 -0
  246. package/dist/utils/youtube.js +137 -0
  247. package/package.json +134 -4
@@ -0,0 +1,26 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import "server-only";
3
+ import ReactMarkdown from "react-markdown";
4
+ import "katex/dist/katex.min.css";
5
+ import { MARKDOWN_PRESETS, prepareCoreSource, rehypeWithNumbering, remarkWithNumbering } from "./markdown-core-presets.js";
6
+ import { withCoreSyntaxElements } from "./syntax/elements/core-syntax-elements.js";
7
+ function MarkdownCoreServer({
8
+ children,
9
+ preset = "gfm",
10
+ components,
11
+ numbering
12
+ }) {
13
+ const plugins = MARKDOWN_PRESETS[preset];
14
+ return /* @__PURE__ */ jsx(
15
+ ReactMarkdown,
16
+ {
17
+ remarkPlugins: remarkWithNumbering(plugins.remark, numbering),
18
+ rehypePlugins: rehypeWithNumbering(plugins.rehype, numbering),
19
+ components: withCoreSyntaxElements(components),
20
+ children: prepareCoreSource(children, preset, numbering)
21
+ }
22
+ );
23
+ }
24
+ export {
25
+ MarkdownCoreServer as default
26
+ };
@@ -0,0 +1,2 @@
1
+ export declare const HeadingAnchorsProvider: import("react").Provider<boolean>;
2
+ export declare function useHeadingAnchors(): boolean;
@@ -0,0 +1,11 @@
1
+ "use client";
2
+ import { createContext, useContext } from "react";
3
+ const HeadingAnchorsContext = createContext(true);
4
+ const HeadingAnchorsProvider = HeadingAnchorsContext.Provider;
5
+ function useHeadingAnchors() {
6
+ return useContext(HeadingAnchorsContext);
7
+ }
8
+ export {
9
+ HeadingAnchorsProvider,
10
+ useHeadingAnchors
11
+ };
@@ -0,0 +1,2 @@
1
+ /** True for the element props of a heading hover anchor. */
2
+ export declare function isHeadingAnchorProps(props: object): boolean;
@@ -0,0 +1,6 @@
1
+ function isHeadingAnchorProps(props) {
2
+ return "data-heading-anchor" in props;
3
+ }
4
+ export {
5
+ isHeadingAnchorProps
6
+ };
@@ -0,0 +1,3 @@
1
+ import type { Root } from "hast";
2
+ /** Markdown → the core's HTML tree (unsanitized; sanitize before serializing). */
3
+ export declare function markdownToHast(markdown: string): Root;
@@ -0,0 +1,33 @@
1
+ import { unified } from "unified";
2
+ import remarkParse from "remark-parse";
3
+ import remarkRehype from "remark-rehype";
4
+ import rehypeRaw from "rehype-raw";
5
+ import { MARKDOWN_PRESETS, prepareCoreSource } from "./markdown-core-presets.js";
6
+ const PRESET = "gfm";
7
+ const processor = unified().use(remarkParse).use(MARKDOWN_PRESETS[PRESET].remark ?? []).use(remarkRehype, { allowDangerousHtml: true }).use(rehypeRaw).use(MARKDOWN_PRESETS[PRESET].rehype ?? []);
8
+ const HEADING = /^h[1-6]$/;
9
+ function dropHeadingAnchors(nodes) {
10
+ return nodes.filter((node) => {
11
+ if (node.type !== "element" || node.tagName !== "a") return true;
12
+ const href = String(node.properties?.href ?? "");
13
+ return !(href.startsWith("#") && node.children.length === 0);
14
+ }).map((node) => {
15
+ if (node.type === "element") {
16
+ const id = node.properties?.id;
17
+ if (HEADING.test(node.tagName) && typeof id === "string" && id.startsWith("user-content-")) {
18
+ delete node.properties.id;
19
+ }
20
+ node.children = dropHeadingAnchors(node.children);
21
+ }
22
+ return node;
23
+ });
24
+ }
25
+ function markdownToHast(markdown) {
26
+ const source = prepareCoreSource(markdown, PRESET);
27
+ const tree = processor.runSync(processor.parse(source));
28
+ tree.children = dropHeadingAnchors(tree.children);
29
+ return tree;
30
+ }
31
+ export {
32
+ markdownToHast
33
+ };
@@ -0,0 +1,22 @@
1
+ import "katex/contrib/mhchem";
2
+ import type { DocumentNumbering } from "./syntax/document-numbering.js";
3
+ import type { Options } from "react-markdown";
4
+ import type { MarkdownPreset } from "./markdown-core-types.js";
5
+ export type MarkdownPluginSet = {
6
+ remark: Options["remarkPlugins"];
7
+ rehype: Options["rehypePlugins"];
8
+ /** Math-capable presets run the ONE math normalizer on their source. */
9
+ math: boolean;
10
+ };
11
+ /** Module-scope arrays so plugin identity is stable across renders. */
12
+ export declare const MARKDOWN_PRESETS: Record<MarkdownPreset, MarkdownPluginSet>;
13
+ /**
14
+ * A preset's remark list with the document-wide numbering handed to the
15
+ * extended-syntax pass, so every block of a split document numbers figures,
16
+ * tables and equations the same way. No numbering → the module-scope list.
17
+ */
18
+ export declare function remarkWithNumbering(remark: Options["remarkPlugins"], numbering: DocumentNumbering | null | undefined): Options["remarkPlugins"];
19
+ /** A preset's rehype list with the document-wide numbering (footnotes) handed to the extended-syntax pass. */
20
+ export declare function rehypeWithNumbering(rehype: Options["rehypePlugins"], numbering: DocumentNumbering | null | undefined): Options["rehypePlugins"];
21
+ /** The source a preset parses: math presets run the one normalizer. */
22
+ export declare function prepareCoreSource(source: string, preset: MarkdownPreset, numbering?: DocumentNumbering | null): string;
@@ -0,0 +1,118 @@
1
+ import remarkGfm from "remark-gfm";
2
+ import remarkTableCodePipes from "./syntax/remark-table-code-pipes.js";
3
+ import remarkInlineOnly from "./syntax/remark-inline-only.js";
4
+ import remarkBreaks from "remark-breaks";
5
+ import remarkMath from "./math/vendor/remark-math.js";
6
+ import rehypeKatex from "./math/vendor/rehype-katex.js";
7
+ import rehypeRaw from "rehype-raw";
8
+ import remarkMatrxVariable from "../display/chat-markdown/matrx-variables/remarkMatrxVariable.js";
9
+ import remarkMatrxCite from "../display/chat-markdown/citations/remarkMatrxCite.js";
10
+ import rehypeSafeRawHtml from "../display/chat-markdown/rehypeSafeRawHtml.js";
11
+ import remarkMatrxPageBreak, {
12
+ isolatePageBreakLines
13
+ } from "../display/chat-markdown/page-break/remarkMatrxPageBreak.js";
14
+ import remarkFrontmatter from "remark-frontmatter";
15
+ import remarkDirective from "remark-directive";
16
+ import { remarkDefinitionList } from "remark-definition-list";
17
+ import remarkGemoji from "remark-gemoji";
18
+ import rehypeSlug from "rehype-slug";
19
+ import "katex/contrib/mhchem";
20
+ import remarkMatrxSyntax from "./syntax/remark-matrx-syntax.js";
21
+ import rehypeMatrxSyntax from "./syntax/rehype-matrx-syntax.js";
22
+ import { rewriteContainerSpellings } from "./syntax/prepare-syntax-source.js";
23
+ import { collectLinkDefinitions, fenceLineKinds, resolveReferenceLinks } from "@ai-matrx/content-ir/source";
24
+ import {
25
+ normalizeMathDelimiters,
26
+ REHYPE_KATEX_OPTIONS,
27
+ REMARK_MATH_OPTIONS
28
+ } from "./math-normalizer.js";
29
+ const MATH = [remarkMath, REMARK_MATH_OPTIONS];
30
+ const KATEX = [rehypeKatex, REHYPE_KATEX_OPTIONS];
31
+ const PAGE_BREAK = remarkMatrxPageBreak;
32
+ const GFM = [remarkGfm, { singleTilde: false }];
33
+ const SYNTAX_PARSE = [[remarkFrontmatter, ["yaml", "toml"]], remarkDirective, remarkDefinitionList];
34
+ const SYNTAX_TRANSFORM = [remarkTableCodePipes, remarkMatrxSyntax, remarkGemoji];
35
+ const SYNTAX_REHYPE = [rehypeSlug, rehypeMatrxSyntax];
36
+ const MARKDOWN_PRESETS = {
37
+ plain: { remark: [], rehype: [], math: false },
38
+ gfm: { remark: [GFM, ...SYNTAX_PARSE, PAGE_BREAK, ...SYNTAX_TRANSFORM], rehype: [...SYNTAX_REHYPE], math: false },
39
+ "gfm-breaks": {
40
+ remark: [GFM, remarkBreaks, ...SYNTAX_PARSE, PAGE_BREAK, ...SYNTAX_TRANSFORM],
41
+ rehype: [...SYNTAX_REHYPE],
42
+ math: false
43
+ },
44
+ math: { remark: [MATH, PAGE_BREAK], rehype: [KATEX], math: true },
45
+ "gfm-math": {
46
+ remark: [GFM, MATH, ...SYNTAX_PARSE, PAGE_BREAK, ...SYNTAX_TRANSFORM],
47
+ rehype: [...SYNTAX_REHYPE, KATEX],
48
+ math: true
49
+ },
50
+ rich: {
51
+ remark: [GFM, remarkBreaks, MATH, ...SYNTAX_PARSE, PAGE_BREAK, ...SYNTAX_TRANSFORM],
52
+ rehype: [...SYNTAX_REHYPE, KATEX],
53
+ math: true
54
+ },
55
+ chat: {
56
+ remark: [
57
+ GFM,
58
+ remarkBreaks,
59
+ MATH,
60
+ ...SYNTAX_PARSE,
61
+ remarkMatrxVariable,
62
+ remarkMatrxCite,
63
+ PAGE_BREAK,
64
+ ...SYNTAX_TRANSFORM
65
+ ],
66
+ // Parse + sanitize allow-listed raw HTML BEFORE KaTeX, so KaTeX's
67
+ // rendered output is never sanitized and matrx-variable / math element
68
+ // nodes are never touched.
69
+ rehype: [rehypeSafeRawHtml, ...SYNTAX_REHYPE, KATEX],
70
+ math: true
71
+ },
72
+ // One GFM table cell: the chat preset with every block construct off
73
+ // (verify-RC-B4 R6-1) — `> 90%` / `- n/a` / `# 3` read as the text they are.
74
+ "chat-cell": {
75
+ remark: [
76
+ remarkInlineOnly,
77
+ GFM,
78
+ remarkBreaks,
79
+ MATH,
80
+ ...SYNTAX_PARSE,
81
+ remarkMatrxVariable,
82
+ remarkMatrxCite,
83
+ PAGE_BREAK,
84
+ ...SYNTAX_TRANSFORM
85
+ ],
86
+ rehype: [rehypeSafeRawHtml, ...SYNTAX_REHYPE, KATEX],
87
+ math: true
88
+ },
89
+ message: {
90
+ remark: [GFM, MATH, remarkBreaks, ...SYNTAX_PARSE, PAGE_BREAK, ...SYNTAX_TRANSFORM],
91
+ rehype: [rehypeRaw, ...SYNTAX_REHYPE, KATEX],
92
+ math: true
93
+ }
94
+ };
95
+ function remarkWithNumbering(remark, numbering) {
96
+ if (!numbering || !remark) return remark;
97
+ return remark.map((plugin) => plugin === remarkMatrxSyntax ? [remarkMatrxSyntax, { numbering }] : plugin);
98
+ }
99
+ function rehypeWithNumbering(rehype, numbering) {
100
+ if (!numbering || !rehype) return rehype;
101
+ return rehype.map((plugin) => plugin === rehypeMatrxSyntax ? [rehypeMatrxSyntax, { numbering }] : plugin);
102
+ }
103
+ function prepareCoreSource(source, preset, numbering) {
104
+ if (preset === "plain") return source;
105
+ if (numbering?.linkDefinitions && source.includes("[")) {
106
+ const defs = collectLinkDefinitions(numbering.linkDefinitions);
107
+ const kinds = fenceLineKinds(source);
108
+ source = source.split("\n").map((line, i) => kinds[i] === "prose" ? resolveReferenceLinks(line, defs) : line).join("\n");
109
+ }
110
+ const isolated = isolatePageBreakLines(rewriteContainerSpellings(source));
111
+ return MARKDOWN_PRESETS[preset].math ? normalizeMathDelimiters(isolated) : isolated;
112
+ }
113
+ export {
114
+ MARKDOWN_PRESETS,
115
+ prepareCoreSource,
116
+ rehypeWithNumbering,
117
+ remarkWithNumbering
118
+ };
@@ -0,0 +1,43 @@
1
+ import type { Components } from "react-markdown";
2
+ import type { DocumentNumbering } from "./syntax/document-numbering.js";
3
+ /**
4
+ * Plugin presets for the ONE shared react-markdown edge (MarkdownCore).
5
+ * Every preset's plugin array lives in MarkdownCoreImpl — callers pick a
6
+ * preset by name so plugin imports never enter caller graphs. Adding a
7
+ * one-off plugin combination? Add a preset here + in the Impl; never
8
+ * import react-markdown or a remark/rehype plugin from a component again.
9
+ *
10
+ * - plain: no plugins
11
+ * - gfm: remark-gfm
12
+ * - gfm-breaks: remark-gfm + remark-breaks
13
+ * - math: math only
14
+ * - gfm-math: gfm + math
15
+ * - rich: gfm + breaks + math
16
+ * - chat: rich + matrx variables + matrx citations + safe raw HTML
17
+ * - chat-cell: chat, INLINE constructs only — one GFM table cell (remark-inline-only)
18
+ * - message: gfm + math + breaks + rehype-raw
19
+ *
20
+ * "math" everywhere means the ONE dialect in math-normalizer.ts: the source
21
+ * is normalized (`\(…\)` inline, `\[…\]` display, unambiguous `$…$`,
22
+ * code untouched) and remark-math/rehype-katex run with the shared options.
23
+ */
24
+ export type MarkdownPreset = "plain" | "gfm" | "gfm-breaks" | "math" | "gfm-math" | "rich" | "chat" | "chat-cell" | "message";
25
+ /** The element-override map a caller may pass to the core — import THIS, never react-markdown's own type. */
26
+ export type MarkdownComponents = Components;
27
+ export interface MarkdownCoreProps {
28
+ children: string;
29
+ preset?: MarkdownPreset;
30
+ components?: Components;
31
+ /**
32
+ * The text is still streaming in: heal half-arrived syntax before parse.
33
+ * Omit to inherit from the nearest MarkdownStreamingProvider (false outside
34
+ * a live stream); finished text is never healed.
35
+ */
36
+ streaming?: boolean;
37
+ /**
38
+ * Server renderer only: the document-wide numbering of the whole document
39
+ * this block belongs to (`computeDocumentNumbering`). Client leaves read it
40
+ * from the nearest DocumentNumberingProvider instead.
41
+ */
42
+ numbering?: DocumentNumbering | null;
43
+ }
File without changes
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @import {Construct, State, TokenizeContext, Tokenizer} from 'micromark-util-types'
3
+ */
4
+ /** @type {Construct} */
5
+ export declare const mathFlow: {
6
+ tokenize: typeof tokenizeMathFenced;
7
+ concrete: boolean;
8
+ name: string;
9
+ };
10
+ /**
11
+ * @this {TokenizeContext}
12
+ * @type {Tokenizer}
13
+ */
14
+ declare function tokenizeMathFenced(effects: any, ok: any, nok: any): (code: any) => any;
15
+ export {};
@@ -0,0 +1,143 @@
1
+ import { factorySpace } from "micromark-factory-space";
2
+ import { markdownLineEnding } from "micromark-util-character";
3
+ const mathFlow = {
4
+ tokenize: tokenizeMathFenced,
5
+ concrete: true,
6
+ name: "mathFlow"
7
+ };
8
+ const nonLazyContinuation = {
9
+ tokenize: tokenizeNonLazyContinuation,
10
+ partial: true
11
+ };
12
+ function tokenizeMathFenced(effects, ok, nok) {
13
+ const self = this;
14
+ const tail = self.events[self.events.length - 1];
15
+ const initialSize = tail && tail[1].type === "linePrefix" ? tail[2].sliceSerialize(tail[1], true).length : 0;
16
+ let sizeOpen = 0;
17
+ return start;
18
+ function start(code) {
19
+ effects.enter("mathFlow");
20
+ effects.enter("mathFlowFence");
21
+ effects.enter("mathFlowFenceSequence");
22
+ return sequenceOpen(code);
23
+ }
24
+ function sequenceOpen(code) {
25
+ if (code === 36) {
26
+ effects.consume(code);
27
+ sizeOpen++;
28
+ return sequenceOpen;
29
+ }
30
+ if (sizeOpen < 2) {
31
+ return nok(code);
32
+ }
33
+ effects.exit("mathFlowFenceSequence");
34
+ return factorySpace(effects, metaBefore, "whitespace")(code);
35
+ }
36
+ function metaBefore(code) {
37
+ if (code === null || markdownLineEnding(code)) {
38
+ return metaAfter(code);
39
+ }
40
+ effects.enter("mathFlowFenceMeta");
41
+ effects.enter("chunkString", {
42
+ contentType: "string"
43
+ });
44
+ return meta(code);
45
+ }
46
+ function meta(code) {
47
+ if (code === null || markdownLineEnding(code)) {
48
+ effects.exit("chunkString");
49
+ effects.exit("mathFlowFenceMeta");
50
+ return metaAfter(code);
51
+ }
52
+ if (code === 36) {
53
+ return nok(code);
54
+ }
55
+ effects.consume(code);
56
+ return meta;
57
+ }
58
+ function metaAfter(code) {
59
+ effects.exit("mathFlowFence");
60
+ if (self.interrupt) {
61
+ return ok(code);
62
+ }
63
+ return effects.attempt(nonLazyContinuation, beforeNonLazyContinuation, after)(code);
64
+ }
65
+ function beforeNonLazyContinuation(code) {
66
+ return effects.attempt({
67
+ tokenize: tokenizeClosingFence,
68
+ partial: true
69
+ }, after, contentStart)(code);
70
+ }
71
+ function contentStart(code) {
72
+ return (initialSize ? factorySpace(effects, beforeContentChunk, "linePrefix", initialSize + 1) : beforeContentChunk)(code);
73
+ }
74
+ function beforeContentChunk(code) {
75
+ if (code === null) {
76
+ return after(code);
77
+ }
78
+ if (markdownLineEnding(code)) {
79
+ return effects.attempt(nonLazyContinuation, beforeNonLazyContinuation, after)(code);
80
+ }
81
+ effects.enter("mathFlowValue");
82
+ return contentChunk(code);
83
+ }
84
+ function contentChunk(code) {
85
+ if (code === null || markdownLineEnding(code)) {
86
+ effects.exit("mathFlowValue");
87
+ return beforeContentChunk(code);
88
+ }
89
+ effects.consume(code);
90
+ return contentChunk;
91
+ }
92
+ function after(code) {
93
+ effects.exit("mathFlow");
94
+ return ok(code);
95
+ }
96
+ function tokenizeClosingFence(effects2, ok2, nok2) {
97
+ let size = 0;
98
+ return factorySpace(effects2, beforeSequenceClose, "linePrefix", self.parser.constructs.disable.null.includes("codeIndented") ? void 0 : 4);
99
+ function beforeSequenceClose(code) {
100
+ effects2.enter("mathFlowFence");
101
+ effects2.enter("mathFlowFenceSequence");
102
+ return sequenceClose(code);
103
+ }
104
+ function sequenceClose(code) {
105
+ if (code === 36) {
106
+ size++;
107
+ effects2.consume(code);
108
+ return sequenceClose;
109
+ }
110
+ if (size < sizeOpen) {
111
+ return nok2(code);
112
+ }
113
+ effects2.exit("mathFlowFenceSequence");
114
+ return factorySpace(effects2, afterSequenceClose, "whitespace")(code);
115
+ }
116
+ function afterSequenceClose(code) {
117
+ if (code === null || markdownLineEnding(code)) {
118
+ effects2.exit("mathFlowFence");
119
+ return ok2(code);
120
+ }
121
+ return nok2(code);
122
+ }
123
+ }
124
+ }
125
+ function tokenizeNonLazyContinuation(effects, ok, nok) {
126
+ const self = this;
127
+ return start;
128
+ function start(code) {
129
+ if (code === null) {
130
+ return ok(code);
131
+ }
132
+ effects.enter("lineEnding");
133
+ effects.consume(code);
134
+ effects.exit("lineEnding");
135
+ return lineStart;
136
+ }
137
+ function lineStart(code) {
138
+ return self.parser.lazy[self.now().line] ? nok(code) : ok(code);
139
+ }
140
+ }
141
+ export {
142
+ mathFlow
143
+ };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @import {Options} from 'micromark-extension-math'
3
+ * @import {Construct, Previous, Resolver, State, Token, TokenizeContext, Tokenizer} from 'micromark-util-types'
4
+ */
5
+ /**
6
+ * @param {Options | null | undefined} [options={}]
7
+ * Configuration (default: `{}`).
8
+ * @returns {Construct}
9
+ * Construct.
10
+ */
11
+ export declare function mathText(options: any): {
12
+ tokenize: (effects: any, ok: any, nok: any) => (code: any) => any;
13
+ resolve: typeof resolveMathText;
14
+ previous: typeof previous;
15
+ name: string;
16
+ };
17
+ /** @type {Resolver} */
18
+ declare function resolveMathText(events: any): any;
19
+ /**
20
+ * @this {TokenizeContext}
21
+ * @type {Previous}
22
+ */
23
+ declare function previous(code: any): boolean;
24
+ export {};
@@ -0,0 +1,127 @@
1
+ import { markdownLineEnding } from "micromark-util-character";
2
+ function mathText(options) {
3
+ const options_ = options || {};
4
+ let single = options_.singleDollarTextMath;
5
+ if (single === null || single === void 0) {
6
+ single = true;
7
+ }
8
+ return {
9
+ tokenize: tokenizeMathText,
10
+ resolve: resolveMathText,
11
+ previous,
12
+ name: "mathText"
13
+ };
14
+ function tokenizeMathText(effects, ok, nok) {
15
+ const self = this;
16
+ let sizeOpen = 0;
17
+ let size;
18
+ let token;
19
+ return start;
20
+ function start(code) {
21
+ effects.enter("mathText");
22
+ effects.enter("mathTextSequence");
23
+ return sequenceOpen(code);
24
+ }
25
+ function sequenceOpen(code) {
26
+ if (code === 36) {
27
+ effects.consume(code);
28
+ sizeOpen++;
29
+ return sequenceOpen;
30
+ }
31
+ if (sizeOpen < 2 && !single) {
32
+ return nok(code);
33
+ }
34
+ effects.exit("mathTextSequence");
35
+ return between(code);
36
+ }
37
+ function between(code) {
38
+ if (code === null) {
39
+ return nok(code);
40
+ }
41
+ if (code === 36) {
42
+ token = effects.enter("mathTextSequence");
43
+ size = 0;
44
+ return sequenceClose(code);
45
+ }
46
+ if (code === 32) {
47
+ effects.enter("space");
48
+ effects.consume(code);
49
+ effects.exit("space");
50
+ return between;
51
+ }
52
+ if (markdownLineEnding(code)) {
53
+ effects.enter("lineEnding");
54
+ effects.consume(code);
55
+ effects.exit("lineEnding");
56
+ return between;
57
+ }
58
+ effects.enter("mathTextData");
59
+ return data(code);
60
+ }
61
+ function data(code) {
62
+ if (code === null || code === 32 || code === 36 || markdownLineEnding(code)) {
63
+ effects.exit("mathTextData");
64
+ return between(code);
65
+ }
66
+ effects.consume(code);
67
+ return data;
68
+ }
69
+ function sequenceClose(code) {
70
+ if (code === 36) {
71
+ effects.consume(code);
72
+ size++;
73
+ return sequenceClose;
74
+ }
75
+ if (size === sizeOpen) {
76
+ effects.exit("mathTextSequence");
77
+ effects.exit("mathText");
78
+ return ok(code);
79
+ }
80
+ token.type = "mathTextData";
81
+ return data(code);
82
+ }
83
+ }
84
+ }
85
+ function resolveMathText(events) {
86
+ let tailExitIndex = events.length - 4;
87
+ let headEnterIndex = 3;
88
+ let index;
89
+ let enter;
90
+ if ((events[headEnterIndex][1].type === "lineEnding" || events[headEnterIndex][1].type === "space") && (events[tailExitIndex][1].type === "lineEnding" || events[tailExitIndex][1].type === "space")) {
91
+ index = headEnterIndex;
92
+ while (++index < tailExitIndex) {
93
+ if (events[index][1].type === "mathTextData") {
94
+ events[tailExitIndex][1].type = "mathTextPadding";
95
+ events[headEnterIndex][1].type = "mathTextPadding";
96
+ headEnterIndex += 2;
97
+ tailExitIndex -= 2;
98
+ break;
99
+ }
100
+ }
101
+ }
102
+ index = headEnterIndex - 1;
103
+ tailExitIndex++;
104
+ while (++index <= tailExitIndex) {
105
+ if (enter === void 0) {
106
+ if (index !== tailExitIndex && events[index][1].type !== "lineEnding") {
107
+ enter = index;
108
+ }
109
+ } else if (index === tailExitIndex || events[index][1].type === "lineEnding") {
110
+ events[enter][1].type = "mathTextData";
111
+ if (index !== enter + 2) {
112
+ events[enter][1].end = events[index - 1][1].end;
113
+ events.splice(enter + 2, index - enter - 2);
114
+ tailExitIndex -= index - enter - 2;
115
+ index = enter + 2;
116
+ }
117
+ enter = void 0;
118
+ }
119
+ }
120
+ return events;
121
+ }
122
+ function previous(code) {
123
+ return code !== 36 || this.events[this.events.length - 1][1].type === "characterEscape";
124
+ }
125
+ export {
126
+ mathText
127
+ };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @import {Options} from 'micromark-extension-math'
3
+ * @import {Extension} from 'micromark-util-types'
4
+ */
5
+ /**
6
+ * Create an extension for `micromark` to enable math syntax.
7
+ *
8
+ * @param {Options | null | undefined} [options={}]
9
+ * Configuration (default: `{}`).
10
+ * @returns {Extension}
11
+ * Extension for `micromark` that can be passed in `extensions`, to
12
+ * enable math syntax.
13
+ */
14
+ export declare function math(options: any): {
15
+ flow: {
16
+ [36]: {
17
+ tokenize: (effects: any, ok: any, nok: any) => (code: any) => any;
18
+ concrete: boolean;
19
+ name: string;
20
+ };
21
+ };
22
+ text: {
23
+ [36]: {
24
+ tokenize: (effects: any, ok: any, nok: any) => (code: any) => any;
25
+ resolve: (events: any) => any;
26
+ previous: (code: any) => boolean;
27
+ name: string;
28
+ };
29
+ };
30
+ };
@@ -0,0 +1,15 @@
1
+ import { mathFlow } from "./micromark-math-math-flow.js";
2
+ import { mathText } from "./micromark-math-math-text.js";
3
+ function math(options) {
4
+ return {
5
+ flow: {
6
+ [36]: mathFlow
7
+ },
8
+ text: {
9
+ [36]: mathText(options)
10
+ }
11
+ };
12
+ }
13
+ export {
14
+ math
15
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @import {ElementContent, Root} from 'hast'
3
+ * @import {KatexOptions} from 'katex'
4
+ * @import {VFile} from 'vfile'
5
+ */
6
+ /**
7
+ * Render elements with a `language-math` (or `math-display`, `math-inline`)
8
+ * class with KaTeX.
9
+ *
10
+ * @param {Readonly<Options> | null | undefined} [options]
11
+ * Configuration (optional).
12
+ * @returns
13
+ * Transform.
14
+ */
15
+ export default function rehypeKatex(options: any): (tree: any, file: any) => void;