@haklex/rich-headless 0.0.80 → 0.0.82

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.
@@ -1,425 +1,366 @@
1
- import { CHECK_LIST, TRANSFORMERS, $convertToMarkdownString } from "@lexical/markdown";
2
- import { $isTableNode, $isTableRowNode, $isTableCellNode } from "@lexical/table";
3
- const NEVER = /a^/;
4
- const NOOP = () => {
5
- };
1
+ import { $isTableCellNode, $isTableNode, $isTableRowNode } from "@lexical/table";
2
+ import { $convertToMarkdownString, CHECK_LIST, TRANSFORMERS } from "@lexical/markdown";
3
+ //#region src/transformers.ts
4
+ /**
5
+ * Headless Markdown transformers — export-only (Lexical → Markdown).
6
+ * Import stubs are no-ops; used only for $convertToMarkdownString.
7
+ */
8
+ var NEVER = /a^/;
9
+ var NOOP = () => {};
6
10
  function qA(v) {
7
- return v.replaceAll('"', '\\"');
11
+ return v.replaceAll("\"", "\\\"");
8
12
  }
9
13
  function escHtml(v) {
10
- return v.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
14
+ return v.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
11
15
  }
12
16
  function escCell(v) {
13
- return v.replaceAll("|", "\\|").replaceAll("\n", "<br/>");
17
+ return v.replaceAll("|", "\\|").replaceAll("\n", "<br/>");
14
18
  }
15
19
  function fence(content) {
16
- const m = content.match(/`+/g);
17
- const max = m?.reduce((a, r) => Math.max(a, r.length), 0) ?? 0;
18
- return "`".repeat(Math.max(3, max + 1));
20
+ const max = content.match(/`+/g)?.reduce((a, r) => Math.max(a, r.length), 0) ?? 0;
21
+ return "`".repeat(Math.max(3, max + 1));
19
22
  }
20
23
  function walkText(node) {
21
- const children = node.children;
22
- if (!children) return node.text ?? "";
23
- return children.map(walkText).join("\n");
24
+ const children = node.children;
25
+ if (!children) return node.text ?? "";
26
+ return children.map(walkText).join("\n");
24
27
  }
25
28
  function stateText(state) {
26
- if (!state || typeof state !== "object") return "";
27
- const root = state.root;
28
- return root ? walkText(root) : "";
29
+ if (!state || typeof state !== "object") return "";
30
+ const root = state.root;
31
+ return root ? walkText(root) : "";
29
32
  }
30
- const SPOILER_TRANSFORMER = {
31
- dependencies: [],
32
- export: (node) => node.getType() === "spoiler" ? `||${node.getTextContent()}||` : null,
33
- importRegExp: /\|\|(.+?)\|\|/,
34
- regExp: /\|\|(.+?)\|\|$/,
35
- replace: NOOP,
36
- trigger: "|",
37
- type: "text-match"
33
+ var SPOILER_TRANSFORMER = {
34
+ dependencies: [],
35
+ export: (node) => node.getType() === "spoiler" ? `||${node.getTextContent()}||` : null,
36
+ importRegExp: /\|\|(.+?)\|\|/,
37
+ regExp: /\|\|(.+?)\|\|$/,
38
+ replace: NOOP,
39
+ trigger: "|",
40
+ type: "text-match"
38
41
  };
39
- const MENTION_TRANSFORMER = {
40
- dependencies: [],
41
- export: (node) => {
42
- if (node.getType() !== "mention") return null;
43
- const j = node.exportJSON();
44
- const base = `{${j.platform}@${j.handle}}`;
45
- return j.displayName ? `[${j.displayName}]${base}` : base;
46
- },
47
- importRegExp: /(?:\[([^\]]+)\])?\{(\w+)@(\w[\w.-]*)\}/,
48
- regExp: /(?:\[([^\]]+)\])?\{(\w+)@(\w[\w.-]*)\}$/,
49
- replace: NOOP,
50
- trigger: "}",
51
- type: "text-match"
42
+ var MENTION_TRANSFORMER = {
43
+ dependencies: [],
44
+ export: (node) => {
45
+ if (node.getType() !== "mention") return null;
46
+ const j = node.exportJSON();
47
+ const base = `{${j.platform}@${j.handle}}`;
48
+ return j.displayName ? `[${j.displayName}]${base}` : base;
49
+ },
50
+ importRegExp: /(?:\[([^\]]+)\])?\{(\w+)@(\w[\w.-]*)\}/,
51
+ regExp: /(?:\[([^\]]+)\])?\{(\w+)@(\w[\w.-]*)\}$/,
52
+ replace: NOOP,
53
+ trigger: "}",
54
+ type: "text-match"
52
55
  };
