@haklex/rich-headless 0.0.82 → 0.0.83

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