@tinacms/mdx 0.0.0-00f6525-20241015065741

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 (155) 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.mjs +42675 -0
  10. package/dist/index.d.ts +10 -0
  11. package/dist/index.js +44582 -0
  12. package/dist/index.mjs +44547 -0
  13. package/dist/next/index.d.ts +2 -0
  14. package/dist/next/parse/index.d.ts +2 -0
  15. package/dist/next/parse/markdown.d.ts +2 -0
  16. package/dist/next/parse/post-processing.d.ts +3 -0
  17. package/dist/next/shortcodes/index.d.ts +2 -0
  18. package/dist/next/shortcodes/lib/factory-tag.d.ts +4 -0
  19. package/dist/next/shortcodes/lib/jsx-flow.d.ts +3 -0
  20. package/dist/next/shortcodes/lib/jsx-text.d.ts +3 -0
  21. package/dist/next/shortcodes/lib/syntax.d.ts +18 -0
  22. package/dist/next/shortcodes/lib/util.d.ts +3 -0
  23. package/dist/next/shortcodes/mdast/index.d.ts +106 -0
  24. package/dist/next/stringify/acorn.d.ts +21 -0
  25. package/dist/next/stringify/index.d.ts +3 -0
  26. package/dist/next/stringify/marks.d.ts +8 -0
  27. package/dist/next/stringify/pre-processing.d.ts +9 -0
  28. package/dist/next/stringify/to-markdown.d.ts +3 -0
  29. package/dist/next/tests/FIXME-markdown-shortcodes-block-with-html-children-1/field.d.ts +2 -0
  30. package/dist/next/tests/FIXME-markdown-shortcodes-block-with-html-children-1/index.test.d.ts +1 -0
  31. package/dist/next/tests/FIXME-markdown-shortcodes-block-with-html-children-2/field.d.ts +2 -0
  32. package/dist/next/tests/FIXME-markdown-shortcodes-block-with-html-children-2/index.test.d.ts +1 -0
  33. package/dist/next/tests/FIXME-markdown-shortcodes-with-duplicates/field.d.ts +2 -0
  34. package/dist/next/tests/FIXME-markdown-shortcodes-with-duplicates/index.test.d.ts +1 -0
  35. package/dist/next/tests/markdown-basic-autoformat-blockquote-in-list/field.d.ts +2 -0
  36. package/dist/next/tests/markdown-basic-autoformat-blockquote-in-list/index.test.d.ts +1 -0
  37. package/dist/next/tests/markdown-basic-autoformat-heading-in-blockquote/field.d.ts +2 -0
  38. package/dist/next/tests/markdown-basic-autoformat-heading-in-blockquote/index.test.d.ts +1 -0
  39. package/dist/next/tests/markdown-basic-autoformat-html/field.d.ts +2 -0
  40. package/dist/next/tests/markdown-basic-autoformat-html/index.test.d.ts +1 -0
  41. package/dist/next/tests/markdown-basic-autoformat-list-item-style/field.d.ts +2 -0
  42. package/dist/next/tests/markdown-basic-autoformat-list-item-style/index.test.d.ts +1 -0
  43. package/dist/next/tests/markdown-basic-autoformat-syntax/field.d.ts +2 -0
  44. package/dist/next/tests/markdown-basic-autoformat-syntax/index.test.d.ts +1 -0
  45. package/dist/next/tests/markdown-basic-break/field.d.ts +2 -0
  46. package/dist/next/tests/markdown-basic-break/index.test.d.ts +1 -0
  47. package/dist/next/tests/markdown-basic-code-block/field.d.ts +2 -0
  48. package/dist/next/tests/markdown-basic-code-block/index.test.d.ts +1 -0
  49. package/dist/next/tests/markdown-basic-empty/field.d.ts +2 -0
  50. package/dist/next/tests/markdown-basic-empty/index.test.d.ts +1 -0
  51. package/dist/next/tests/markdown-basic-image/field.d.ts +2 -0
  52. package/dist/next/tests/markdown-basic-image/index.test.d.ts +1 -0
  53. package/dist/next/tests/markdown-basic-image-callback/field.d.ts +2 -0
  54. package/dist/next/tests/markdown-basic-image-callback/index.test.d.ts +1 -0
  55. package/dist/next/tests/markdown-basic-image-in-link/field.d.ts +2 -0
  56. package/dist/next/tests/markdown-basic-image-in-link/index.test.d.ts +1 -0
  57. package/dist/next/tests/markdown-basic-image-json-as-top-level/field.d.ts +2 -0
  58. package/dist/next/tests/markdown-basic-image-json-as-top-level/index.test.d.ts +1 -0
  59. package/dist/next/tests/markdown-basic-invalid-mdx/field.d.ts +2 -0
  60. package/dist/next/tests/markdown-basic-invalid-mdx/index.test.d.ts +1 -0
  61. package/dist/next/tests/markdown-basic-kitchen-sink/field.d.ts +2 -0
  62. package/dist/next/tests/markdown-basic-kitchen-sink/index.test.d.ts +1 -0
  63. package/dist/next/tests/markdown-basic-links/field.d.ts +2 -0
  64. package/dist/next/tests/markdown-basic-links/index.test.d.ts +1 -0
  65. package/dist/next/tests/markdown-basic-lists/field.d.ts +2 -0
  66. package/dist/next/tests/markdown-basic-lists/index.test.d.ts +1 -0
  67. package/dist/next/tests/markdown-basic-marks/field.d.ts +2 -0
  68. package/dist/next/tests/markdown-basic-marks/index.test.d.ts +1 -0
  69. package/dist/next/tests/markdown-basic-tables/field.d.ts +2 -0
  70. package/dist/next/tests/markdown-basic-tables/index.test.d.ts +1 -0
  71. package/dist/next/tests/markdown-html-issues/field.d.ts +2 -0
  72. package/dist/next/tests/markdown-html-issues/index.test.d.ts +1 -0
  73. package/dist/next/tests/markdown-mermaid/field.d.ts +2 -0
  74. package/dist/next/tests/markdown-mermaid/index.test.d.ts +1 -0
  75. package/dist/next/tests/markdown-shortcodes-inline/field.d.ts +2 -0
  76. package/dist/next/tests/markdown-shortcodes-inline/index.test.d.ts +1 -0
  77. package/dist/next/tests/markdown-shortcodes-inline-with-children/field.d.ts +2 -0
  78. package/dist/next/tests/markdown-shortcodes-inline-with-children/index.test.d.ts +1 -0
  79. package/dist/next/tests/markdown-shortcodes-invalid/field.d.ts +2 -0
  80. package/dist/next/tests/markdown-shortcodes-invalid/index.test.d.ts +1 -0
  81. package/dist/next/tests/markdown-shortcodes-invalid-2/field.d.ts +2 -0
  82. package/dist/next/tests/markdown-shortcodes-invalid-2/index.test.d.ts +1 -0
  83. package/dist/next/tests/markdown-shortcodes-invalid-3/field.d.ts +2 -0
  84. package/dist/next/tests/markdown-shortcodes-invalid-3/index.test.d.ts +1 -0
  85. package/dist/next/tests/markdown-shortcodes-invalid-4/field.d.ts +2 -0
  86. package/dist/next/tests/markdown-shortcodes-invalid-4/index.test.d.ts +1 -0
  87. package/dist/next/tests/markdown-shortcodes-markdoc/field.d.ts +2 -0
  88. package/dist/next/tests/markdown-shortcodes-markdoc/index.test.d.ts +1 -0
  89. package/dist/next/tests/markdown-shortcodes-nested-rich-text-children/field.d.ts +2 -0
  90. package/dist/next/tests/markdown-shortcodes-nested-rich-text-children/index.test.d.ts +1 -0
  91. package/dist/next/tests/markdown-shortcodes-rich-text-children/field.d.ts +2 -0
  92. package/dist/next/tests/markdown-shortcodes-rich-text-children/index.test.d.ts +1 -0
  93. package/dist/next/tests/markdown-shortcodes-rich-text-children-2/field.d.ts +2 -0
  94. package/dist/next/tests/markdown-shortcodes-rich-text-children-2/index.test.d.ts +1 -0
  95. package/dist/next/tests/markdown-shortcodes-rich-text-children-3/field.d.ts +2 -0
  96. package/dist/next/tests/markdown-shortcodes-rich-text-children-3/index.test.d.ts +1 -0
  97. package/dist/next/tests/markdown-shortcodes-unclosed/field.d.ts +2 -0
  98. package/dist/next/tests/markdown-shortcodes-unclosed/index.test.d.ts +1 -0
  99. package/dist/next/tests/mdx-basic-nested-objects/field.d.ts +2 -0
  100. package/dist/next/tests/mdx-basic-nested-objects/index.test.d.ts +1 -0
  101. package/dist/next/tests/mdx-basic-nested-objects-2/field.d.ts +2 -0
  102. package/dist/next/tests/mdx-basic-nested-objects-2/index.test.d.ts +1 -0
  103. package/dist/next/tests/mdx-basic-nested-objects-3/field.d.ts +2 -0
  104. package/dist/next/tests/mdx-basic-nested-objects-3/index.test.d.ts +1 -0
  105. package/dist/next/tests/mdx-basic-tables/field.d.ts +2 -0
  106. package/dist/next/tests/mdx-basic-tables/index.test.d.ts +1 -0
  107. package/dist/next/tests/mdx-block-object-list-field/field.d.ts +2 -0
  108. package/dist/next/tests/mdx-block-object-list-field/index.test.d.ts +1 -0
  109. package/dist/next/tests/mdx-block-object-list-template/field.d.ts +2 -0
  110. package/dist/next/tests/mdx-block-object-list-template/index.test.d.ts +1 -0
  111. package/dist/next/tests/mdx-block-scalar-fields/field.d.ts +2 -0
  112. package/dist/next/tests/mdx-block-scalar-fields/index.test.d.ts +1 -0
  113. package/dist/next/tests/mdx-blocks-autoformat-nested-mdx/field.d.ts +2 -0
  114. package/dist/next/tests/mdx-blocks-autoformat-nested-mdx/index.test.d.ts +1 -0
  115. package/dist/next/tests/mdx-blocks-autoformat-nested-mdx-null-children/field.d.ts +2 -0
  116. package/dist/next/tests/mdx-blocks-autoformat-nested-mdx-null-children/index.test.d.ts +1 -0
  117. package/dist/next/tests/mdx-blocks-multiple-rich-text-fields/field.d.ts +2 -0
  118. package/dist/next/tests/mdx-blocks-multiple-rich-text-fields/index.test.d.ts +1 -0
  119. package/dist/next/tests/mdx-blocks-rich-text-children/field.d.ts +2 -0
  120. package/dist/next/tests/mdx-blocks-rich-text-children/index.test.d.ts +1 -0
  121. package/dist/next/tests/mdx-blocks-rich-text-children-on-one-line/field.d.ts +2 -0
  122. package/dist/next/tests/mdx-blocks-rich-text-children-on-one-line/index.test.d.ts +1 -0
  123. package/dist/next/tests/mdx-blocks-rich-text-children-with-an-empty-object-value/field.d.ts +2 -0
  124. package/dist/next/tests/mdx-blocks-rich-text-children-with-an-empty-object-value/index.test.d.ts +1 -0
  125. package/dist/next/tests/mdx-table-like-field/field.d.ts +2 -0
  126. package/dist/next/tests/mdx-table-like-field/index.test.d.ts +1 -0
  127. package/dist/next/tests/mdx-unregistered-component/field.d.ts +2 -0
  128. package/dist/next/tests/mdx-unregistered-component/index.test.d.ts +1 -0
  129. package/dist/next/tests/unrecognized-shortcodes/field.d.ts +2 -0
  130. package/dist/next/tests/unrecognized-shortcodes/index.test.d.ts +1 -0
  131. package/dist/next/tests/util.d.ts +4 -0
  132. package/dist/next/tests/wordpress-style/field.d.ts +2 -0
  133. package/dist/next/tests/wordpress-style/index.test.d.ts +1 -0
  134. package/dist/next/tests/wordpress-style-2/field.d.ts +2 -0
  135. package/dist/next/tests/wordpress-style-2/index.test.d.ts +1 -0
  136. package/dist/next/tests/wordpress-style-2-block-with-children/field.d.ts +2 -0
  137. package/dist/next/tests/wordpress-style-2-block-with-children/index.test.d.ts +1 -0
  138. package/dist/next/tests/wordpress-style-2-with-children/field.d.ts +2 -0
  139. package/dist/next/tests/wordpress-style-2-with-children/index.test.d.ts +1 -0
  140. package/dist/next/util.d.ts +3 -0
  141. package/dist/parse/acorn.d.ts +4 -0
  142. package/dist/parse/acorn.test.d.ts +1 -0
  143. package/dist/parse/index.d.ts +64 -0
  144. package/dist/parse/mdx.d.ts +13 -0
  145. package/dist/parse/parseShortcode.d.ts +7 -0
  146. package/dist/parse/parseShortcode.test.d.ts +1 -0
  147. package/dist/parse/plate.d.ts +244 -0
  148. package/dist/parse/remarkToPlate.d.ts +30 -0
  149. package/dist/stringify/acorn.d.ts +21 -0
  150. package/dist/stringify/index.d.ts +36 -0
  151. package/dist/stringify/marks.d.ts +13 -0
  152. package/dist/stringify/stringifyShortcode.d.ts +7 -0
  153. package/dist/stringify/stringifyShortcode.test.d.ts +1 -0
  154. package/package.json +94 -0
  155. 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,4 @@
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;
@@ -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 { RichTextParseError } from './remarkToPlate';
7
+ import type { RichTextType } from '@tinacms/schema-tools';
8
+ import type * as Plate from './plate';
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/editing/mdx/#differences-from-other-mdx-implementations";
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/editing/mdx/#differences-from-other-mdx-implementations\" 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,244 @@
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
+ /**
21
+ * @group BlockElement
22
+ */
23
+ export type CodeBlockElement = {
24
+ type: 'code_block';
25
+ lang?: string;
26
+ value: string;
27
+ children: [EmptyTextElement];
28
+ };
29
+ /**
30
+ * @group BlockElement
31
+ */
32
+ export type HeadingElement = {
33
+ type: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
34
+ children: InlineElement[];
35
+ };
36
+ /**
37
+ * @group BlockElement
38
+ */
39
+ export type HrElement = {
40
+ type: 'hr';
41
+ children: [EmptyTextElement];
42
+ };
43
+ /**
44
+ * @group BlockElement
45
+ */
46
+ export type HTMLElement = {
47
+ type: 'html';
48
+ value: string;
49
+ children: [EmptyTextElement];
50
+ };
51
+ /**
52
+ * @group InlineElement
53
+ */
54
+ export type HTMLInlineElement = {
55
+ type: 'html_inline';
56
+ value: string;
57
+ children: [EmptyTextElement];
58
+ };
59
+ /**
60
+ * @group BlockElement
61
+ */
62
+ export type InvalidMarkdownElement = {
63
+ type: 'invalid_markdown';
64
+ value: string;
65
+ message: string;
66
+ position?: Position;
67
+ children: [EmptyTextElement];
68
+ };
69
+ /**
70
+ * @group ListElements
71
+ */
72
+ export type List = OrderedListElement | UnorderedListElement;
73
+ /**
74
+ * @group ListElements
75
+ */
76
+ export type ListItemContentElement = {
77
+ type: 'lic';
78
+ children: LicElement[];
79
+ };
80
+ /**
81
+ * @group ListElements
82
+ */
83
+ export type ListItemChildrenElement = ListItemContentElement | UnorderedListElement | OrderedListElement;
84
+ /**
85
+ * @group BlockElement
86
+ */
87
+ export type ListItemElement = {
88
+ type: 'li';
89
+ children: ListItemChildrenElement[];
90
+ };
91
+ /**
92
+ * @group BlockElement
93
+ */
94
+ export type UnorderedListElement = {
95
+ type: 'ul';
96
+ children: ListItemElement[];
97
+ };
98
+ /**
99
+ * @group BlockElement
100
+ */
101
+ export type MdxBlockElement = {
102
+ type: 'mdxJsxFlowElement';
103
+ name: string | null;
104
+ props: Record<string, unknown>;
105
+ children: [EmptyTextElement];
106
+ };
107
+ /**
108
+ * @group BlockElement
109
+ */
110
+ export type OrderedListElement = {
111
+ type: 'ol';
112
+ children: ListItemElement[];
113
+ };
114
+ /**
115
+ * @group BlockElement
116
+ */
117
+ export type ParagraphElement = {
118
+ type: 'p';
119
+ children: InlineElement[];
120
+ };
121
+ /**
122
+ * @group BlockElement
123
+ */
124
+ export type TableCellElement = {
125
+ type: 'td';
126
+ children: ParagraphElement[];
127
+ };
128
+ /**
129
+ * @group BlockElement
130
+ */
131
+ export type TableRowElement = {
132
+ type: 'tr';
133
+ children: TableCellElement[];
134
+ };
135
+ /**
136
+ * @group BlockElement
137
+ */
138
+ export type TableElement = {
139
+ type: 'table';
140
+ children: TableRowElement[];
141
+ props: Record<string, unknown>;
142
+ };
143
+ /**
144
+ * @group MermaidElement
145
+ */
146
+ export type MermaidElement = {
147
+ type: 'mermaid';
148
+ value: string;
149
+ children: [EmptyTextElement];
150
+ };
151
+ /**
152
+ * @group BlockElement
153
+ */
154
+ export type BlockElement = BlockquoteElement | CodeBlockElement | HeadingElement | HrElement | HTMLElement | ImageElement | InvalidMarkdownElement | ListItemElement | MdxBlockElement | ParagraphElement | MermaidElement | OrderedListElement | UnorderedListElement | TableCellElement | TableRowElement | TableElement;
155
+ /**
156
+ * @group InlineElement
157
+ */
158
+ export type MdxInlineElement = {
159
+ type: 'mdxJsxTextElement';
160
+ name: string | null;
161
+ props: Record<string, unknown>;
162
+ children: [EmptyTextElement];
163
+ };
164
+ /**
165
+ * @remarks
166
+ * Used specifically to denote no children, used by
167
+ * the frontend rich-text editor for void nodes
168
+ *
169
+ * @group MiscellaneousElement
170
+ */
171
+ export type EmptyTextElement = {
172
+ type: 'text';
173
+ text: '';
174
+ };
175
+ /**
176
+ * @group InlineElement
177
+ */
178
+ export type TextElement = {
179
+ type: 'text';
180
+ text: string;
181
+ bold?: boolean;
182
+ italic?: boolean;
183
+ code?: boolean;
184
+ };
185
+ /**
186
+ * @remarks
187
+ * It may be beneficial to treat this as a block element
188
+ *
189
+ * @group InlineElement
190
+ */
191
+ export type ImageElement = {
192
+ type: 'img';
193
+ url: string;
194
+ alt?: string;
195
+ caption?: string | null;
196
+ children: [EmptyTextElement];
197
+ };
198
+ /**
199
+ * @group InlineElement
200
+ */
201
+ export type LinkElement = {
202
+ type: 'a';
203
+ url: string;
204
+ title?: string | null;
205
+ children: InlineElement[];
206
+ };
207
+ /**
208
+ * @group InlineElement
209
+ */
210
+ export type BreakElement = {
211
+ type: 'break';
212
+ children: [EmptyTextElement];
213
+ };
214
+ /**
215
+ * @group ListElements
216
+ */
217
+ export type LicElement = InlineElement;
218
+ /**
219
+ * @group InlineElement
220
+ */
221
+ export type InlineElement = TextElement | MdxInlineElement | BreakElement | LinkElement | ImageElement | HTMLInlineElement;
222
+ /**
223
+ * @remarks
224
+ * Positional information for error reporting
225
+ *
226
+ * @group _MiscellaneousElement
227
+ */
228
+ export type Position = {
229
+ start: PositionItem;
230
+ end: PositionItem;
231
+ };
232
+ /**
233
+ * @remarks
234
+ * Positional information for error reporting
235
+ *
236
+ * @group _MiscellaneousElement
237
+ */
238
+ export type PositionItem = {
239
+ line?: number | null;
240
+ column?: number | null;
241
+ offset?: number | null;
242
+ _index?: number | null;
243
+ _bufferIndex?: number | null;
244
+ };
@@ -0,0 +1,30 @@
1
+ /**
2
+
3
+
4
+
5
+ */
6
+ import type * as Md from 'mdast';
7
+ import type * as Plate from './plate';
8
+ import type { RichTextType } from '@tinacms/schema-tools';
9
+ import type { MdxJsxTextElement, MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
10
+ import type { ContainerDirective } from 'mdast-util-directive';
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
+ }
@@ -0,0 +1,21 @@
1
+ import type { RichTextField } from '@tinacms/schema-tools';
2
+ import type { MdxJsxAttribute } from 'mdast-util-mdx-jsx';
3
+ import * as Plate from '../parse/plate';
4
+ import type * as Md from 'mdast';
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,36 @@
1
+ /**
2
+
3
+
4
+
5
+ */
6
+ import { MdxJsxTextElement, MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
7
+ import type { RichTextType } from '@tinacms/schema-tools';
8
+ import type * as Md from 'mdast';
9
+ import type * as Plate from '../parse/plate';
10
+ declare module 'mdast' {
11
+ interface StaticPhrasingContentMap {
12
+ mdxJsxTextElement: MdxJsxTextElement;
13
+ }
14
+ interface PhrasingContentMap {
15
+ mdxJsxTextElement: MdxJsxTextElement;
16
+ }
17
+ interface BlockContentMap {
18
+ mdxJsxFlowElement: MdxJsxFlowElement;
19
+ }
20
+ interface ContentMap {
21
+ mdxJsxFlowElement: MdxJsxFlowElement;
22
+ }
23
+ }
24
+ export declare const stringifyMDX: (value: Plate.RootElement, field: RichTextType, imageCallback: (url: string) => string) => string | undefined;
25
+ export type Pattern = {
26
+ start: string;
27
+ end: string;
28
+ name: string;
29
+ templateName: string;
30
+ type: 'block' | 'leaf';
31
+ };
32
+ export declare const toTinaMarkdown: (tree: Md.Root, field: RichTextType) => string;
33
+ export declare const rootElement: (content: Plate.RootElement, field: RichTextType, imageCallback: (url: string) => string) => Md.Root;
34
+ export declare const blockElement: (content: Plate.BlockElement, field: RichTextType, imageCallback: (url: string) => string) => Md.Content | null;
35
+ export type Marks = 'strong' | 'emphasis' | 'inlineCode';
36
+ 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,94 @@
1
+ {
2
+ "name": "@tinacms/mdx",
3
+ "version": "0.0.0-00f6525-20241015065741",
4
+ "typings": "dist/index.d.ts",
5
+ "main": "dist/index.js",
6
+ "browser": "dist/index.browser.mjs",
7
+ "module": "dist/index.mjs",
8
+ "files": [
9
+ "package.json",
10
+ "dist"
11
+ ],
12
+ "exports": {
13
+ ".": {
14
+ "import": "./dist/index.mjs",
15
+ "require": "./dist/index.js",
16
+ "browser": "./dist/index.browser.mjs"
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
+ "lodash.flatten": "4.4.0",
34
+ "mdast-util-compact": "4.1.1",
35
+ "mdast-util-directive": "2.2.4",
36
+ "mdast-util-from-markdown": "1.3.0",
37
+ "mdast-util-gfm": "2.0.2",
38
+ "mdast-util-mdx-jsx": "2.1.2",
39
+ "mdast-util-to-markdown": "1.5.0",
40
+ "micromark-extension-gfm": "2.0.3",
41
+ "micromark-factory-mdx-expression": "1.0.7",
42
+ "micromark-factory-space": "1.0.0",
43
+ "micromark-factory-whitespace": "1.0.0",
44
+ "micromark-util-character": "1.1.0",
45
+ "micromark-util-symbol": "1.0.1",
46
+ "micromark-util-types": "1.0.2",
47
+ "parse-entities": "4.0.1",
48
+ "prettier": "^2.8.8",
49
+ "remark": "14.0.2",
50
+ "remark-gfm": "^2.0.0",
51
+ "remark-mdx": "2.3.0",
52
+ "stringify-entities": "4.0.3",
53
+ "typedoc": "^0.26.7",
54
+ "unist-util-source": "4.0.2",
55
+ "unist-util-stringify-position": "3.0.3",
56
+ "unist-util-visit": "4.1.2",
57
+ "uvu": "0.5.6",
58
+ "vfile-message": "3.1.4",
59
+ "@tinacms/schema-tools": "0.0.0-00f6525-20241015065741"
60
+ },
61
+ "publishConfig": {
62
+ "registry": "https://registry.npmjs.org"
63
+ },
64
+ "repository": {
65
+ "url": "https://github.com/tinacms/tinacms.git",
66
+ "directory": "packages/tina-graphql"
67
+ },
68
+ "devDependencies": {
69
+ "@types/estree": "1.0.0",
70
+ "@types/lodash.flatten": "^4.4.9",
71
+ "@types/mdast": "^3.0.15",
72
+ "@types/node": "^22.7.4",
73
+ "@types/prettier": "^2.7.3",
74
+ "@types/unist": "^2.0.11",
75
+ "c8": "^7.14.0",
76
+ "concat-md": "^0.5.1",
77
+ "jest-file-snapshot": "^0.5.0",
78
+ "ts-node": "^10.9.2",
79
+ "typedoc-plugin-markdown": "^3.17.1",
80
+ "typescript": "^5.6.2",
81
+ "vite": "^4.5.5",
82
+ "vitest": "^0.32.4",
83
+ "@tinacms/scripts": "0.0.0-00f6525-20241015065741"
84
+ },
85
+ "scripts": {
86
+ "types": "tsc",
87
+ "build": "tinacms-scripts build",
88
+ "docs": "typedoc --plugin typedoc-plugin-markdown src/parse/plate.ts --theme markdown && concat-md --decrease-title-levels --dir-name-as-title docs > spec.md",
89
+ "serve": "nodemon dist/server.js",
90
+ "test": "vitest",
91
+ "coverage": "vitest run --coverage",
92
+ "test-watch": "jest --watch"
93
+ }
94
+ }
package/readme.md ADDED
File without changes