53
- const FOOTNOTE_TRANSFORMER = {
54
- dependencies: [],
55
- export: (node) => node.getType() === "footnote" ? `[^${node.__identifier ?? ""}]` : null,
56
- importRegExp: /\[\^(\w+)\]/,
57
- regExp: /\[\^(\w+)\]$/,
58
- replace: NOOP,
59
- trigger: "]",
60
- type: "text-match"
56
+ var FOOTNOTE_TRANSFORMER = {
57
+ dependencies: [],
58
+ export: (node) => node.getType() === "footnote" ? `[^${node.__identifier ?? ""}]` : null,
59
+ importRegExp: /\[\^(\w+)\]/,
60
+ regExp: /\[\^(\w+)\]$/,
61
+ replace: NOOP,
62
+ trigger: "]",
63
+ type: "text-match"
61
64
  };
62
- const KATEX_INLINE_TRANSFORMER = {
63
- dependencies: [],
64
- export: (node) => node.getType() === "katex-inline" ? `$${node.__equation ?? ""}$` : null,
65
- importRegExp: /\$([^\n$]+)\$/,
66
- regExp: /\$([^\n$]+)\$$/,
67
- replace: NOOP,
68
- trigger: "$",
69
- type: "text-match"
65
+ var KATEX_INLINE_TRANSFORMER = {
66
+ dependencies: [],
67
+ export: (node) => node.getType() === "katex-inline" ? `$${node.__equation ?? ""}$` : null,
68
+ importRegExp: /\$([^\n$]+)\$/,
69
+ regExp: /\$([^\n$]+)\$$/,
70
+ replace: NOOP,
71
+ trigger: "$",
72
+ type: "text-match"
70
73
  };
71
- const RUBY_TRANSFORMER = {
72
- dependencies: [],
73
- export: (node) => {
74
- if (node.getType() !== "ruby") return null;
75
- const base = escHtml(node.getTextContent());
76
- const reading = escHtml(node.__reading ?? "");
77
- if (!reading) return base;
78
- return `<ruby>${base}<rt>${reading}</rt></ruby>`;
79
- },
80
- importRegExp: /<ruby>([^<]*)<rt>([^<]*)<\/rt>(?:<rp>[^<]*<\/rp>)*<\/ruby>/i,
81
- regExp: /<ruby>([^<]*)<rt>([^<]*)<\/rt>(?:<rp>[^<]*<\/rp>)*<\/ruby>$/i,
82
- replace: NOOP,
83
- trigger: ">",
84
- type: "text-match"
74
+ var RUBY_TRANSFORMER = {
75
+ dependencies: [],
76
+ export: (node) => {
77
+ if (node.getType() !== "ruby") return null;
78
+ const base = escHtml(node.getTextContent());
79
+ const reading = escHtml(node.__reading ?? "");
80
+ if (!reading) return base;
81
+ return `<ruby>${base}<rt>${reading}</rt></ruby>`;
82
+ },
83
+ importRegExp: /<ruby>([^<]*)<rt>([^<]*)<\/rt>(?:<rp>[^<]*<\/rp>)*<\/ruby>/i,
84
+ regExp: /<ruby>([^<]*)<rt>([^<]*)<\/rt>(?:<rp>[^<]*<\/rp>)*<\/ruby>$/i,
85
+ replace: NOOP,
86
+ trigger: ">",
87
+ type: "text-match"
85
88
  };
86
- const INSERT_TRANSFORMER = {
87
- format: ["underline"],
88
- tag: "++",
89
- type: "text-format"
89
+ var INSERT_TRANSFORMER = {
90
+ format: ["underline"],
91
+ tag: "++",
92
+ type: "text-format"
90
93
  };
91
- const SUPERSCRIPT_TRANSFORMER = {
92
- format: ["superscript"],
93
- tag: "^",
94
- type: "text-format"
94
+ var SUPERSCRIPT_TRANSFORMER = {
95
+ format: ["superscript"],
96
+ tag: "^",
97
+ type: "text-format"
95
98
  };
96
- const SUBSCRIPT_TRANSFORMER = {
97
- format: ["subscript"],
98
- tag: "~",
99
- type: "text-format"
99
+ var SUBSCRIPT_TRANSFORMER = {
100
+ format: ["subscript"],
101
+ tag: "~",
102
+ type: "text-format"
100
103
  };
101
- const TAG_TRANSFORMER = {
102
- dependencies: [],
103
- export: (node) => node.getType() === "tag" ? `<tag>${node.__text ?? ""}</tag>` : null,
104
- importRegExp: /<tag>([^<]+)<\/tag>/,
105
- regExp: /<tag>([^<]+)<\/tag>$/,
106
- replace: NOOP,
107
- trigger: ">",
108
- type: "text-match"
104
+ var TAG_TRANSFORMER = {
105
+ dependencies: [],
106
+ export: (node) => node.getType() === "tag" ? `<tag>${node.__text ?? ""}</tag>` : null,
107
+ importRegExp: /<tag>([^<]+)<\/tag>/,
108
+ regExp: /<tag>([^<]+)<\/tag>$/,
109
+ replace: NOOP,
110
+ trigger: ">",
111
+ type: "text-match"
109
112
  };
110
- const FOOTNOTE_SECTION_TRANSFORMER = {
111
- dependencies: [],
112
- export: (node) => {
113
- if (node.getType() !== "footnote-section") return null;
114
- const defs = node.__definitions ?? {};
115
- return Object.entries(defs).map(([id, content]) => `[^${id}]: ${content}`).join("\n");
116
- },
117
- regExp: NEVER,
118
- replace: NOOP,
119
- type: "element"
113
+ var FOOTNOTE_SECTION_TRANSFORMER = {
114
+ dependencies: [],
115
+ export: (node) => {
116
+ if (node.getType() !== "footnote-section") return null;
117
+ const defs = node.__definitions ?? {};
118
+ return Object.entries(defs).map(([id, content]) => `[^${id}]: ${content}`).join("\n");
119
+ },
120
+ regExp: NEVER,
121
+ replace: NOOP,
122
+ type: "element"
120
123
  };
121
- const CONTAINER_TRANSFORMER = {
122
- dependencies: [],
123
- export: (node) => {
124
- const t = node.getType();
125
- if (t === "banner") {
126
- const type = node.__bannerType ?? "note";
127
- return `::: ${type}
128
- ${node.getTextContent()}
129
- :::`;
130
- }
131
- if (t === "details") {
132
- const summary = node.__summary ?? "";
133
- return `::: details{summary="${qA(summary)}"}
134
- ${node.getTextContent()}
135
- :::`;
136
- }
137
- return null;
138
- },
139
- regExp: NEVER,
140
- replace: NOOP,
141
- type: "element"
124
+ var CONTAINER_TRANSFORMER = {
125
+ dependencies: [],
126
+ export: (node) => {
127
+ const t = node.getType();
128
+ if (t === "banner") return `::: ${node.__bannerType ?? "note"}\n${node.getTextContent()}\n:::`;
129
+ if (t === "details") return `::: details{summary="${qA(node.__summary ?? "")}"}\n${node.getTextContent()}\n:::`;
130
+ return null;
131
+ },
132
+ regExp: NEVER,
133
+ replace: NOOP,
134
+ type: "element"
142
135
  };
143
- const ALERT_KEY = {
144
- note: "NOTE",
145
- tip: "TIP",
146
- important: "IMPORTANT",
147
- warning: "WARNING",
148
- caution: "CAUTION"
136
+ var ALERT_KEY = {
137
+ note: "NOTE",
138
+ tip: "TIP",
139
+ important: "IMPORTANT",
140
+ warning: "WARNING",
141
+ caution: "CAUTION"
149
142
  };
150
- const GIT_ALERT_TRANSFORMER = {
151
- dependencies: [],
152
- export: (node) => {
153
- if (node.getType() !== "alert-quote") return null;
154
- const key = ALERT_KEY[node.__alertType ?? "note"] ?? "NOTE";
155
- const lines = node.getTextContent().split("\n");
156
- return [`> [!${key}]`, ...lines.map((l) => `> ${l}`)].join("\n");
157
- },
158
- regExp: NEVER,
159
- replace: NOOP,
160
- type: "element"
143
+ var GIT_ALERT_TRANSFORMER = {
144
+ dependencies: [],
145
+ export: (node) => {
146
+ if (node.getType() !== "alert-quote") return null;
147
+ const key = ALERT_KEY[node.__alertType ?? "note"] ?? "NOTE";
148
+ const lines = node.getTextContent().split("\n");
149
+ return [`> [!${key}]`, ...lines.map((l) => `> ${l}`)].join("\n");
150
+ },
151
+ regExp: NEVER,
152
+ replace: NOOP,
153
+ type: "element"
161
154
  };
162
- const KATEX_BLOCK_TRANSFORMER = {
163
- dependencies: [],
164
- export: (node) => node.getType() === "katex-block" ? `$$${node.__equation ?? ""}$$` : null,
165
- importRegExp: /\$\$([^$]+)\$\$/,
166
- regExp: /\$\$([^$]+)\$\$$/,
167
- replace: NOOP,
168
- trigger: "$",
169
- type: "text-match"
155
+ var KATEX_BLOCK_TRANSFORMER = {
156
+ dependencies: [],
157
+ export: (node) => node.getType() === "katex-block" ? `$$${node.__equation ?? ""}$$` : null,
158
+ importRegExp: /\$\$([^$]+)\$\$/,
159
+ regExp: /\$\$([^$]+)\$\$$/,
160
+ replace: NOOP,
161
+ trigger: "$",
162
+ type: "text-match"
170
163
  };
171
- const IMAGE_BLOCK_TRANSFORMER = {
172
- dependencies: [],
173
- export: (node) => {
174
- if (node.getType() !== "image") return null;
175
- const j = node.exportJSON();
176
- const title = j.caption ? ` "${qA(j.caption)}"` : "";
177
- return `![${j.altText || ""}](${j.src}${title})`;
178
- },
179
- regExp: NEVER,
180
- replace: NOOP,
181
- type: "element"
164
+ var IMAGE_BLOCK_TRANSFORMER = {
165
+ dependencies: [],
166
+ export: (node) => {
167
+ if (node.getType() !== "image") return null;
168
+ const j = node.exportJSON();
169
+ const title = j.caption ? ` "${qA(j.caption)}"` : "";
170
+ return `![${j.altText || ""}](${j.src}${title})`;
171
+ },
172
+ regExp: NEVER,
173
+ replace: NOOP,
174
+ type: "element"
182
175
  };
183
- const VIDEO_BLOCK_TRANSFORMER = {
184
- dependencies: [],
185
- export: (node) => {
186
- if (node.getType() !== "video") return null;
187
- const j = node.exportJSON();
188
- const attrs = [`src="${qA(j.src)}"`];
189
- if (j.poster) attrs.push(`poster="${qA(j.poster)}"`);
190
- if (j.width) attrs.push(`width=${j.width}`);
191
- if (j.height) attrs.push(`height=${j.height}`);
192
- return `<video ${attrs.join(" ")} controls></video>`;
193
- },
194
- regExp: NEVER,
195
- replace: NOOP,
196
- type: "element"
176
+ var VIDEO_BLOCK_TRANSFORMER = {
177
+ dependencies: [],
178
+ export: (node) => {
179
+ if (node.getType() !== "video") return null;
180
+ const j = node.exportJSON();
181
+ const attrs = [`src="${qA(j.src)}"`];
182
+ if (j.poster) attrs.push(`poster="${qA(j.poster)}"`);
183
+ if (j.width) attrs.push(`width=${j.width}`);
184
+ if (j.height) attrs.push(`height=${j.height}`);
185
+ return `<video ${attrs.join(" ")} controls></video>`;
186
+ },
187
+ regExp: NEVER,
188
+ replace: NOOP,
189
+ type: "element"
197
190
  };
198
- const CODE_BLOCK_NODE_TRANSFORMER = {
199
- dependencies: [],
200
- export: (node) => {
201
- if (node.getType() !== "code-block") return null;
202
- const j = node.exportJSON();
203
- const f = fence(j.code || "");
204
- return `${f}${j.language || ""}
205
- ${j.code || ""}
206
- ${f}`;
207
- },
208
- regExp: NEVER,
209
- replace: NOOP,
210
- type: "element"
191
+ var CODE_BLOCK_NODE_TRANSFORMER = {
192
+ dependencies: [],
193
+ export: (node) => {
194
+ if (node.getType() !== "code-block") return null;
195
+ const j = node.exportJSON();
196
+ const f = fence(j.code || "");
197
+ return `${f}${j.language || ""}\n${j.code || ""}\n${f}`;
198
+ },
199
+ regExp: NEVER,
200
+ replace: NOOP,
201
+ type: "element"
211
202
  };
212
- const LEGACY_CODE_NODE_TRANSFORMER = {
213
- dependencies: [],
214
- export: (node) => {
215
- if (node.getType() !== "code") return null;
216
- const lang = node.getLanguage?.() ?? "";
217
- const text = node.getTextContent();
218
- const f = fence(text);
219
- return `${f}${lang}
220
- ${text}
221
- ${f}`;
222
- },
223
- regExp: NEVER,
224
- replace: NOOP,
225
- type: "element"
203
+ var LEGACY_CODE_NODE_TRANSFORMER = {
204
+ dependencies: [],
205
+ export: (node) => {
206
+ if (node.getType() !== "code") return null;
207
+ const lang = node.getLanguage?.() ?? "";
208
+ const text = node.getTextContent();
209
+ const f = fence(text);
210
+ return `${f}${lang}\n${text}\n${f}`;
211
+ },
212
+ regExp: NEVER,
213
+ replace: NOOP,
214
+ type: "element"
226
215
  };
227
- const LINK_CARD_BLOCK_TRANSFORMER = {
228
- dependencies: [],
229
- export: (node) => {
230
- if (node.getType() !== "link-card") return null;
231
- const j = node.exportJSON();
232
- return j.title ? `[${j.title}](${j.url})` : `<${j.url}>`;
233
- },
234
- regExp: NEVER,
235
- replace: NOOP,
236
- type: "element"
216
+ var LINK_CARD_BLOCK_TRANSFORMER = {
217
+ dependencies: [],
218
+ export: (node) => {
219
+ if (node.getType() !== "link-card") return null;
220
+ const j = node.exportJSON();
221
+ return j.title ? `[${j.title}](${j.url})` : `<${j.url}>`;
222
+ },
223
+ regExp: NEVER,
224
+ replace: NOOP,
225
+ type: "element"
237
226
  };
238
- const MERMAID_BLOCK_TRANSFORMER = {
239
- dependencies: [],
240
- export: (node) => {
241
- if (node.getType() !== "mermaid") return null;
242
- const d = node.__diagram ?? "";
243
- const f = fence(d);
244
- return `${f}mermaid
245
- ${d}
246
- ${f}`;
247
- },
248
- regExp: NEVER,
249
- replace: NOOP,
250
- type: "element"
227
+ var MERMAID_BLOCK_TRANSFORMER = {
228
+ dependencies: [],
229
+ export: (node) => {
230
+ if (node.getType() !== "mermaid") return null;
231
+ const d = node.__diagram ?? "";
232
+ const f = fence(d);
233
+ return `${f}mermaid\n${d}\n${f}`;
234
+ },
235
+ regExp: NEVER,
236
+ replace: NOOP,
237
+ type: "element"
251
238
  };
252
- const NESTED_DOC_BLOCK_TRANSFORMER = {
253
- dependencies: [],
254
- export: (node) => {
255
- if (node.getType() !== "nested-doc") return null;
256
- return `<nested-doc>
257
- ${stateText(node.__contentState)}
258
- </nested-doc>`;
259
- },
260
- regExp: NEVER,
261
- replace: NOOP,
262
- type: "element"
239
+ var NESTED_DOC_BLOCK_TRANSFORMER = {
240
+ dependencies: [],
241
+ export: (node) => {
242
+ if (node.getType() !== "nested-doc") return null;
243
+ return `<nested-doc>\n${stateText(node.__contentState)}\n</nested-doc>`;
244
+ },
245
+ regExp: NEVER,
246
+ replace: NOOP,
247
+ type: "element"
263
248
  };
264
- const GRID_CONTAINER_BLOCK_TRANSFORMER = {
265
- dependencies: [],
266
- export: (node) => {
267
- if (node.getType() !== "grid-container") return null;
268
- const j = node.exportJSON();
269
- const cells = (j.cells ?? []).map((c) => `::: cell
270
- ${stateText(c)}
271
- :::`).join("\n");
272
- return `::: grid{cols=${j.cols ?? 2} gap="${qA(String(j.gap ?? "16px"))}"}
273
- ${cells}
274
- :::`;
275
- },
276
- regExp: NEVER,
277
- replace: NOOP,
278
- type: "element"
249
+ var GRID_CONTAINER_BLOCK_TRANSFORMER = {
250
+ dependencies: [],
251
+ export: (node) => {
252
+ if (node.getType() !== "grid-container") return null;
253
+ const j = node.exportJSON();
254
+ const cells = (j.cells ?? []).map((c) => `::: cell\n${stateText(c)}\n:::`).join("\n");
255
+ return `::: grid{cols=${j.cols ?? 2} gap="${qA(String(j.gap ?? "16px"))}"}\n${cells}\n:::`;
256
+ },
257
+ regExp: NEVER,
258
+ replace: NOOP,
259
+ type: "element"
279
260
  };
280
- const HORIZONTAL_RULE_BLOCK_TRANSFORMER = {
281
- dependencies: [],
282
- export: (node) => node.getType() === "horizontalrule" ? "---" : null,
283
- regExp: NEVER,
284
- replace: NOOP,
285
- type: "element"
261
+ var HORIZONTAL_RULE_BLOCK_TRANSFORMER = {
262
+ dependencies: [],
263
+ export: (node) => node.getType() === "horizontalrule" ? "---" : null,
264
+ regExp: NEVER,
265
+ replace: NOOP,
266
+ type: "element"
286
267
  };
287
- const TABLE_BLOCK_TRANSFORMER = {
288
- dependencies: [],
289
- export: (node) => {
290
- if (!$isTableNode(node)) return null;
291
- const rows = node.getChildren().filter($isTableRowNode);
292
- if (rows.length === 0) return "| |\n| --- |";
293
- const data = rows.map(
294
- (row) => row.getChildren().filter($isTableCellNode).map((c) => escCell(c.getTextContent()))
295
- );
296
- const hdr = data[0];
297
- const sep = hdr.map(() => "---");
298
- return [
299
- `| ${hdr.join(" | ")} |`,
300
- `| ${sep.join(" | ")} |`,
301
- ...data.slice(1).map((r) => `| ${r.join(" | ")} |`)
302
- ].join("\n");
303
- },
304
- regExp: NEVER,
305
- replace: NOOP,
306
- type: "element"
268
+ var TABLE_BLOCK_TRANSFORMER = {
269
+ dependencies: [],
270
+ export: (node) => {
271
+ if (!$isTableNode(node)) return null;
272
+ const rows = node.getChildren().filter($isTableRowNode);
273
+ if (rows.length === 0) return "| |\n| --- |";
274
+ const data = rows.map((row) => row.getChildren().filter($isTableCellNode).map((c) => escCell(c.getTextContent())));
275
+ const hdr = data[0];
276
+ const sep = hdr.map(() => "---");
277
+ return [
278
+ `| ${hdr.join(" | ")} |`,
279
+ `| ${sep.join(" | ")} |`,
280
+ ...data.slice(1).map((r) => `| ${r.join(" | ")} |`)
281
+ ].join("\n");
282
+ },
283
+ regExp: NEVER,
284
+ replace: NOOP,
285
+ type: "element"
307
286
  };
308
- const CODE_SNIPPET_BLOCK_TRANSFORMER = {
309
- dependencies: [],
310
- export: (node) => {
311
- if (node.getType() !== "code-snippet") return null;
312
- const j = node.exportJSON();
313
- const body = (j.files ?? []).map((f) => {
314
- const fc = fence(f.code || "");
315
- return [
316
- `::: file{name="${qA(f.filename || "untitled")}" lang="${qA(f.language || "")}"}`,
317
- `${fc}${f.language || ""}`,
318
- f.code || "",
319
- fc,
320
- ":::"
321
- ].join("\n");
322
- }).join("\n");
323
- return `::: code-snippet
324
- ${body}
325
- :::`;
326
- },
327
- regExp: NEVER,
328
- replace: NOOP,
329
- type: "element"
287
+ var CODE_SNIPPET_BLOCK_TRANSFORMER = {
288
+ dependencies: [],
289
+ export: (node) => {
290
+ if (node.getType() !== "code-snippet") return null;
291
+ return `::: code-snippet\n${(node.exportJSON().files ?? []).map((f) => {
292
+ const fc = fence(f.code || "");
293
+ return [
294
+ `::: file{name="${qA(f.filename || "untitled")}" lang="${qA(f.language || "")}"}`,
295
+ `${fc}${f.language || ""}`,
296
+ f.code || "",
297
+ fc,
298
+ ":::"
299
+ ].join("\n");
300
+ }).join("\n")}\n:::`;
301
+ },
302
+ regExp: NEVER,
303
+ replace: NOOP,
304
+ type: "element"
330
305
  };
331
- const EMBED_BLOCK_TRANSFORMER = {
332
- dependencies: [],
333
- export: (node) => node.getType() === "embed" ? `<${node.__url || ""}>` : null,
334
- regExp: NEVER,
335
- replace: NOOP,
336
- type: "element"
306
+ var EMBED_BLOCK_TRANSFORMER = {
307
+ dependencies: [],
308
+ export: (node) => node.getType() === "embed" ? `<${node.__url || ""}>` : null,
309
+ regExp: NEVER,
310
+ replace: NOOP,
311
+ type: "element"
337
312
  };
338
- const GALLERY_BLOCK_TRANSFORMER = {
339
- dependencies: [],
340
- export: (node) => {
341
- if (node.getType() !== "gallery") return null;
342
- const imgs = node.exportJSON().images ?? [];
343
- return imgs.map((i) => `![${i.alt || ""}](${i.src || ""})`).join("\n");
344
- },
345
- regExp: NEVER,
346
- replace: NOOP,
347
- type: "element"
313
+ var GALLERY_BLOCK_TRANSFORMER = {
314
+ dependencies: [],
315
+ export: (node) => {
316
+ if (node.getType() !== "gallery") return null;
317
+ return (node.exportJSON().images ?? []).map((i) => `![${i.alt || ""}](${i.src || ""})`).join("\n");
318
+ },
319
+ regExp: NEVER,
320
+ replace: NOOP,
321
+ type: "element"
348
322
  };
349
- const EXCALIDRAW_BLOCK_TRANSFORMER = {
350
- dependencies: [],
351
- export: (node) => node.getType() === "excalidraw" ? `<excalidraw>
352
- ${node.__snapshot || ""}
353
- </excalidraw>` : null,
354
- regExp: NEVER,
355
- replace: NOOP,
356
- type: "element"
323
+ var EXCALIDRAW_BLOCK_TRANSFORMER = {
324
+ dependencies: [],
325
+ export: (node) => node.getType() === "excalidraw" ? `<excalidraw>\n${node.__snapshot || ""}\n</excalidraw>` : null,
326
+ regExp: NEVER,
327
+ replace: NOOP,
328
+ type: "element"
357
329
  };
358
- const allHeadlessTransformers = [
359
- // Inline
360
- SPOILER_TRANSFORMER,
361
- MENTION_TRANSFORMER,
362
- FOOTNOTE_TRANSFORMER,
363
- INSERT_TRANSFORMER,
364
- SUPERSCRIPT_TRANSFORMER,
365
- SUBSCRIPT_TRANSFORMER,
366
- RUBY_TRANSFORMER,
367
- KATEX_INLINE_TRANSFORMER,
368
- TAG_TRANSFORMER,
369
- // Block (specific first)
370
- FOOTNOTE_SECTION_TRANSFORMER,
371
- CONTAINER_TRANSFORMER,
372
- GIT_ALERT_TRANSFORMER,
373
- CHECK_LIST,
374
- KATEX_BLOCK_TRANSFORMER,
375
- IMAGE_BLOCK_TRANSFORMER,
376
- VIDEO_BLOCK_TRANSFORMER,
377
- CODE_BLOCK_NODE_TRANSFORMER,
378
- LEGACY_CODE_NODE_TRANSFORMER,
379
- LINK_CARD_BLOCK_TRANSFORMER,
380
- MERMAID_BLOCK_TRANSFORMER,
381
- NESTED_DOC_BLOCK_TRANSFORMER,
382
- GRID_CONTAINER_BLOCK_TRANSFORMER,
383
- HORIZONTAL_RULE_BLOCK_TRANSFORMER,
384
- TABLE_BLOCK_TRANSFORMER,
385
- CODE_SNIPPET_BLOCK_TRANSFORMER,
386
- EMBED_BLOCK_TRANSFORMER,
387
- GALLERY_BLOCK_TRANSFORMER,
388
- EXCALIDRAW_BLOCK_TRANSFORMER,
389
- // Standard (heading, quote, list, code, bold, italic, strikethrough, link…)
390
- ...TRANSFORMERS
330
+ var allHeadlessTransformers = [
331
+ SPOILER_TRANSFORMER,
332
+ MENTION_TRANSFORMER,
333
+ FOOTNOTE_TRANSFORMER,
334
+ INSERT_TRANSFORMER,
335
+ SUPERSCRIPT_TRANSFORMER,
336
+ SUBSCRIPT_TRANSFORMER,
337
+ RUBY_TRANSFORMER,
338
+ KATEX_INLINE_TRANSFORMER,
339
+ TAG_TRANSFORMER,
340
+ FOOTNOTE_SECTION_TRANSFORMER,
341
+ CONTAINER_TRANSFORMER,
342
+ GIT_ALERT_TRANSFORMER,
343
+ CHECK_LIST,
344
+ KATEX_BLOCK_TRANSFORMER,
345
+ IMAGE_BLOCK_TRANSFORMER,
346
+ VIDEO_BLOCK_TRANSFORMER,
347
+ CODE_BLOCK_NODE_TRANSFORMER,
348
+ LEGACY_CODE_NODE_TRANSFORMER,
349
+ LINK_CARD_BLOCK_TRANSFORMER,
350
+ MERMAID_BLOCK_TRANSFORMER,
351
+ NESTED_DOC_BLOCK_TRANSFORMER,
352
+ GRID_CONTAINER_BLOCK_TRANSFORMER,
353
+ HORIZONTAL_RULE_BLOCK_TRANSFORMER,
354
+ TABLE_BLOCK_TRANSFORMER,
355
+ CODE_SNIPPET_BLOCK_TRANSFORMER,
356
+ EMBED_BLOCK_TRANSFORMER,
357
+ GALLERY_BLOCK_TRANSFORMER,
358
+ EXCALIDRAW_BLOCK_TRANSFORMER,
359
+ ...TRANSFORMERS
391
360
  ];
361
+ /** Call inside editor.read() to convert current state to Markdown. */
392
362
  function $toMarkdown() {
393
- return $convertToMarkdownString(allHeadlessTransformers);
363
+ return $convertToMarkdownString(allHeadlessTransformers);
394
364
  }
395
- export {
396
- $toMarkdown,
397
- CODE_BLOCK_NODE_TRANSFORMER,
398
- CODE_SNIPPET_BLOCK_TRANSFORMER,
399
- CONTAINER_TRANSFORMER,
400
- EMBED_BLOCK_TRANSFORMER,
401
- EXCALIDRAW_BLOCK_TRANSFORMER,
402
- FOOTNOTE_SECTION_TRANSFORMER,
403
- FOOTNOTE_TRANSFORMER,
404
- GALLERY_BLOCK_TRANSFORMER,
405
- GIT_ALERT_TRANSFORMER,
406
- GRID_CONTAINER_BLOCK_TRANSFORMER,
407
- HORIZONTAL_RULE_BLOCK_TRANSFORMER,
408
- IMAGE_BLOCK_TRANSFORMER,
409
- INSERT_TRANSFORMER,
410
- KATEX_BLOCK_TRANSFORMER,
411
- KATEX_INLINE_TRANSFORMER,
412
- LEGACY_CODE_NODE_TRANSFORMER,
413
- LINK_CARD_BLOCK_TRANSFORMER,
414
- MENTION_TRANSFORMER,
415
- MERMAID_BLOCK_TRANSFORMER,
416
- NESTED_DOC_BLOCK_TRANSFORMER,
417
- RUBY_TRANSFORMER,
418
- SPOILER_TRANSFORMER,
419
- SUBSCRIPT_TRANSFORMER,
420
- SUPERSCRIPT_TRANSFORMER,
421
- TABLE_BLOCK_TRANSFORMER,
422
- TAG_TRANSFORMER,
423
- VIDEO_BLOCK_TRANSFORMER,
424
- allHeadlessTransformers
425
- };
365
+ //#endregion
366
+ export { $toMarkdown, CODE_BLOCK_NODE_TRANSFORMER, CODE_SNIPPET_BLOCK_TRANSFORMER, CONTAINER_TRANSFORMER, EMBED_BLOCK_TRANSFORMER, EXCALIDRAW_BLOCK_TRANSFORMER, FOOTNOTE_SECTION_TRANSFORMER, FOOTNOTE_TRANSFORMER, GALLERY_BLOCK_TRANSFORMER, GIT_ALERT_TRANSFORMER, GRID_CONTAINER_BLOCK_TRANSFORMER, HORIZONTAL_RULE_BLOCK_TRANSFORMER, IMAGE_BLOCK_TRANSFORMER, INSERT_TRANSFORMER, KATEX_BLOCK_TRANSFORMER, KATEX_INLINE_TRANSFORMER, LEGACY_CODE_NODE_TRANSFORMER, LINK_CARD_BLOCK_TRANSFORMER, MENTION_TRANSFORMER, MERMAID_BLOCK_TRANSFORMER, NESTED_DOC_BLOCK_TRANSFORMER, RUBY_TRANSFORMER, SPOILER_TRANSFORMER, SUBSCRIPT_TRANSFORMER, SUPERSCRIPT_TRANSFORMER, TABLE_BLOCK_TRANSFORMER, TAG_TRANSFORMER, VIDEO_BLOCK_TRANSFORMER, allHeadlessTransformers };