@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.
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +461 -443
- package/dist/transformers.d.ts +1 -0
- package/dist/transformers.d.ts.map +1 -1
- package/dist/transformers.mjs +393 -323
- package/package.json +1 -1
package/dist/transformers.mjs
CHANGED
|
@@ -1,366 +1,436 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
7
|
+
return v.replaceAll('"', '\\"');
|
|
12
8
|
}
|
|
13
9
|
function escHtml(v) {
|
|
14
|
-
|
|
10
|
+
return v.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
15
11
|
}
|
|
16
12
|
function escCell(v) {
|
|
17
|
-
|
|
13
|
+
return v.replaceAll("|", "\\|").replaceAll("\n", "<br/>");
|
|
18
14
|
}
|
|
19
15
|
function fence(content) {
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
if (!state || typeof state !== "object") return "";
|
|
27
|
+
const root = state.root;
|
|
28
|
+
return root ? walkText(root) : "";
|
|
32
29
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
const SUPERSCRIPT_TRANSFORMER = {
|
|
92
|
+
format: ["superscript"],
|
|
93
|
+
tag: "^",
|
|
94
|
+
type: "text-format"
|
|
93
95
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
const SUBSCRIPT_TRANSFORMER = {
|
|
97
|
+
format: ["subscript"],
|
|
98
|
+
tag: "~",
|
|
99
|
+
type: "text-format"
|
|
98
100
|
};
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
152
|
+
const ALERT_KEY = {
|
|
153
|
+
note: "NOTE",
|
|
154
|
+
tip: "TIP",
|
|
155
|
+
important: "IMPORTANT",
|
|
156
|
+
warning: "WARNING",
|
|
157
|
+
caution: "CAUTION"
|
|
142
158
|
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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 ``;
|
|
187
|
+
},
|
|
188
|
+
regExp: NEVER,
|
|
189
|
+
replace: NOOP,
|
|
190
|
+
type: "element"
|
|
175
191
|
};
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
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
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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) => ``).join("\n");
|
|
353
|
+
},
|
|
354
|
+
regExp: NEVER,
|
|
355
|
+
replace: NOOP,
|
|
356
|
+
type: "element"
|
|
322
357
|
};
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
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
|
-
|
|
403
|
+
return $convertToMarkdownString(allHeadlessTransformers);
|
|
364
404
|
}
|
|
365
|
-
|
|
366
|
-
|
|
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
|
+
};
|