@tinacms/mdx 0.0.0-00d7b85-20251222014449

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 (159) hide show
  1. package/LICENSE +176 -0
  2. package/dist/extensions/tina-shortcodes/extension.d.ts +3 -0
  3. package/dist/extensions/tina-shortcodes/factory-attributes.d.ts +2 -0
  4. package/dist/extensions/tina-shortcodes/factory-name.d.ts +2 -0
  5. package/dist/extensions/tina-shortcodes/from-markdown.d.ts +2 -0
  6. package/dist/extensions/tina-shortcodes/shortcode-container.d.ts +3 -0
  7. package/dist/extensions/tina-shortcodes/shortcode-leaf.d.ts +5 -0
  8. package/dist/extensions/tina-shortcodes/to-markdown.d.ts +3 -0
  9. package/dist/index.browser.js +43058 -0
  10. package/dist/index.d.ts +5 -0
  11. package/dist/index.js +44924 -0
  12. package/dist/next/index.d.ts +2 -0
  13. package/dist/next/parse/index.d.ts +2 -0
  14. package/dist/next/parse/markdown.d.ts +2 -0
  15. package/dist/next/parse/post-processing.d.ts +3 -0
  16. package/dist/next/shortcodes/index.d.ts +2 -0
  17. package/dist/next/shortcodes/lib/factory-tag.d.ts +4 -0
  18. package/dist/next/shortcodes/lib/jsx-flow.d.ts +3 -0
  19. package/dist/next/shortcodes/lib/jsx-text.d.ts +3 -0
  20. package/dist/next/shortcodes/lib/syntax.d.ts +18 -0
  21. package/dist/next/shortcodes/lib/util.d.ts +3 -0
  22. package/dist/next/shortcodes/mdast/index.d.ts +106 -0
  23. package/dist/next/stringify/acorn.d.ts +21 -0
  24. package/dist/next/stringify/index.d.ts +3 -0
  25. package/dist/next/stringify/marks.d.ts +8 -0
  26. package/dist/next/stringify/pre-processing.d.ts +8 -0
  27. package/dist/next/stringify/to-markdown.d.ts +3 -0
  28. package/dist/next/tests/FIXME-markdown-shortcodes-block-with-html-children-1/field.d.ts +2 -0
  29. package/dist/next/tests/FIXME-markdown-shortcodes-block-with-html-children-1/index.test.d.ts +1 -0
  30. package/dist/next/tests/FIXME-markdown-shortcodes-block-with-html-children-2/field.d.ts +2 -0
  31. package/dist/next/tests/FIXME-markdown-shortcodes-block-with-html-children-2/index.test.d.ts +1 -0
  32. package/dist/next/tests/FIXME-markdown-shortcodes-with-duplicates/field.d.ts +2 -0
  33. package/dist/next/tests/FIXME-markdown-shortcodes-with-duplicates/index.test.d.ts +1 -0
  34. package/dist/next/tests/markdown-basic-autoformat-blockquote-in-list/field.d.ts +2 -0
  35. package/dist/next/tests/markdown-basic-autoformat-blockquote-in-list/index.test.d.ts +1 -0
  36. package/dist/next/tests/markdown-basic-autoformat-heading-in-blockquote/field.d.ts +2 -0
  37. package/dist/next/tests/markdown-basic-autoformat-heading-in-blockquote/index.test.d.ts +1 -0
  38. package/dist/next/tests/markdown-basic-autoformat-html/field.d.ts +2 -0
  39. package/dist/next/tests/markdown-basic-autoformat-html/index.test.d.ts +1 -0
  40. package/dist/next/tests/markdown-basic-autoformat-list-item-style/field.d.ts +2 -0
  41. package/dist/next/tests/markdown-basic-autoformat-list-item-style/index.test.d.ts +1 -0
  42. package/dist/next/tests/markdown-basic-autoformat-syntax/field.d.ts +2 -0
  43. package/dist/next/tests/markdown-basic-autoformat-syntax/index.test.d.ts +1 -0
  44. package/dist/next/tests/markdown-basic-break/field.d.ts +2 -0
  45. package/dist/next/tests/markdown-basic-break/index.test.d.ts +1 -0
  46. package/dist/next/tests/markdown-basic-code-block/field.d.ts +2 -0
  47. package/dist/next/tests/markdown-basic-code-block/index.test.d.ts +1 -0
  48. package/dist/next/tests/markdown-basic-empty/field.d.ts +2 -0
  49. package/dist/next/tests/markdown-basic-empty/index.test.d.ts +1 -0
  50. package/dist/next/tests/markdown-basic-image/field.d.ts +2 -0
  51. package/dist/next/tests/markdown-basic-image/index.test.d.ts +1 -0
  52. package/dist/next/tests/markdown-basic-image-callback/field.d.ts +2 -0
  53. package/dist/next/tests/markdown-basic-image-callback/index.test.d.ts +1 -0
  54. package/dist/next/tests/markdown-basic-image-in-link/field.d.ts +2 -0
  55. package/dist/next/tests/markdown-basic-image-in-link/index.test.d.ts +1 -0
  56. package/dist/next/tests/markdown-basic-image-json-as-top-level/field.d.ts +2 -0
  57. package/dist/next/tests/markdown-basic-image-json-as-top-level/index.test.d.ts +1 -0
  58. package/dist/next/tests/markdown-basic-invalid-mdx/field.d.ts +2 -0
  59. package/dist/next/tests/markdown-basic-invalid-mdx/index.test.d.ts +1 -0
  60. package/dist/next/tests/markdown-basic-kitchen-sink/field.d.ts +2 -0
  61. package/dist/next/tests/markdown-basic-kitchen-sink/index.test.d.ts +1 -0
  62. package/dist/next/tests/markdown-basic-links/field.d.ts +2 -0
  63. package/dist/next/tests/markdown-basic-links/index.test.d.ts +1 -0
  64. package/dist/next/tests/markdown-basic-lists/field.d.ts +2 -0
  65. package/dist/next/tests/markdown-basic-lists/index.test.d.ts +1 -0
  66. package/dist/next/tests/markdown-basic-marks/field.d.ts +2 -0
  67. package/dist/next/tests/markdown-basic-marks/index.test.d.ts +1 -0
  68. package/dist/next/tests/markdown-basic-marks-strikethrough/field.d.ts +2 -0
  69. package/dist/next/tests/markdown-basic-marks-strikethrough/index.test.d.ts +1 -0
  70. package/dist/next/tests/markdown-basic-tables/field.d.ts +2 -0
  71. package/dist/next/tests/markdown-basic-tables/index.test.d.ts +1 -0
  72. package/dist/next/tests/markdown-html-issues/field.d.ts +2 -0
  73. package/dist/next/tests/markdown-html-issues/index.test.d.ts +1 -0
  74. package/dist/next/tests/markdown-mermaid/field.d.ts +2 -0
  75. package/dist/next/tests/markdown-mermaid/index.test.d.ts +1 -0
  76. package/dist/next/tests/markdown-shortcodes-inline/field.d.ts +2 -0
  77. package/dist/next/tests/markdown-shortcodes-inline/index.test.d.ts +1 -0
  78. package/dist/next/tests/markdown-shortcodes-inline-with-children/field.d.ts +2 -0
  79. package/dist/next/tests/markdown-shortcodes-inline-with-children/index.test.d.ts +1 -0
  80. package/dist/next/tests/markdown-shortcodes-invalid/field.d.ts +2 -0
  81. package/dist/next/tests/markdown-shortcodes-invalid/index.test.d.ts +1 -0
  82. package/dist/next/tests/markdown-shortcodes-invalid-2/field.d.ts +2 -0
  83. package/dist/next/tests/markdown-shortcodes-invalid-2/index.test.d.ts +1 -0
  84. package/dist/next/tests/markdown-shortcodes-invalid-3/field.d.ts +2 -0
  85. package/dist/next/tests/markdown-shortcodes-invalid-3/index.test.d.ts +1 -0
  86. package/dist/next/tests/markdown-shortcodes-invalid-4/field.d.ts +2 -0
  87. package/dist/next/tests/markdown-shortcodes-invalid-4/index.test.d.ts +1 -0
  88. package/dist/next/tests/markdown-shortcodes-markdoc/field.d.ts +2 -0
  89. package/dist/next/tests/markdown-shortcodes-markdoc/index.test.d.ts +1 -0
  90. package/dist/next/tests/markdown-shortcodes-nested-rich-text-children/field.d.ts +2 -0
  91. package/dist/next/tests/markdown-shortcodes-nested-rich-text-children/index.test.d.ts +1 -0
  92. package/dist/next/tests/markdown-shortcodes-rich-text-children/field.d.ts +2 -0
  93. package/dist/next/tests/markdown-shortcodes-rich-text-children/index.test.d.ts +1 -0
  94. package/dist/next/tests/markdown-shortcodes-rich-text-children-2/field.d.ts +2 -0
  95. package/dist/next/tests/markdown-shortcodes-rich-text-children-2/index.test.d.ts +1 -0
  96. package/dist/next/tests/markdown-shortcodes-rich-text-children-3/field.d.ts +2 -0
  97. package/dist/next/tests/markdown-shortcodes-rich-text-children-3/index.test.d.ts +1 -0
  98. package/dist/next/tests/markdown-shortcodes-unclosed/field.d.ts +2 -0
  99. package/dist/next/tests/markdown-shortcodes-unclosed/index.test.d.ts +1 -0
  100. package/dist/next/tests/mdx-basic-nested-objects/field.d.ts +2 -0
  101. package/dist/next/tests/mdx-basic-nested-objects/index.test.d.ts +1 -0
  102. package/dist/next/tests/mdx-basic-nested-objects-2/field.d.ts +2 -0
  103. package/dist/next/tests/mdx-basic-nested-objects-2/index.test.d.ts +1 -0
  104. package/dist/next/tests/mdx-basic-nested-objects-3/field.d.ts +2 -0
  105. package/dist/next/tests/mdx-basic-nested-objects-3/index.test.d.ts +1 -0
  106. package/dist/next/tests/mdx-basic-tables/field.d.ts +2 -0
  107. package/dist/next/tests/mdx-basic-tables/index.test.d.ts +1 -0
  108. package/dist/next/tests/mdx-block-object-list-field/field.d.ts +2 -0
  109. package/dist/next/tests/mdx-block-object-list-field/index.test.d.ts +1 -0
  110. package/dist/next/tests/mdx-block-object-list-template/field.d.ts +2 -0
  111. package/dist/next/tests/mdx-block-object-list-template/index.test.d.ts +1 -0
  112. package/dist/next/tests/mdx-block-scalar-fields/field.d.ts +2 -0
  113. package/dist/next/tests/mdx-block-scalar-fields/index.test.d.ts +1 -0
  114. package/dist/next/tests/mdx-blocks-autoformat-nested-mdx/field.d.ts +2 -0
  115. package/dist/next/tests/mdx-blocks-autoformat-nested-mdx/index.test.d.ts +1 -0
  116. package/dist/next/tests/mdx-blocks-autoformat-nested-mdx-null-children/field.d.ts +2 -0
  117. package/dist/next/tests/mdx-blocks-autoformat-nested-mdx-null-children/index.test.d.ts +1 -0
  118. package/dist/next/tests/mdx-blocks-multiple-rich-text-fields/field.d.ts +2 -0
  119. package/dist/next/tests/mdx-blocks-multiple-rich-text-fields/index.test.d.ts +1 -0
  120. package/dist/next/tests/mdx-blocks-rich-text-children/field.d.ts +2 -0
  121. package/dist/next/tests/mdx-blocks-rich-text-children/index.test.d.ts +1 -0
  122. package/dist/next/tests/mdx-blocks-rich-text-children-on-one-line/field.d.ts +2 -0
  123. package/dist/next/tests/mdx-blocks-rich-text-children-on-one-line/index.test.d.ts +1 -0
  124. package/dist/next/tests/mdx-blocks-rich-text-children-with-an-empty-object-value/field.d.ts +2 -0
  125. package/dist/next/tests/mdx-blocks-rich-text-children-with-an-empty-object-value/index.test.d.ts +1 -0
  126. package/dist/next/tests/mdx-table-like-field/field.d.ts +2 -0
  127. package/dist/next/tests/mdx-table-like-field/index.test.d.ts +1 -0
  128. package/dist/next/tests/mdx-unregistered-component/field.d.ts +2 -0
  129. package/dist/next/tests/mdx-unregistered-component/index.test.d.ts +1 -0
  130. package/dist/next/tests/slatejson/field.d.ts +2 -0
  131. package/dist/next/tests/slatejson/index.test.d.ts +1 -0
  132. package/dist/next/tests/unrecognized-shortcodes/field.d.ts +2 -0
  133. package/dist/next/tests/unrecognized-shortcodes/index.test.d.ts +1 -0
  134. package/dist/next/tests/util.d.ts +5 -0
  135. package/dist/next/tests/wordpress-style/field.d.ts +2 -0
  136. package/dist/next/tests/wordpress-style/index.test.d.ts +1 -0
  137. package/dist/next/tests/wordpress-style-2/field.d.ts +2 -0
  138. package/dist/next/tests/wordpress-style-2/index.test.d.ts +1 -0
  139. package/dist/next/tests/wordpress-style-2-block-with-children/field.d.ts +2 -0
  140. package/dist/next/tests/wordpress-style-2-block-with-children/index.test.d.ts +1 -0
  141. package/dist/next/tests/wordpress-style-2-with-children/field.d.ts +2 -0
  142. package/dist/next/tests/wordpress-style-2-with-children/index.test.d.ts +1 -0
  143. package/dist/next/util.d.ts +3 -0
  144. package/dist/parse/acorn.d.ts +4 -0
  145. package/dist/parse/acorn.test.d.ts +1 -0
  146. package/dist/parse/index.d.ts +64 -0
  147. package/dist/parse/mdx.d.ts +13 -0
  148. package/dist/parse/parseShortcode.d.ts +7 -0
  149. package/dist/parse/parseShortcode.test.d.ts +1 -0
  150. package/dist/parse/plate.d.ts +240 -0
  151. package/dist/parse/remarkToPlate.d.ts +31 -0
  152. package/dist/parse/remarkToPlate.test.d.ts +1 -0
  153. package/dist/stringify/acorn.d.ts +21 -0
  154. package/dist/stringify/index.d.ts +32 -0
  155. package/dist/stringify/marks.d.ts +13 -0
  156. package/dist/stringify/stringifyShortcode.d.ts +7 -0
  157. package/dist/stringify/stringifyShortcode.test.d.ts +1 -0
  158. package/package.json +92 -0
  159. package/readme.md +0 -0
