@karimsa/mdxserve 0.4.0 → 0.5.1

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.
@@ -0,0 +1,295 @@
1
+ import type { Editor, Range } from "@tiptap/core";
2
+
3
+ export type BlockGroup = "Basic blocks" | "Media and structure" | "Components";
4
+ export interface SlashBlock {
5
+ id: string;
6
+ label: string;
7
+ description: string;
8
+ aliases: string[];
9
+ group: BlockGroup;
10
+ kind: "native" | "component" | "diagram" | "image";
11
+ template?: string;
12
+ }
13
+
14
+ const native = (
15
+ id: string,
16
+ label: string,
17
+ description: string,
18
+ aliases: string[] = [],
19
+ ): SlashBlock => ({
20
+ id,
21
+ label,
22
+ description,
23
+ aliases,
24
+ group: "Basic blocks",
25
+ kind: "native",
26
+ });
27
+ const component = (
28
+ label: string,
29
+ description: string,
30
+ template: string,
31
+ aliases: string[] = [],
32
+ ): SlashBlock => ({
33
+ id: label.toLowerCase().replace(/\s+/g, "-"),
34
+ label,
35
+ description,
36
+ aliases,
37
+ group: "Components",
38
+ kind: "component",
39
+ template,
40
+ });
41
+
42
+ export const slashBlocks: SlashBlock[] = [
43
+ native("paragraph", "Text", "Plain paragraph", ["paragraph", "body"]),
44
+ native("link", "Link", "Text linked to a web address", ["url", "hyperlink"]),
45
+ ...Array.from({ length: 6 }, (_, index) =>
46
+ native(`heading${index + 1}`, `Heading ${index + 1}`, `Level ${index + 1} heading`, [
47
+ `h${index + 1}`,
48
+ `title ${index + 1}`,
49
+ ]),
50
+ ),
51
+ native("bulletList", "Bulleted list", "List with bullet points", ["unordered", "bullets"]),
52
+ native("orderedList", "Numbered list", "List with numbered steps", ["ordered", "numbers"]),
53
+ native("taskList", "To-do list", "Checklist with boxes", ["todo", "checkbox", "tasks"]),
54
+ native("blockquote", "Quote", "Indented quotation", ["blockquote", "citation"]),
55
+ {
56
+ ...native("codeBlock", "Code", "Fenced code block", ["snippet", "preformatted"]),
57
+ group: "Media and structure",
58
+ },
59
+ {
60
+ ...native("table", "Table", "Three-column Markdown table", ["grid", "rows"]),
61
+ group: "Media and structure",
62
+ },
63
+ {
64
+ ...native("horizontalRule", "Divider", "Horizontal rule", ["rule", "separator", "hr"]),
65
+ group: "Media and structure",
66
+ },
67
+ {
68
+ id: "image",
69
+ label: "Image",
70
+ description: "Add an image URL and alt text",
71
+ aliases: ["photo", "picture"],
72
+ group: "Media and structure",
73
+ kind: "image",
74
+ },
75
+ {
76
+ id: "mermaid",
77
+ label: "Mermaid diagram",
78
+ description: "Create a diagram or edit Mermaid source",
79
+ aliases: ["diagram", "flowchart", "sequence"],
80
+ group: "Media and structure",
81
+ kind: "diagram",
82
+ },
83
+ component(
84
+ "Custom component",
85
+ "Editable MDX or JSX source",
86
+ '<Callout title="Custom component">\n Edit this MDX source.\n</Callout>',
87
+ ["mdx", "jsx", "source", "component"],
88
+ ),
89
+ component(
90
+ "Callout",
91
+ "Highlighted note or warning",
92
+ '<Callout title="Note">\n Add your note here.\n</Callout>',
93
+ ["note", "warning", "tip"],
94
+ ),
95
+ component(
96
+ "Button",
97
+ "Link styled as a button",
98
+ '<Button href="https://example.com">\n Open link\n</Button>',
99
+ ["link", "action"],
100
+ ),
101
+ component(
102
+ "Tooltip",
103
+ "Hover explanation for text",
104
+ '<Tooltip content="More information">\n Explained term\n</Tooltip>',
105
+ ["hint", "hover"],
106
+ ),
107
+ component(
108
+ "Tabs",
109
+ "Tabbed content panels",
110
+ '<Tabs>\n <Tab label="First">First panel</Tab>\n <Tab label="Second">Second panel</Tab>\n</Tabs>',
111
+ ["panels"],
112
+ ),
113
+ component(
114
+ "Tab",
115
+ "A tab inside Tabs",
116
+ '<Tabs>\n <Tab label="First">First panel</Tab>\n <Tab label="Second">Second panel</Tab>\n</Tabs>',
117
+ ["panel"],
118
+ ),
119
+ component("Badge", "Small status label", '<Badge tone="ok">\n Ready\n</Badge>', [
120
+ "status",
121
+ "pill",
122
+ ]),
123
+ component(
124
+ "Diff",
125
+ "Before and after code",
126
+ '<Diff before="old value" after="new value" language="text" />',
127
+ ["changes", "compare"],
128
+ ),
129
+ component(
130
+ "Card",
131
+ "Featured content card",
132
+ '<Card title="Next step" description="Learn more about this topic" href="https://example.com" />',
133
+ ["feature", "link card"],
134
+ ),
135
+ component(
136
+ "CardGrid",
137
+ "Responsive group of cards",
138
+ '<CardGrid>\n <Card title="First" description="First option" />\n <Card title="Second" description="Second option" />\n</CardGrid>',
139
+ ["cards", "grid"],
140
+ ),
141
+ component("Kbd", "Keyboard shortcut key", "<Kbd>\n ⌘\n</Kbd>", ["key", "keyboard"]),
142
+ component(
143
+ "FileTree",
144
+ "Directory layout",
145
+ '<FileTree nodes={[{ name: "src", children: [{ name: "index.ts" }] }]} />',
146
+ ["files", "folder"],
147
+ ),
148
+ component(
149
+ "Chart",
150
+ "Small data chart",
151
+ '<Chart data={[{ label: "First", value: 3 }, { label: "Second", value: 5 }]} />',
152
+ ["graph", "bar chart"],
153
+ ),
154
+ component("Sparkline", "Inline trend line", "<Sparkline values={[2, 3, 5, 4, 7]} />", [
155
+ "trend",
156
+ "line",
157
+ ]),
158
+ component(
159
+ "Dropdown",
160
+ "Picker with choices",
161
+ '<Dropdown label="Choose one" options={["First", "Second"]} />',
162
+ ["select", "menu"],
163
+ ),
164
+ component(
165
+ "Option",
166
+ "A panel inside Dropdown",
167
+ '<Dropdown label="Choose one">\n <Option label="First">First panel</Option>\n <Option label="Second">Second panel</Option>\n</Dropdown>',
168
+ ["choice"],
169
+ ),
170
+ component(
171
+ "DataTable",
172
+ "Sortable data table",
173
+ '<DataTable id="example-table" columns={[{ key: "name", label: "Name", type: "text" }, { key: "value", label: "Value", type: "number" }]} data={[{ name: "First", value: 3 }, { name: "Second", value: 5 }]} />',
174
+ ["dataset", "sortable table"],
175
+ ),
176
+ component(
177
+ "Screenshot",
178
+ "App screenshot in a window",
179
+ '<Screenshot src="/screenshot.png" alt="Description of the screenshot" title="Example" />',
180
+ ["window", "screen capture"],
181
+ ),
182
+ ];
183
+
184
+ export function matchingBlocks(query: string): SlashBlock[] {
185
+ const terms = query.trim().toLowerCase().split(/\s+/).filter(Boolean);
186
+ return slashBlocks.filter((block) =>
187
+ terms.every(
188
+ (term) =>
189
+ [block.label, ...block.aliases].some((value) => value.toLowerCase().includes(term)) ||
190
+ block.description
191
+ .toLowerCase()
192
+ .split(/\W+/)
193
+ .some((word) => word.startsWith(term)),
194
+ ),
195
+ );
196
+ }
197
+
198
+ const paragraph = (text: string) => ({ type: "paragraph", content: [{ type: "text", text }] });
199
+
200
+ export function blockContent(block: SlashBlock): Record<string, unknown> {
201
+ if (block.kind === "component") return { type: "mdxBlock", attrs: { source: block.template } };
202
+ if (block.id.startsWith("heading"))
203
+ return {
204
+ type: "heading",
205
+ attrs: { level: Number(block.id.slice(-1)) },
206
+ content: [{ type: "text", text: "Heading" }],
207
+ };
208
+ switch (block.id) {
209
+ case "paragraph":
210
+ return paragraph("Text");
211
+ case "link":
212
+ return {
213
+ type: "paragraph",
214
+ content: [
215
+ {
216
+ type: "text",
217
+ text: "Link text",
218
+ marks: [{ type: "link", attrs: { href: "https://example.com" } }],
219
+ },
220
+ ],
221
+ };
222
+ case "bulletList":
223
+ return {
224
+ type: "bulletList",
225
+ content: [{ type: "listItem", content: [paragraph("List item")] }],
226
+ };
227
+ case "orderedList":
228
+ return {
229
+ type: "orderedList",
230
+ content: [{ type: "listItem", content: [paragraph("List item")] }],
231
+ };
232
+ case "taskList":
233
+ return {
234
+ type: "taskList",
235
+ content: [{ type: "taskItem", attrs: { checked: false }, content: [paragraph("Task")] }],
236
+ };
237
+ case "blockquote":
238
+ return { type: "blockquote", content: [paragraph("Quote")] };
239
+ case "codeBlock":
240
+ return { type: "codeBlock", content: [{ type: "text", text: "Code" }] };
241
+ case "table":
242
+ return {
243
+ type: "table",
244
+ content: [
245
+ {
246
+ type: "tableRow",
247
+ content: ["Column 1", "Column 2", "Column 3"].map((value) => ({
248
+ type: "tableHeader",
249
+ content: [paragraph(value)],
250
+ })),
251
+ },
252
+ {
253
+ type: "tableRow",
254
+ content: ["Value 1", "Value 2", "Value 3"].map((value) => ({
255
+ type: "tableCell",
256
+ content: [paragraph(value)],
257
+ })),
258
+ },
259
+ ],
260
+ };
261
+ case "horizontalRule":
262
+ return { type: "horizontalRule" };
263
+ case "mermaid":
264
+ return {
265
+ type: "codeBlock",
266
+ attrs: { language: "mermaid" },
267
+ content: [{ type: "text", text: "flowchart TD\n A[Start] --> B[End]" }],
268
+ };
269
+ default:
270
+ throw new Error(`Unknown slash block: ${block.id}`);
271
+ }
272
+ }
273
+
274
+ /** Replace the whole slash paragraph rather than nesting a block inside it. */
275
+ export function insertSlashBlock(editor: Editor, range: Range, block: SlashBlock): boolean {
276
+ const { doc } = editor.state;
277
+ if (range.to > doc.content.size) return false;
278
+ const start = doc.resolve(range.from);
279
+ if (
280
+ start.parent.type.name !== "paragraph" ||
281
+ start.parent.textContent !== doc.textBetween(range.from, range.to)
282
+ )
283
+ return false;
284
+ if (block.kind === "image") return false;
285
+ const replacement = { from: start.before(), to: start.after() };
286
+ const content = blockContent(block);
287
+ if (block.id === "datatable") {
288
+ const identifier = `table-${globalThis.crypto?.randomUUID?.() ?? Math.random().toString(36).slice(2)}`;
289
+ (content.attrs as { source: string }).source = block.template!.replace(
290
+ 'id="example-table"',
291
+ `id="${identifier}"`,
292
+ );
293
+ }
294
+ return editor.chain().focus().insertContentAt(replacement, content).run();
295
+ }
@@ -0,0 +1,57 @@
1
+ .mdx-source-block {
2
+ border: 1px solid var(--border-default);
3
+ border-radius: var(--radius-md);
4
+ background: var(--surface-card);
5
+ padding: var(--space-4);
6
+ margin-block: var(--space-4);
7
+ white-space: normal;
8
+ }
9
+ .mdx-component-name {
10
+ display: block;
11
+ margin-bottom: var(--space-3);
12
+ color: var(--text-heading);
13
+ }
14
+ .mdx-component-fields {
15
+ display: grid;
16
+ grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
17
+ gap: var(--space-3);
18
+ }
19
+ .mdx-component-fields label {
20
+ display: flex;
21
+ flex-direction: column;
22
+ gap: var(--space-1);
23
+ font-size: var(--size-sm);
24
+ color: var(--text-muted);
25
+ }
26
+ .mdx-component-fields input:not([type="checkbox"]),
27
+ .mdx-component-fields textarea,
28
+ .mdx-component-source {
29
+ width: 100%;
30
+ padding: var(--space-2);
31
+ border: 1px solid var(--border-default);
32
+ border-radius: var(--radius-sm);
33
+ background: var(--surface-sunken);
34
+ color: var(--text-body);
35
+ }
36
+ .mdx-component-fields input[type="checkbox"] {
37
+ align-self: start;
38
+ }
39
+ .mdx-component-fields textarea {
40
+ resize: vertical;
41
+ min-height: 80px;
42
+ }
43
+ .mdx-source-block details {
44
+ margin-top: var(--space-3);
45
+ font-size: var(--size-sm);
46
+ color: var(--text-muted);
47
+ }
48
+ .mdx-source-block summary {
49
+ cursor: pointer;
50
+ }
51
+ .mdx-component-source {
52
+ margin-top: var(--space-2);
53
+ min-height: 160px;
54
+ font-family: var(--font-mono);
55
+ resize: vertical;
56
+ white-space: pre;
57
+ }
@@ -0,0 +1,128 @@
1
+ import { fromMarkdown } from "mdast-util-from-markdown";
2
+ import { mdxFromMarkdown } from "mdast-util-mdx";
3
+ import { mdxjs } from "micromark-extension-mdxjs";
4
+ import type { RootContent } from "mdast";
5
+
6
+ export interface ComponentField {
7
+ key: string;
8
+ label: string;
9
+ value: string;
10
+ kind: "text" | "number" | "boolean" | "content";
11
+ from: number;
12
+ to: number;
13
+ attribute?: string;
14
+ }
15
+
16
+ /** Expose literal values without evaluating expressions or rewriting surrounding source. */
17
+ export function componentFields(source: string): { name: string; fields: ComponentField[] } {
18
+ const fields: ComponentField[] = [];
19
+ try {
20
+ const tree = fromMarkdown(source, {
21
+ extensions: [mdxjs()],
22
+ mdastExtensions: [mdxFromMarkdown()],
23
+ });
24
+ const root = tree.children[0];
25
+ const first =
26
+ root?.type === "paragraph" && root.children.length === 1 ? root.children[0] : root;
27
+ if (first?.type !== "mdxJsxFlowElement" && first?.type !== "mdxJsxTextElement")
28
+ return { name: "Custom block", fields };
29
+ function visit(node: RootContent, path: string, label: string) {
30
+ if (node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") {
31
+ for (const attribute of node.attributes) {
32
+ if (attribute.type !== "mdxJsxAttribute" || typeof attribute.name !== "string") continue;
33
+ const from = attribute.position?.start.offset;
34
+ const to = attribute.position?.end.offset;
35
+ if (from === undefined || to === undefined) continue;
36
+ let value: unknown = attribute.value;
37
+ if (value === null) value = true;
38
+ else if (typeof value === "object") {
39
+ try {
40
+ value = JSON.parse((value as { value: string }).value);
41
+ } catch {
42
+ continue;
43
+ }
44
+ }
45
+ if (!["string", "number", "boolean"].includes(typeof value)) continue;
46
+ fields.push({
47
+ key: `${path}:${attribute.name}`,
48
+ label: `${label} ${attribute.name}`,
49
+ value: String(value),
50
+ kind:
51
+ typeof value === "string" ? "text" : typeof value === "number" ? "number" : "boolean",
52
+ from,
53
+ to,
54
+ attribute: attribute.name,
55
+ });
56
+ }
57
+ }
58
+ if (node.type === "mdxFlowExpression" || node.type === "mdxTextExpression") {
59
+ try {
60
+ const value: unknown = JSON.parse(node.value);
61
+ const from = node.position?.start.offset;
62
+ const to = node.position?.end.offset;
63
+ if (typeof value === "string" && from !== undefined && to !== undefined)
64
+ fields.push({
65
+ key: `${path}:content`,
66
+ label: `${label} text`,
67
+ value,
68
+ kind: "content",
69
+ from,
70
+ to,
71
+ });
72
+ } catch {
73
+ /* Nonliteral expressions stay in the source editor. */
74
+ }
75
+ }
76
+ if ("children" in node) {
77
+ const children = node.children as RootContent[];
78
+ if (children.length === 1 && children[0].type === "text") {
79
+ const child = children[0];
80
+ const from = child.position?.start.offset;
81
+ const to = child.position?.end.offset;
82
+ if (from !== undefined && to !== undefined)
83
+ fields.push({
84
+ key: `${path}:content`,
85
+ label: `${label} text`,
86
+ value: child.value,
87
+ kind: "content",
88
+ from,
89
+ to,
90
+ });
91
+ } else if (
92
+ children.length === 1 &&
93
+ (children[0].type === "mdxTextExpression" ||
94
+ children[0].type === "mdxFlowExpression" ||
95
+ children[0].type === "paragraph")
96
+ ) {
97
+ visit(children[0], path, label);
98
+ } else
99
+ children.forEach((child, index) =>
100
+ visit(
101
+ child,
102
+ `${path}.${index}`,
103
+ child.type === "mdxJsxFlowElement" || child.type === "mdxJsxTextElement"
104
+ ? `${child.name ?? "Component"} ${index + 1}`
105
+ : label,
106
+ ),
107
+ );
108
+ }
109
+ }
110
+ visit(first, "root", first.name ?? "Component");
111
+ return { name: first.name ?? "Component", fields };
112
+ } catch {
113
+ return { name: "Custom block", fields };
114
+ }
115
+ }
116
+
117
+ export function updateComponentField(source: string, field: ComponentField, value: string): string {
118
+ let replacement: string;
119
+ if (field.kind === "content") {
120
+ replacement = `{${JSON.stringify(value)}}`;
121
+ } else {
122
+ const literal =
123
+ field.kind === "boolean" ? value === "true" : field.kind === "number" ? Number(value) : value;
124
+ if (typeof literal === "number" && (!value.trim() || !Number.isFinite(literal))) return source;
125
+ replacement = `${field.attribute}={${JSON.stringify(literal)}}`;
126
+ }
127
+ return source.slice(0, field.from) + replacement + source.slice(field.to);
128
+ }
@@ -0,0 +1,44 @@
1
+ .editor-image-dialog {
2
+ width: min(440px, calc(100vw - 32px));
3
+ margin: auto;
4
+ padding: var(--space-6);
5
+ border: 1px solid var(--border-default);
6
+ border-radius: var(--radius-lg);
7
+ background: var(--surface-raised);
8
+ color: var(--text-body);
9
+ }
10
+ .editor-image-dialog::backdrop {
11
+ background: rgb(0 0 0 / 40%);
12
+ }
13
+ .editor-image-dialog form,
14
+ .editor-image-dialog label {
15
+ display: flex;
16
+ flex-direction: column;
17
+ gap: var(--space-2);
18
+ }
19
+ .editor-image-dialog form {
20
+ gap: var(--space-4);
21
+ }
22
+ .editor-image-dialog h2 {
23
+ font-weight: 600;
24
+ font-size: 1.1rem;
25
+ }
26
+ .editor-image-dialog input {
27
+ padding: var(--space-2);
28
+ border: 1px solid var(--border-default);
29
+ border-radius: var(--radius-sm);
30
+ background: var(--surface-sunken);
31
+ }
32
+ .editor-image-dialog footer {
33
+ display: flex;
34
+ gap: var(--space-3);
35
+ justify-content: flex-end;
36
+ }
37
+ .editor-image-dialog button {
38
+ padding: var(--space-2) var(--space-3);
39
+ border: 1px solid var(--border-default);
40
+ border-radius: var(--radius-sm);
41
+ }
42
+ .editor-image-dialog button:disabled {
43
+ opacity: 0.5;
44
+ }
@@ -0,0 +1,138 @@
1
+ import { Node } from "@tiptap/core";
2
+ import { ReactNodeViewRenderer, NodeViewWrapper, type NodeViewProps } from "@tiptap/react";
3
+ import { fromMarkdown } from "mdast-util-from-markdown";
4
+ import { mdxFromMarkdown } from "mdast-util-mdx";
5
+ import { mdxjs } from "micromark-extension-mdxjs";
6
+ import { componentFields, updateComponentField } from "./component-fields";
7
+
8
+ function readFlowJsx(source: string): string | undefined {
9
+ if (!/^ {0,3}</.test(source)) return;
10
+ const parse = (candidate: string): string | undefined => {
11
+ const tree = fromMarkdown(candidate, {
12
+ extensions: [mdxjs()],
13
+ mdastExtensions: [mdxFromMarkdown()],
14
+ });
15
+ const first = tree.children[0];
16
+ if (
17
+ first?.type !== "mdxJsxFlowElement" ||
18
+ first.position?.start.offset === undefined ||
19
+ first.position.start.offset > 3
20
+ )
21
+ return;
22
+ const end = first.position.end.offset;
23
+ return end === undefined ? undefined : source.slice(0, end);
24
+ };
25
+ try {
26
+ return parse(source);
27
+ } catch {
28
+ // A later tolerant Markdown span can be invalid MDX. Parse only up to
29
+ // the first complete JSX block, never requiring the rest to be valid.
30
+ for (const match of source.matchAll(/\n/g)) {
31
+ try {
32
+ const block = parse(source.slice(0, match.index + 1));
33
+ if (block) return block;
34
+ } catch {
35
+ // The component may still be open at this line boundary.
36
+ }
37
+ }
38
+ return;
39
+ }
40
+ }
41
+
42
+ /** Keep JSX in one atom so its children and JavaScript expressions never pass through Marked. */
43
+ function MdxBlockView({ node, updateAttributes }: NodeViewProps) {
44
+ const source = node.attrs.source as string;
45
+ const { name, fields } = componentFields(source);
46
+ return (
47
+ <NodeViewWrapper className="mdx-source-block" contentEditable={false}>
48
+ <strong className="mdx-component-name">{name}</strong>
49
+ <div className="mdx-component-fields">
50
+ {fields.map((field) => (
51
+ <label key={field.key}>
52
+ <span>{field.label}</span>
53
+ {field.kind === "boolean" ? (
54
+ <input
55
+ type="checkbox"
56
+ checked={field.value === "true"}
57
+ onChange={(event) =>
58
+ updateAttributes({
59
+ source: updateComponentField(source, field, String(event.target.checked)),
60
+ })
61
+ }
62
+ />
63
+ ) : field.kind === "content" ? (
64
+ <textarea
65
+ value={field.value}
66
+ onChange={(event) =>
67
+ updateAttributes({
68
+ source: updateComponentField(source, field, event.target.value),
69
+ })
70
+ }
71
+ />
72
+ ) : (
73
+ <input
74
+ type={field.kind === "number" ? "number" : "text"}
75
+ value={field.value}
76
+ onChange={(event) =>
77
+ updateAttributes({
78
+ source: updateComponentField(source, field, event.target.value),
79
+ })
80
+ }
81
+ />
82
+ )}
83
+ </label>
84
+ ))}
85
+ </div>
86
+ <details open={fields.length === 0 ? true : undefined}>
87
+ <summary>Advanced source</summary>
88
+ <label>
89
+ <span className="sr-only">MDX source</span>
90
+ <textarea
91
+ aria-label="MDX source"
92
+ className="mdx-component-source"
93
+ value={source}
94
+ onChange={(event) => updateAttributes({ source: event.target.value })}
95
+ spellCheck={false}
96
+ />
97
+ </label>
98
+ </details>
99
+ </NodeViewWrapper>
100
+ );
101
+ }
102
+
103
+ /** A block-level JSX element, preserved byte-for-byte while its section is edited. */
104
+ export const MdxBlock = Node.create({
105
+ name: "mdxBlock",
106
+ group: "block",
107
+ atom: true,
108
+ draggable: true,
109
+ addAttributes() {
110
+ return { source: { default: "" } };
111
+ },
112
+ parseHTML() {
113
+ return [
114
+ {
115
+ tag: "div[data-mdx-block]",
116
+ getAttrs: (element) => ({ source: element.getAttribute("data-source") ?? "" }),
117
+ },
118
+ ];
119
+ },
120
+ renderHTML({ node }) {
121
+ return ["div", { "data-mdx-block": "", "data-source": node.attrs.source as string }];
122
+ },
123
+ addNodeView() {
124
+ return ReactNodeViewRenderer(MdxBlockView);
125
+ },
126
+ markdownTokenName: "mdxBlock",
127
+ markdownTokenizer: {
128
+ name: "mdxBlock",
129
+ level: "block",
130
+ start: (source) => source.search(/(^|\n) {0,3}</),
131
+ tokenize: (source) => {
132
+ const raw = readFlowJsx(source);
133
+ return raw ? { type: "mdxBlock", raw, text: raw } : undefined;
134
+ },
135
+ },
136
+ parseMarkdown: (token, helpers) => helpers.createNode("mdxBlock", { source: token.raw }),
137
+ renderMarkdown: (node) => node.attrs?.source ?? "",
138
+ });