@@ -0,0 +1,2 @@
1
+ import { RichTextField } from '@tinacms/schema-tools';
2
+ export declare const field: RichTextField;
@@ -0,0 +1,2 @@
1
+ import { RichTextField } from '@tinacms/schema-tools';
2
+ export declare const field: RichTextField;
@@ -0,0 +1,2 @@
1
+ import { RichTextField } from '@tinacms/schema-tools';
2
+ export declare const field: RichTextField;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { RichTextField } from '@tinacms/schema-tools';
2
+ export declare const field: RichTextField;
@@ -0,0 +1,5 @@
1
+ export declare function removePosition(tree: any): any;
2
+ export declare const print: (tree: object) => string;
3
+ export declare const nodePath: (dir: string) => string;
4
+ export declare const mdPath: (dir: string) => string;
5
+ export declare const jsonPath: (dir: string) => string;
@@ -0,0 +1,2 @@
1
+ import { RichTextField } from '@tinacms/schema-tools';
2
+ export declare const field: RichTextField;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { RichTextField } from '@tinacms/schema-tools';
2
+ export declare const field: RichTextField;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { RichTextField } from '@tinacms/schema-tools';
2
+ export declare const field: RichTextField;
@@ -0,0 +1,2 @@
1
+ import { RichTextField } from '@tinacms/schema-tools';
2
+ export declare const field: RichTextField;
@@ -0,0 +1,3 @@
1
+ import type { RichTextField } from '@tinacms/schema-tools';
2
+ import type { Pattern } from './shortcodes';
3
+ export declare const getFieldPatterns: (field: RichTextField) => Pattern[];
@@ -0,0 +1,4 @@
1
+ import type { MdxJsxAttribute, MdxJsxExpressionAttribute } from 'mdast-util-mdx-jsx';
2
+ import type { TinaField } from '@tinacms/schema-tools';
3
+ export declare const extractAttributes: (attributes: (MdxJsxAttribute | MdxJsxExpressionAttribute)[], fields: TinaField[], imageCallback: (image: string) => string) => Record<string, unknown>;
4
+ export declare const trimFragments: (string: string) => string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,64 @@
1
+ /**
2
+
3
+
4
+
5
+ */
6
+ import type { RichTextType } from '@tinacms/schema-tools';
7
+ import type * as Plate from './plate';
8
+ import { RichTextParseError } from './remarkToPlate';
9
+ /**
10
+ * ### Convert the MDXAST into an API-friendly format
11
+ *
12
+ * When we parse with Remark + MDX we get an AST which has a ton of JS capabilities, meaning
13
+ * we could pass this back into a JS runtime and evaluate it. Ex.
14
+ *
15
+ * ```mdx
16
+ * ## Hello world! The time and date is: {(new Date().toLocaleString())}
17
+ * ```
18
+ *
19
+ * However, as an intentional constraint we don't want this information as part of our API, as
20
+ * we don't intend to support the true JS runtime properties of MDX. Rather, we're using MDX for
21
+ * it's expressive syntax and it's advanced tooling with how it parses JSX inside Markdown.
22
+ *
23
+ * Parsing here does 2 things:
24
+ *
25
+ * #### Remove non-literal uses of JSX
26
+ * Things like <MyComponent myProp={() => alert("HI")} /> are not supported and will be ignored
27
+ *
28
+ * #### Convert remark nodes to slate-compatible nodes
29
+ *
30
+ * A remark node might look like this:
31
+ * ```js
32
+ * {
33
+ * type: "heading",
34
+ * depth: 1
35
+ * children: [{type: 'text', value: 'Hello'}]
36
+ * }
37
+ * ```
38
+ * A slate-compatible node would be:
39
+ * ```js
40
+ * {
41
+ * type: "heading_one",
42
+ * children: [{type: 'text', text: 'Hello'}]
43
+ * }
44
+ * ```
45
+ * It's not a huge difference, but in general slate does better with less layers of indirection.
46
+ *
47
+ * While it may be desirable to ultimately serve a remark AST shape as part of the API response,
48
+ * it's currently much easier to only support the shape that works with Slate. This is ok for now for 2
49
+ * reasons.
50
+ *
51
+ * 1. Us providing the `TinaMarkdown` component on the frontend abstracts away an work the developer
52
+ * would need to do, so it doesn't really matter what shape the response is as long as the external API
53
+ * doesn't change
54
+ *
55
+ * 2. We don't need to do any client-side parsing. Since TinaMarkdown and the slate editor work with the same
56
+ * format we can just allow Tina to do it's thing and update the form value with no additional work.
57
+ */
58
+ export declare const markdownToAst: (value: string, field: RichTextType) => import("mdast").Root;
59
+ export declare const mdxToAst: (value: string) => import("mdast").Root;
60
+ export declare const MDX_PARSE_ERROR_MSG = "TinaCMS supports a stricter version of markdown and a subset of MDX. https://tina.io/docs/r/what-is-markdown";
61
+ export declare const MDX_PARSE_ERROR_MSG_HTML = "TinaCMS supports a stricter version of markdown and a subset of MDX. <a href=\"https://tina.io/docs/r/what-is-markdown\" target=\"_blank\" rel=\"noopener noreferrer\">Learn More</a>";
62
+ export declare const parseMDX: (value: string, field: RichTextType, imageCallback: (s: string) => string) => Plate.RootElement;
63
+ export declare const invalidMarkdown: (e: RichTextParseError, value: string) => Plate.RootElement;
64
+ export declare const replaceAll: (string: string, target: string, value: string) => string;
@@ -0,0 +1,13 @@
1
+ /**
2
+
3
+
4
+
5
+ */
6
+ import type { MdxJsxTextElement, MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
7
+ import type { RichTextType } from '@tinacms/schema-tools';
8
+ import type * as Plate from './plate';
9
+ import { ContainerDirective } from 'mdast-util-directive';
10
+ import { LeafDirective } from 'mdast-util-directive/lib';
11
+ export declare function mdxJsxElement(node: MdxJsxTextElement, field: RichTextType, imageCallback: (url: string) => string): Plate.MdxInlineElement;
12
+ export declare function mdxJsxElement(node: MdxJsxFlowElement, field: RichTextType, imageCallback: (url: string) => string): Plate.MdxBlockElement;
13
+ export declare const directiveElement: (node: ContainerDirective | LeafDirective, field: RichTextType, imageCallback: (url: string) => string, raw?: string) => Plate.BlockElement | Plate.ParagraphElement;
@@ -0,0 +1,7 @@
1
+ /**
2
+
3
+
4
+
5
+ */
6
+ import { RichTextTemplate } from '@tinacms/schema-tools';
7
+ export declare function parseShortcode(preprocessedString: string, template: RichTextTemplate): string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,240 @@
1
+ /**
2
+
3
+
4
+
5
+ */
6
+ /**
7
+ * @group _MiscellaneousElement
8
+ */
9
+ export type RootElement = {
10
+ type: 'root';
11
+ children: BlockElement[];
12
+ };
13
+ /**
14
+ * @group BlockElement
15
+ */
16
+ export type BlockquoteElement = {
17
+ type: 'blockquote';
18
+ children: InlineElement[];
19
+ };
20
+ export type CodeLineElement = {
21
+ type: 'code_line';
22
+ children: {
23
+ text: string;
24
+ }[];
25
+ };
26
+ export type CodeBlockElement = {
27
+ type: 'code_block';
28
+ lang?: string;
29
+ value?: string;
30
+ children: CodeLineElement[];
31
+ };
32
+ /**
33
+ * @group BlockElement
34
+ */
35
+ export type HeadingElement = {
36
+ type: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
37
+ children: InlineElement[];
38
+ };
39
+ /**
40
+ * @group BlockElement
41
+ */
42
+ export type HrElement = {
43
+ type: 'hr';
44
+ children: [EmptyTextElement];
45
+ };
46
+ /**
47
+ * @group BlockElement
48
+ */
49
+ export type HTMLElement = {
50
+ type: 'html';
51
+ value: string;
52
+ children: [EmptyTextElement];
53
+ };
54
+ /**
55
+ * @group InlineElement
56
+ */
57
+ export type HTMLInlineElement = {
58
+ type: 'html_inline';
59
+ value: string;
60
+ children: [EmptyTextElement];
61
+ };
62
+ /**
63
+ * @group BlockElement
64
+ */
65
+ export type InvalidMarkdownElement = {
66
+ type: 'invalid_markdown';
67
+ value: string;
68
+ message: string;
69
+ position?: Position;
70
+ children: [EmptyTextElement];
71
+ };
72
+ /**
73
+ * @group ListElements
74
+ */
75
+ export type List = OrderedListElement | UnorderedListElement;
76
+ /**
77
+ * @group ListElements
78
+ */
79
+ export type ListItemContentElement = {
80
+ type: 'lic';
81
+ children: LicElement[];
82
+ };
83
+ /**
84
+ * @group ListElements
85
+ */
86
+ export type ListItemChildrenElement = ListItemContentElement | UnorderedListElement | OrderedListElement;
87
+ /**
88
+ * @group BlockElement
89
+ */
90
+ export type ListItemElement = {
91
+ type: 'li';
92
+ children: ListItemChildrenElement[];
93
+ };
94
+ /**
95
+ * @group BlockElement
96
+ */
97
+ export type UnorderedListElement = {
98
+ type: 'ul';
99
+ children: ListItemElement[];
100
+ };
101
+ /**
102
+ * @group BlockElement
103
+ */
104
+ export type MdxBlockElement = {
105
+ type: 'mdxJsxFlowElement';
106
+ name: string | null;
107
+ props: Record<string, unknown>;
108
+ children: [EmptyTextElement];
109
+ };
110
+ /**
111
+ * @group BlockElement
112
+ */
113
+ export type OrderedListElement = {
114
+ type: 'ol';
115
+ children: ListItemElement[];
116
+ };
117
+ /**
118
+ * @group BlockElement
119
+ */
120
+ export type ParagraphElement = {
121
+ type: 'p';
122
+ children: InlineElement[];
123
+ };
124
+ /**
125
+ * @group BlockElement
126
+ */
127
+ export type TableCellElement = {
128
+ type: 'td';
129
+ children: ParagraphElement[];
130
+ };
131
+ /**
132
+ * @group BlockElement
133
+ */
134
+ export type TableRowElement = {
135
+ type: 'tr';
136
+ children: TableCellElement[];
137
+ };
138
+ /**
139
+ * @group BlockElement
140
+ */
141
+ export type TableElement = {
142
+ type: 'table';
143
+ children: TableRowElement[];
144
+ props: Record<string, unknown>;
145
+ };
146
+ /**
147
+ * @group BlockElement
148
+ */
149
+ export type BlockElement = BlockquoteElement | CodeBlockElement | HeadingElement | HrElement | HTMLElement | ImageElement | InvalidMarkdownElement | ListItemElement | MdxBlockElement | ParagraphElement | OrderedListElement | UnorderedListElement | TableCellElement | TableRowElement | TableElement;
150
+ /**
151
+ * @group InlineElement
152
+ */
153
+ export type MdxInlineElement = {
154
+ type: 'mdxJsxTextElement';
155
+ name: string | null;
156
+ props: Record<string, unknown>;
157
+ children: [EmptyTextElement];
158
+ };
159
+ /**
160
+ * @remarks
161
+ * Used specifically to denote no children, used by
162
+ * the frontend rich-text editor for void nodes
163
+ *
164
+ * @group MiscellaneousElement
165
+ */
166
+ export type EmptyTextElement = {
167
+ type: 'text';
168
+ text: '';
169
+ };
170
+ /**
171
+ * @group InlineElement
172
+ */
173
+ export type TextElement = {
174
+ type: 'text';
175
+ text: string;
176
+ bold?: boolean;
177
+ italic?: boolean;
178
+ code?: boolean;
179
+ strikethrough?: boolean;
180
+ };
181
+ /**
182
+ * @remarks
183
+ * It may be beneficial to treat this as a block element
184
+ *
185
+ * @group InlineElement
186
+ */
187
+ export type ImageElement = {
188
+ type: 'img';
189
+ url: string;
190
+ alt?: string;
191
+ caption?: string | null;
192
+ children: [EmptyTextElement];
193
+ };
194
+ /**
195
+ * @group InlineElement
196
+ */
197
+ export type LinkElement = {
198
+ type: 'a';
199
+ url: string;
200
+ title?: string | null;
201
+ children: InlineElement[];
202
+ };
203
+ /**
204
+ * @group InlineElement
205
+ */
206
+ export type BreakElement = {
207
+ type: 'break';
208
+ children: [EmptyTextElement];
209
+ };
210
+ /**
211
+ * @group ListElements
212
+ */
213
+ export type LicElement = InlineElement;
214
+ /**
215
+ * @group InlineElement
216
+ */
217
+ export type InlineElement = TextElement | MdxInlineElement | BreakElement | LinkElement | ImageElement | HTMLInlineElement;
218
+ /**
219
+ * @remarks
220
+ * Positional information for error reporting
221
+ *
222
+ * @group _MiscellaneousElement
223
+ */
224
+ export type Position = {
225
+ start: PositionItem;
226
+ end: PositionItem;
227
+ };
228
+ /**
229
+ * @remarks
230
+ * Positional information for error reporting
231
+ *
232
+ * @group _MiscellaneousElement
233
+ */
234
+ export type PositionItem = {
235
+ line?: number | null;
236
+ column?: number | null;
237
+ offset?: number | null;
238
+ _index?: number | null;
239
+ _bufferIndex?: number | null;
240
+ };
@@ -0,0 +1,31 @@
1
+ /**
2
+
3
+
4
+
5
+ */
6
+ import type { RichTextType } from '@tinacms/schema-tools';
7
+ import type * as Md from 'mdast';
8
+ import type { ContainerDirective } from 'mdast-util-directive';
9
+ import type { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx-jsx';
10
+ import type * as Plate from './plate';
11
+ export type { Position, PositionItem } from './plate';
12
+ declare module 'mdast' {
13
+ interface StaticPhrasingContentMap {
14
+ mdxJsxTextElement: MdxJsxTextElement;
15
+ }
16
+ interface PhrasingContentMap {
17
+ mdxJsxTextElement: MdxJsxTextElement;
18
+ }
19
+ interface BlockContentMap {
20
+ mdxJsxFlowElement: MdxJsxFlowElement;
21
+ }
22
+ interface ContentMap {
23
+ mdxJsxFlowElement: MdxJsxFlowElement;
24
+ }
25
+ }
26
+ export declare const remarkToSlate: (root: Md.Root | MdxJsxFlowElement | MdxJsxTextElement | ContainerDirective, field: RichTextType, imageCallback: (url: string) => string, raw?: string, skipMDXProcess?: boolean) => Plate.RootElement;
27
+ export declare class RichTextParseError extends Error {
28
+ position?: Plate.Position;
29
+ constructor(message: string, position?: Plate.Position);
30
+ }
31
+ export declare const sanitizeUrl: (url: string | undefined) => string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ import type { RichTextField } from '@tinacms/schema-tools';
2
+ import type * as Md from 'mdast';
3
+ import type { MdxJsxAttribute } from 'mdast-util-mdx-jsx';
4
+ import * as Plate from '../parse/plate';
5
+ export declare const stringifyPropsInline: (element: Plate.MdxInlineElement, field: RichTextField, imageCallback: (url: string) => string) => {
6
+ attributes: MdxJsxAttribute[];
7
+ children: Md.PhrasingContent[];
8
+ };
9
+ export declare function stringifyProps(element: Plate.MdxInlineElement, parentField: RichTextField, flatten: boolean, imageCallback: (url: string) => string): {
10
+ attributes: MdxJsxAttribute[];
11
+ children: Md.PhrasingContent[];
12
+ useDirective: boolean;
13
+ directiveType: string;
14
+ };
15
+ export declare function stringifyProps(element: Plate.MdxBlockElement, parentField: RichTextField, flatten: boolean, imageCallback: (url: string) => string): {
16
+ attributes: MdxJsxAttribute[];
17
+ children: Md.BlockContent[];
18
+ useDirective: boolean;
19
+ directiveType: string;
20
+ };
21
+ export declare function assertShape<T>(value: unknown, callback: (item: any) => boolean, errorMessage?: string): asserts value is T;
@@ -0,0 +1,32 @@
1
+ import type { RichTextType } from '@tinacms/schema-tools';
2
+ import type * as Md from 'mdast';
3
+ import { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx-jsx';
4
+ import type * as Plate from '../parse/plate';
5
+ declare module 'mdast' {
6
+ interface StaticPhrasingContentMap {
7
+ mdxJsxTextElement: MdxJsxTextElement;
8
+ }
9
+ interface PhrasingContentMap {
10
+ mdxJsxTextElement: MdxJsxTextElement;
11
+ }
12
+ interface BlockContentMap {
13
+ mdxJsxFlowElement: MdxJsxFlowElement;
14
+ }
15
+ interface ContentMap {
16
+ mdxJsxFlowElement: MdxJsxFlowElement;
17
+ }
18
+ }
19
+ export declare const serializeMDX: (value: Plate.RootElement, field: RichTextType, imageCallback: (url: string) => string) => string | Plate.RootElement | undefined;
20
+ export type Pattern = {
21
+ start: string;
22
+ end: string;
23
+ name: string;
24
+ templateName: string;
25
+ type: 'block' | 'leaf';
26
+ };
27
+ export declare const toTinaMarkdown: (tree: Md.Root, field: RichTextType) => string;
28
+ export declare const rootElement: (content: Plate.RootElement, field: RichTextType, imageCallback: (url: string) => string) => Md.Root;
29
+ export declare function codeLinesToString(content: Plate.CodeBlockElement): string;
30
+ export declare const blockElement: (content: Plate.BlockElement, field: RichTextType, imageCallback: (url: string) => string) => Md.Content | null;
31
+ export type Marks = 'strong' | 'emphasis' | 'inlineCode' | 'delete';
32
+ export declare const getMarks: (content: Plate.InlineElement) => Marks[];
@@ -0,0 +1,13 @@
1
+ /**
2
+
3
+
4
+
5
+ */
6
+ import type * as Md from 'mdast';
7
+ import type * as Plate from '../parse/plate';
8
+ import type { RichTextType } from '@tinacms/schema-tools';
9
+ type InlineElementWithCallback = Plate.InlineElement & {
10
+ linkifyTextNode?: (arg: Md.Text) => Md.Link;
11
+ };
12
+ export declare const eat: (c: InlineElementWithCallback[], field: RichTextType, imageCallback: (url: string) => string) => Md.PhrasingContent[];
13
+ export {};
@@ -0,0 +1,7 @@
1
+ /**
2
+
3
+
4
+
5
+ */
6
+ import { RichTextTemplate } from '@tinacms/schema-tools';
7
+ export declare function stringifyShortcode(preprocessedString: string, template: RichTextTemplate): string;
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,92 @@
1
+ {
2
+ "name": "@tinacms/mdx",
3
+ "version": "0.0.0-00d7b85-20251222014449",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "browser": "dist/index.browser.js",
8
+ "files": [
9
+ "package.json",
10
+ "dist"
11
+ ],
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "browser": "./dist/index.browser.js",
16
+ "default": "./dist/index.js"
17
+ }
18
+ },
19
+ "license": "Apache-2.0",
20
+ "buildConfig": {
21
+ "entryPoints": [
22
+ {
23
+ "name": "src/index.ts",
24
+ "target": "node",
25
+ "bundleDeps": true
26
+ }
27
+ ]
28
+ },
29
+ "dependencies": {
30
+ "acorn": "8.8.2",
31
+ "ccount": "2.0.1",
32
+ "estree-util-is-identifier-name": "2.1.0",
33
+ "mdast-util-compact": "4.1.1",
34
+ "mdast-util-directive": "2.2.4",
35
+ "mdast-util-from-markdown": "1.3.0",
36
+ "mdast-util-gfm": "2.0.2",
37
+ "mdast-util-mdx-jsx": "2.1.2",
38
+ "mdast-util-to-markdown": "1.5.0",
39
+ "micromark-extension-gfm": "2.0.3",
40
+ "micromark-factory-mdx-expression": "1.0.7",
41
+ "micromark-factory-space": "1.0.0",
42
+ "micromark-factory-whitespace": "1.0.0",
43
+ "micromark-util-character": "1.1.0",
44
+ "micromark-util-symbol": "1.0.1",
45
+ "micromark-util-types": "1.0.2",
46
+ "parse-entities": "4.0.1",
47
+ "prettier": "^2.8.8",
48
+ "remark": "14.0.2",
49
+ "remark-gfm": "^2.0.0",
50
+ "remark-mdx": "2.3.0",
51
+ "stringify-entities": "4.0.3",
52
+ "typedoc": "^0.26.11",
53
+ "unist-util-source": "4.0.2",
54
+ "unist-util-stringify-position": "3.0.3",
55
+ "unist-util-visit": "4.1.2",
56
+ "uvu": "0.5.6",
57
+ "vfile-message": "3.1.4",
58
+ "@tinacms/schema-tools": "0.0.0-00d7b85-20251222014449"
59
+ },
60
+ "publishConfig": {
61
+ "registry": "https://registry.npmjs.org"
62
+ },
63
+ "repository": {
64
+ "url": "https://github.com/tinacms/tinacms.git",
65
+ "directory": "packages/tina-graphql"
66
+ },
67
+ "devDependencies": {
68
+ "@types/estree": "1.0.0",
69
+ "@types/mdast": "^3.0.15",
70
+ "@types/node": "^22.13.1",
71
+ "@types/prettier": "^2.7.3",
72
+ "@types/unist": "^2.0.11",
73
+ "c8": "^7.14.0",
74
+ "concat-md": "^0.5.1",
75
+ "jest-file-snapshot": "^0.5.0",
76
+ "ts-node": "^10.9.2",
77
+ "typedoc-plugin-markdown": "^3.17.1",
78
+ "typescript": "^5.7.3",
79
+ "vite": "^4.5.9",
80
+ "vitest": "^0.32.4",
81
+ "@tinacms/scripts": "1.4.2"
82
+ },
83
+ "scripts": {
84
+ "types": "tsc",
85
+ "build": "tinacms-scripts build",
86
+ "docs": "typedoc --plugin typedoc-plugin-markdown src/parse/plate.ts --theme markdown && concat-md --decrease-title-levels --dir-name-as-title docs > spec.md",
87
+ "serve": "nodemon dist/server.js",
88
+ "test": "vitest run",
89
+ "coverage": "vitest run --coverage",
90
+ "test-watch": "vitest"
91
+ }
92
+ }
package/readme.md ADDED
File without changes