astro-md-editor 0.0.3 → 0.0.5
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/.output/nitro.json +1 -1
- package/.output/public/assets/index-UQt6zCrS.js +334 -0
- package/.output/public/assets/{main-_miJG8oz.js → main-DzXOjsqg.js} +1 -1
- package/.output/public/assets/styles-CezfLgHY.css +1 -0
- package/.output/server/{__root-C4T8UKZy.mjs → __root-CL_tq3ov.mjs} +1 -1
- package/.output/server/_libs/mixmark-io__domino.mjs +16632 -0
- package/.output/server/_libs/turndown.mjs +687 -675
- package/.output/server/_ssr/IconPickerPopover-fNUx2jAc.mjs +125 -0
- package/.output/server/_ssr/{ImageAssetBrowser-DWEdNK_g.mjs → ImageAssetBrowser-DNDdTqtf.mjs} +2 -2
- package/.output/server/_ssr/{collections.server-DyZEpKg6.mjs → collections.server-s12asITg.mjs} +24 -1
- package/.output/server/_ssr/{file-history.api-BLrUovD8.mjs → file-history.api-oydnxFVV.mjs} +8 -2
- package/.output/server/_ssr/{image-assets.server-Dn044pdj.mjs → image-assets.server-Ci2E1_Tm.mjs} +4 -2
- package/.output/server/_ssr/{image-preview.api-bqd1erIP.mjs → image-preview.api-pcN5PQhH.mjs} +2 -2
- package/.output/server/_ssr/{index-wJDNoCM2.mjs → index-BjQuGIib.mjs} +7 -2
- package/.output/server/_ssr/{index-2cOxFkCu.mjs → index-Bn1uKwTu.mjs} +527 -97
- package/.output/server/_ssr/index.mjs +17 -11
- package/.output/server/_ssr/{router-sxRLAh5a.mjs → router-dPC3iVPs.mjs} +2 -2
- package/.output/server/{_tanstack-start-manifest_v-CWdBk-ge.mjs → _tanstack-start-manifest_v-Da8tuNDH.mjs} +1 -1
- package/.output/server/index.mjs +50 -50
- package/LICENSE.md +21 -0
- package/README.md +71 -69
- package/package.json +3 -2
- package/scripts/bootstrap-collections.mjs +59 -13
- package/.output/public/assets/index-DVVq2QjK.js +0 -334
- package/.output/public/assets/styles-yeMm8TG7.css +0 -1
|
@@ -1,720 +1,732 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { g as getDefaultExportFromCjs } from "./react.mjs";
|
|
2
|
+
import { r as requireLib } from "./mixmark-io__domino.mjs";
|
|
3
|
+
var turndown_cjs;
|
|
4
|
+
var hasRequiredTurndown_cjs;
|
|
5
|
+
function requireTurndown_cjs() {
|
|
6
|
+
if (hasRequiredTurndown_cjs) return turndown_cjs;
|
|
7
|
+
hasRequiredTurndown_cjs = 1;
|
|
8
|
+
function extend(destination) {
|
|
9
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
10
|
+
var source = arguments[i];
|
|
11
|
+
for (var key in source) {
|
|
12
|
+
if (source.hasOwnProperty(key)) destination[key] = source[key];
|
|
13
|
+
}
|
|
6
14
|
}
|
|
15
|
+
return destination;
|
|
7
16
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function repeat(character, count) {
|
|
11
|
-
return Array(count + 1).join(character);
|
|
12
|
-
}
|
|
13
|
-
function trimLeadingNewlines(string) {
|
|
14
|
-
return string.replace(/^\n*/, "");
|
|
15
|
-
}
|
|
16
|
-
function trimTrailingNewlines(string) {
|
|
17
|
-
var indexEnd = string.length;
|
|
18
|
-
while (indexEnd > 0 && string[indexEnd - 1] === "\n") indexEnd--;
|
|
19
|
-
return string.substring(0, indexEnd);
|
|
20
|
-
}
|
|
21
|
-
function trimNewlines(string) {
|
|
22
|
-
return trimTrailingNewlines(trimLeadingNewlines(string));
|
|
23
|
-
}
|
|
24
|
-
var blockElements = [
|
|
25
|
-
"ADDRESS",
|
|
26
|
-
"ARTICLE",
|
|
27
|
-
"ASIDE",
|
|
28
|
-
"AUDIO",
|
|
29
|
-
"BLOCKQUOTE",
|
|
30
|
-
"BODY",
|
|
31
|
-
"CANVAS",
|
|
32
|
-
"CENTER",
|
|
33
|
-
"DD",
|
|
34
|
-
"DIR",
|
|
35
|
-
"DIV",
|
|
36
|
-
"DL",
|
|
37
|
-
"DT",
|
|
38
|
-
"FIELDSET",
|
|
39
|
-
"FIGCAPTION",
|
|
40
|
-
"FIGURE",
|
|
41
|
-
"FOOTER",
|
|
42
|
-
"FORM",
|
|
43
|
-
"FRAMESET",
|
|
44
|
-
"H1",
|
|
45
|
-
"H2",
|
|
46
|
-
"H3",
|
|
47
|
-
"H4",
|
|
48
|
-
"H5",
|
|
49
|
-
"H6",
|
|
50
|
-
"HEADER",
|
|
51
|
-
"HGROUP",
|
|
52
|
-
"HR",
|
|
53
|
-
"HTML",
|
|
54
|
-
"ISINDEX",
|
|
55
|
-
"LI",
|
|
56
|
-
"MAIN",
|
|
57
|
-
"MENU",
|
|
58
|
-
"NAV",
|
|
59
|
-
"NOFRAMES",
|
|
60
|
-
"NOSCRIPT",
|
|
61
|
-
"OL",
|
|
62
|
-
"OUTPUT",
|
|
63
|
-
"P",
|
|
64
|
-
"PRE",
|
|
65
|
-
"SECTION",
|
|
66
|
-
"TABLE",
|
|
67
|
-
"TBODY",
|
|
68
|
-
"TD",
|
|
69
|
-
"TFOOT",
|
|
70
|
-
"TH",
|
|
71
|
-
"THEAD",
|
|
72
|
-
"TR",
|
|
73
|
-
"UL"
|
|
74
|
-
];
|
|
75
|
-
function isBlock(node) {
|
|
76
|
-
return is(node, blockElements);
|
|
77
|
-
}
|
|
78
|
-
var voidElements = [
|
|
79
|
-
"AREA",
|
|
80
|
-
"BASE",
|
|
81
|
-
"BR",
|
|
82
|
-
"COL",
|
|
83
|
-
"COMMAND",
|
|
84
|
-
"EMBED",
|
|
85
|
-
"HR",
|
|
86
|
-
"IMG",
|
|
87
|
-
"INPUT",
|
|
88
|
-
"KEYGEN",
|
|
89
|
-
"LINK",
|
|
90
|
-
"META",
|
|
91
|
-
"PARAM",
|
|
92
|
-
"SOURCE",
|
|
93
|
-
"TRACK",
|
|
94
|
-
"WBR"
|
|
95
|
-
];
|
|
96
|
-
function isVoid(node) {
|
|
97
|
-
return is(node, voidElements);
|
|
98
|
-
}
|
|
99
|
-
function hasVoid(node) {
|
|
100
|
-
return has(node, voidElements);
|
|
101
|
-
}
|
|
102
|
-
var meaningfulWhenBlankElements = [
|
|
103
|
-
"A",
|
|
104
|
-
"TABLE",
|
|
105
|
-
"THEAD",
|
|
106
|
-
"TBODY",
|
|
107
|
-
"TFOOT",
|
|
108
|
-
"TH",
|
|
109
|
-
"TD",
|
|
110
|
-
"IFRAME",
|
|
111
|
-
"SCRIPT",
|
|
112
|
-
"AUDIO",
|
|
113
|
-
"VIDEO"
|
|
114
|
-
];
|
|
115
|
-
function isMeaningfulWhenBlank(node) {
|
|
116
|
-
return is(node, meaningfulWhenBlankElements);
|
|
117
|
-
}
|
|
118
|
-
function hasMeaningfulWhenBlank(node) {
|
|
119
|
-
return has(node, meaningfulWhenBlankElements);
|
|
120
|
-
}
|
|
121
|
-
function is(node, tagNames) {
|
|
122
|
-
return tagNames.indexOf(node.nodeName) >= 0;
|
|
123
|
-
}
|
|
124
|
-
function has(node, tagNames) {
|
|
125
|
-
return node.getElementsByTagName && tagNames.some(function(tagName) {
|
|
126
|
-
return node.getElementsByTagName(tagName).length;
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
var rules = {};
|
|
130
|
-
rules.paragraph = {
|
|
131
|
-
filter: "p",
|
|
132
|
-
replacement: function(content) {
|
|
133
|
-
return "\n\n" + content + "\n\n";
|
|
17
|
+
function repeat(character, count) {
|
|
18
|
+
return Array(count + 1).join(character);
|
|
134
19
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
filter: "br",
|
|
138
|
-
replacement: function(content, node, options) {
|
|
139
|
-
return options.br + "\n";
|
|
20
|
+
function trimLeadingNewlines(string) {
|
|
21
|
+
return string.replace(/^\n*/, "");
|
|
140
22
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
var hLevel = Number(node.nodeName.charAt(1));
|
|
146
|
-
if (options.headingStyle === "setext" && hLevel < 3) {
|
|
147
|
-
var underline = repeat(hLevel === 1 ? "=" : "-", content.length);
|
|
148
|
-
return "\n\n" + content + "\n" + underline + "\n\n";
|
|
149
|
-
} else {
|
|
150
|
-
return "\n\n" + repeat("#", hLevel) + " " + content + "\n\n";
|
|
151
|
-
}
|
|
23
|
+
function trimTrailingNewlines(string) {
|
|
24
|
+
var indexEnd = string.length;
|
|
25
|
+
while (indexEnd > 0 && string[indexEnd - 1] === "\n") indexEnd--;
|
|
26
|
+
return string.substring(0, indexEnd);
|
|
152
27
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
filter: "blockquote",
|
|
156
|
-
replacement: function(content) {
|
|
157
|
-
content = trimNewlines(content).replace(/^/gm, "> ");
|
|
158
|
-
return "\n\n" + content + "\n\n";
|
|
28
|
+
function trimNewlines(string) {
|
|
29
|
+
return trimTrailingNewlines(trimLeadingNewlines(string));
|
|
159
30
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
31
|
+
var blockElements = [
|
|
32
|
+
"ADDRESS",
|
|
33
|
+
"ARTICLE",
|
|
34
|
+
"ASIDE",
|
|
35
|
+
"AUDIO",
|
|
36
|
+
"BLOCKQUOTE",
|
|
37
|
+
"BODY",
|
|
38
|
+
"CANVAS",
|
|
39
|
+
"CENTER",
|
|
40
|
+
"DD",
|
|
41
|
+
"DIR",
|
|
42
|
+
"DIV",
|
|
43
|
+
"DL",
|
|
44
|
+
"DT",
|
|
45
|
+
"FIELDSET",
|
|
46
|
+
"FIGCAPTION",
|
|
47
|
+
"FIGURE",
|
|
48
|
+
"FOOTER",
|
|
49
|
+
"FORM",
|
|
50
|
+
"FRAMESET",
|
|
51
|
+
"H1",
|
|
52
|
+
"H2",
|
|
53
|
+
"H3",
|
|
54
|
+
"H4",
|
|
55
|
+
"H5",
|
|
56
|
+
"H6",
|
|
57
|
+
"HEADER",
|
|
58
|
+
"HGROUP",
|
|
59
|
+
"HR",
|
|
60
|
+
"HTML",
|
|
61
|
+
"ISINDEX",
|
|
62
|
+
"LI",
|
|
63
|
+
"MAIN",
|
|
64
|
+
"MENU",
|
|
65
|
+
"NAV",
|
|
66
|
+
"NOFRAMES",
|
|
67
|
+
"NOSCRIPT",
|
|
68
|
+
"OL",
|
|
69
|
+
"OUTPUT",
|
|
70
|
+
"P",
|
|
71
|
+
"PRE",
|
|
72
|
+
"SECTION",
|
|
73
|
+
"TABLE",
|
|
74
|
+
"TBODY",
|
|
75
|
+
"TD",
|
|
76
|
+
"TFOOT",
|
|
77
|
+
"TH",
|
|
78
|
+
"THEAD",
|
|
79
|
+
"TR",
|
|
80
|
+
"UL"
|
|
81
|
+
];
|
|
82
|
+
function isBlock(node) {
|
|
83
|
+
return is(node, blockElements);
|
|
170
84
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
85
|
+
var voidElements = [
|
|
86
|
+
"AREA",
|
|
87
|
+
"BASE",
|
|
88
|
+
"BR",
|
|
89
|
+
"COL",
|
|
90
|
+
"COMMAND",
|
|
91
|
+
"EMBED",
|
|
92
|
+
"HR",
|
|
93
|
+
"IMG",
|
|
94
|
+
"INPUT",
|
|
95
|
+
"KEYGEN",
|
|
96
|
+
"LINK",
|
|
97
|
+
"META",
|
|
98
|
+
"PARAM",
|
|
99
|
+
"SOURCE",
|
|
100
|
+
"TRACK",
|
|
101
|
+
"WBR"
|
|
102
|
+
];
|
|
103
|
+
function isVoid(node) {
|
|
104
|
+
return is(node, voidElements);
|
|
186
105
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
filter: function(node, options) {
|
|
190
|
-
return options.codeBlockStyle === "indented" && node.nodeName === "PRE" && node.firstChild && node.firstChild.nodeName === "CODE";
|
|
191
|
-
},
|
|
192
|
-
replacement: function(content, node, options) {
|
|
193
|
-
return "\n\n " + node.firstChild.textContent.replace(/\n/g, "\n ") + "\n\n";
|
|
106
|
+
function hasVoid(node) {
|
|
107
|
+
return has(node, voidElements);
|
|
194
108
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
fenceSize = match[0].length + 1;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
var fence = repeat(fenceChar, fenceSize);
|
|
214
|
-
return "\n\n" + fence + language + "\n" + code.replace(/\n$/, "") + "\n" + fence + "\n\n";
|
|
109
|
+
var meaningfulWhenBlankElements = [
|
|
110
|
+
"A",
|
|
111
|
+
"TABLE",
|
|
112
|
+
"THEAD",
|
|
113
|
+
"TBODY",
|
|
114
|
+
"TFOOT",
|
|
115
|
+
"TH",
|
|
116
|
+
"TD",
|
|
117
|
+
"IFRAME",
|
|
118
|
+
"SCRIPT",
|
|
119
|
+
"AUDIO",
|
|
120
|
+
"VIDEO"
|
|
121
|
+
];
|
|
122
|
+
function isMeaningfulWhenBlank(node) {
|
|
123
|
+
return is(node, meaningfulWhenBlankElements);
|
|
215
124
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
filter: "hr",
|
|
219
|
-
replacement: function(content, node, options) {
|
|
220
|
-
return "\n\n" + options.hr + "\n\n";
|
|
125
|
+
function hasMeaningfulWhenBlank(node) {
|
|
126
|
+
return has(node, meaningfulWhenBlankElements);
|
|
221
127
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
filter: function(node, options) {
|
|
225
|
-
return options.linkStyle === "inlined" && node.nodeName === "A" && node.getAttribute("href");
|
|
226
|
-
},
|
|
227
|
-
replacement: function(content, node) {
|
|
228
|
-
var href = node.getAttribute("href");
|
|
229
|
-
if (href) href = href.replace(/([()])/g, "\\$1");
|
|
230
|
-
var title = cleanAttribute(node.getAttribute("title"));
|
|
231
|
-
if (title) title = ' "' + title.replace(/"/g, '\\"') + '"';
|
|
232
|
-
return "[" + content + "](" + href + title + ")";
|
|
128
|
+
function is(node, tagNames) {
|
|
129
|
+
return tagNames.indexOf(node.nodeName) >= 0;
|
|
233
130
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
var reference;
|
|
245
|
-
switch (options.linkReferenceStyle) {
|
|
246
|
-
case "collapsed":
|
|
247
|
-
replacement = "[" + content + "][]";
|
|
248
|
-
reference = "[" + content + "]: " + href + title;
|
|
249
|
-
break;
|
|
250
|
-
case "shortcut":
|
|
251
|
-
replacement = "[" + content + "]";
|
|
252
|
-
reference = "[" + content + "]: " + href + title;
|
|
253
|
-
break;
|
|
254
|
-
default:
|
|
255
|
-
var id = this.references.length + 1;
|
|
256
|
-
replacement = "[" + content + "][" + id + "]";
|
|
257
|
-
reference = "[" + id + "]: " + href + title;
|
|
131
|
+
function has(node, tagNames) {
|
|
132
|
+
return node.getElementsByTagName && tagNames.some(function(tagName) {
|
|
133
|
+
return node.getElementsByTagName(tagName).length;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
var rules = {};
|
|
137
|
+
rules.paragraph = {
|
|
138
|
+
filter: "p",
|
|
139
|
+
replacement: function(content) {
|
|
140
|
+
return "\n\n" + content + "\n\n";
|
|
258
141
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
var references = "";
|
|
265
|
-
if (this.references.length) {
|
|
266
|
-
references = "\n\n" + this.references.join("\n") + "\n\n";
|
|
267
|
-
this.references = [];
|
|
142
|
+
};
|
|
143
|
+
rules.lineBreak = {
|
|
144
|
+
filter: "br",
|
|
145
|
+
replacement: function(content, node, options) {
|
|
146
|
+
return options.br + "\n";
|
|
268
147
|
}
|
|
269
|
-
return references;
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
rules.emphasis = {
|
|
273
|
-
filter: ["em", "i"],
|
|
274
|
-
replacement: function(content, node, options) {
|
|
275
|
-
if (!content.trim()) return "";
|
|
276
|
-
return options.emDelimiter + content + options.emDelimiter;
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
rules.strong = {
|
|
280
|
-
filter: ["strong", "b"],
|
|
281
|
-
replacement: function(content, node, options) {
|
|
282
|
-
if (!content.trim()) return "";
|
|
283
|
-
return options.strongDelimiter + content + options.strongDelimiter;
|
|
284
|
-
}
|
|
285
|
-
};
|
|
286
|
-
rules.code = {
|
|
287
|
-
filter: function(node) {
|
|
288
|
-
var hasSiblings = node.previousSibling || node.nextSibling;
|
|
289
|
-
var isCodeBlock = node.parentNode.nodeName === "PRE" && !hasSiblings;
|
|
290
|
-
return node.nodeName === "CODE" && !isCodeBlock;
|
|
291
|
-
},
|
|
292
|
-
replacement: function(content) {
|
|
293
|
-
if (!content) return "";
|
|
294
|
-
content = content.replace(/\r?\n|\r/g, " ");
|
|
295
|
-
var extraSpace = /^`|^ .*?[^ ].* $|`$/.test(content) ? " " : "";
|
|
296
|
-
var delimiter = "`";
|
|
297
|
-
var matches = content.match(/`+/gm) || [];
|
|
298
|
-
while (matches.indexOf(delimiter) !== -1) delimiter = delimiter + "`";
|
|
299
|
-
return delimiter + extraSpace + content + extraSpace + delimiter;
|
|
300
|
-
}
|
|
301
|
-
};
|
|
302
|
-
rules.image = {
|
|
303
|
-
filter: "img",
|
|
304
|
-
replacement: function(content, node) {
|
|
305
|
-
var alt = cleanAttribute(node.getAttribute("alt"));
|
|
306
|
-
var src = node.getAttribute("src") || "";
|
|
307
|
-
var title = cleanAttribute(node.getAttribute("title"));
|
|
308
|
-
var titlePart = title ? ' "' + title + '"' : "";
|
|
309
|
-
return src ? "" : "";
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
function cleanAttribute(attribute) {
|
|
313
|
-
return attribute ? attribute.replace(/(\n+\s*)+/g, "\n") : "";
|
|
314
|
-
}
|
|
315
|
-
function Rules(options) {
|
|
316
|
-
this.options = options;
|
|
317
|
-
this._keep = [];
|
|
318
|
-
this._remove = [];
|
|
319
|
-
this.blankRule = {
|
|
320
|
-
replacement: options.blankReplacement
|
|
321
148
|
};
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
replacement: options
|
|
149
|
+
rules.heading = {
|
|
150
|
+
filter: ["h1", "h2", "h3", "h4", "h5", "h6"],
|
|
151
|
+
replacement: function(content, node, options) {
|
|
152
|
+
var hLevel = Number(node.nodeName.charAt(1));
|
|
153
|
+
if (options.headingStyle === "setext" && hLevel < 3) {
|
|
154
|
+
var underline = repeat(hLevel === 1 ? "=" : "-", content.length);
|
|
155
|
+
return "\n\n" + content + "\n" + underline + "\n\n";
|
|
156
|
+
} else {
|
|
157
|
+
return "\n\n" + repeat("#", hLevel) + " " + content + "\n\n";
|
|
158
|
+
}
|
|
159
|
+
}
|
|
325
160
|
};
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
filter,
|
|
342
|
-
replacement: function() {
|
|
343
|
-
return "";
|
|
161
|
+
rules.blockquote = {
|
|
162
|
+
filter: "blockquote",
|
|
163
|
+
replacement: function(content) {
|
|
164
|
+
content = trimNewlines(content).replace(/^/gm, "> ");
|
|
165
|
+
return "\n\n" + content + "\n\n";
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
rules.list = {
|
|
169
|
+
filter: ["ul", "ol"],
|
|
170
|
+
replacement: function(content, node) {
|
|
171
|
+
var parent = node.parentNode;
|
|
172
|
+
if (parent.nodeName === "LI" && parent.lastElementChild === node) {
|
|
173
|
+
return "\n" + content;
|
|
174
|
+
} else {
|
|
175
|
+
return "\n\n" + content + "\n\n";
|
|
344
176
|
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
rules.listItem = {
|
|
180
|
+
filter: "li",
|
|
181
|
+
replacement: function(content, node, options) {
|
|
182
|
+
var prefix = options.bulletListMarker + " ";
|
|
183
|
+
var parent = node.parentNode;
|
|
184
|
+
if (parent.nodeName === "OL") {
|
|
185
|
+
var start = parent.getAttribute("start");
|
|
186
|
+
var index = Array.prototype.indexOf.call(parent.children, node);
|
|
187
|
+
prefix = (start ? Number(start) + index : index + 1) + ". ";
|
|
188
|
+
}
|
|
189
|
+
var isParagraph = /\n$/.test(content);
|
|
190
|
+
content = trimNewlines(content) + (isParagraph ? "\n" : "");
|
|
191
|
+
content = content.replace(/\n/gm, "\n" + " ".repeat(prefix.length));
|
|
192
|
+
return prefix + content + (node.nextSibling ? "\n" : "");
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
rules.indentedCodeBlock = {
|
|
196
|
+
filter: function(node, options) {
|
|
197
|
+
return options.codeBlockStyle === "indented" && node.nodeName === "PRE" && node.firstChild && node.firstChild.nodeName === "CODE";
|
|
198
|
+
},
|
|
199
|
+
replacement: function(content, node, options) {
|
|
200
|
+
return "\n\n " + node.firstChild.textContent.replace(/\n/g, "\n ") + "\n\n";
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
rules.fencedCodeBlock = {
|
|
204
|
+
filter: function(node, options) {
|
|
205
|
+
return options.codeBlockStyle === "fenced" && node.nodeName === "PRE" && node.firstChild && node.firstChild.nodeName === "CODE";
|
|
206
|
+
},
|
|
207
|
+
replacement: function(content, node, options) {
|
|
208
|
+
var className = node.firstChild.getAttribute("class") || "";
|
|
209
|
+
var language = (className.match(/language-(\S+)/) || [null, ""])[1];
|
|
210
|
+
var code = node.firstChild.textContent;
|
|
211
|
+
var fenceChar = options.fence.charAt(0);
|
|
212
|
+
var fenceSize = 3;
|
|
213
|
+
var fenceInCodeRegex = new RegExp("^" + fenceChar + "{3,}", "gm");
|
|
214
|
+
var match;
|
|
215
|
+
while (match = fenceInCodeRegex.exec(code)) {
|
|
216
|
+
if (match[0].length >= fenceSize) {
|
|
217
|
+
fenceSize = match[0].length + 1;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
var fence = repeat(fenceChar, fenceSize);
|
|
221
|
+
return "\n\n" + fence + language + "\n" + code.replace(/\n$/, "") + "\n" + fence + "\n\n";
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
rules.horizontalRule = {
|
|
225
|
+
filter: "hr",
|
|
226
|
+
replacement: function(content, node, options) {
|
|
227
|
+
return "\n\n" + options.hr + "\n\n";
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
rules.inlineLink = {
|
|
231
|
+
filter: function(node, options) {
|
|
232
|
+
return options.linkStyle === "inlined" && node.nodeName === "A" && node.getAttribute("href");
|
|
233
|
+
},
|
|
234
|
+
replacement: function(content, node) {
|
|
235
|
+
var href = node.getAttribute("href");
|
|
236
|
+
if (href) href = href.replace(/([()])/g, "\\$1");
|
|
237
|
+
var title = cleanAttribute(node.getAttribute("title"));
|
|
238
|
+
if (title) title = ' "' + title.replace(/"/g, '\\"') + '"';
|
|
239
|
+
return "[" + content + "](" + href + title + ")";
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
rules.referenceLink = {
|
|
243
|
+
filter: function(node, options) {
|
|
244
|
+
return options.linkStyle === "referenced" && node.nodeName === "A" && node.getAttribute("href");
|
|
245
|
+
},
|
|
246
|
+
replacement: function(content, node, options) {
|
|
247
|
+
var href = node.getAttribute("href");
|
|
248
|
+
var title = cleanAttribute(node.getAttribute("title"));
|
|
249
|
+
if (title) title = ' "' + title + '"';
|
|
250
|
+
var replacement;
|
|
251
|
+
var reference;
|
|
252
|
+
switch (options.linkReferenceStyle) {
|
|
253
|
+
case "collapsed":
|
|
254
|
+
replacement = "[" + content + "][]";
|
|
255
|
+
reference = "[" + content + "]: " + href + title;
|
|
256
|
+
break;
|
|
257
|
+
case "shortcut":
|
|
258
|
+
replacement = "[" + content + "]";
|
|
259
|
+
reference = "[" + content + "]: " + href + title;
|
|
260
|
+
break;
|
|
261
|
+
default:
|
|
262
|
+
var id = this.references.length + 1;
|
|
263
|
+
replacement = "[" + content + "][" + id + "]";
|
|
264
|
+
reference = "[" + id + "]: " + href + title;
|
|
265
|
+
}
|
|
266
|
+
this.references.push(reference);
|
|
267
|
+
return replacement;
|
|
268
|
+
},
|
|
269
|
+
references: [],
|
|
270
|
+
append: function(options) {
|
|
271
|
+
var references = "";
|
|
272
|
+
if (this.references.length) {
|
|
273
|
+
references = "\n\n" + this.references.join("\n") + "\n\n";
|
|
274
|
+
this.references = [];
|
|
275
|
+
}
|
|
276
|
+
return references;
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
rules.emphasis = {
|
|
280
|
+
filter: ["em", "i"],
|
|
281
|
+
replacement: function(content, node, options) {
|
|
282
|
+
if (!content.trim()) return "";
|
|
283
|
+
return options.emDelimiter + content + options.emDelimiter;
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
rules.strong = {
|
|
287
|
+
filter: ["strong", "b"],
|
|
288
|
+
replacement: function(content, node, options) {
|
|
289
|
+
if (!content.trim()) return "";
|
|
290
|
+
return options.strongDelimiter + content + options.strongDelimiter;
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
rules.code = {
|
|
294
|
+
filter: function(node) {
|
|
295
|
+
var hasSiblings = node.previousSibling || node.nextSibling;
|
|
296
|
+
var isCodeBlock = node.parentNode.nodeName === "PRE" && !hasSiblings;
|
|
297
|
+
return node.nodeName === "CODE" && !isCodeBlock;
|
|
298
|
+
},
|
|
299
|
+
replacement: function(content) {
|
|
300
|
+
if (!content) return "";
|
|
301
|
+
content = content.replace(/\r?\n|\r/g, " ");
|
|
302
|
+
var extraSpace = /^`|^ .*?[^ ].* $|`$/.test(content) ? " " : "";
|
|
303
|
+
var delimiter = "`";
|
|
304
|
+
var matches = content.match(/`+/gm) || [];
|
|
305
|
+
while (matches.indexOf(delimiter) !== -1) delimiter = delimiter + "`";
|
|
306
|
+
return delimiter + extraSpace + content + extraSpace + delimiter;
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
rules.image = {
|
|
310
|
+
filter: "img",
|
|
311
|
+
replacement: function(content, node) {
|
|
312
|
+
var alt = cleanAttribute(node.getAttribute("alt"));
|
|
313
|
+
var src = node.getAttribute("src") || "";
|
|
314
|
+
var title = cleanAttribute(node.getAttribute("title"));
|
|
315
|
+
var titlePart = title ? ' "' + title + '"' : "";
|
|
316
|
+
return src ? "" : "";
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
function cleanAttribute(attribute) {
|
|
320
|
+
return attribute ? attribute.replace(/(\n+\s*)+/g, "\n") : "";
|
|
363
321
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
322
|
+
function Rules(options) {
|
|
323
|
+
this.options = options;
|
|
324
|
+
this._keep = [];
|
|
325
|
+
this._remove = [];
|
|
326
|
+
this.blankRule = {
|
|
327
|
+
replacement: options.blankReplacement
|
|
328
|
+
};
|
|
329
|
+
this.keepReplacement = options.keepReplacement;
|
|
330
|
+
this.defaultRule = {
|
|
331
|
+
replacement: options.defaultReplacement
|
|
332
|
+
};
|
|
333
|
+
this.array = [];
|
|
334
|
+
for (var key in options.rules) this.array.push(options.rules[key]);
|
|
376
335
|
}
|
|
377
|
-
|
|
378
|
-
function
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
336
|
+
Rules.prototype = {
|
|
337
|
+
add: function(key, rule) {
|
|
338
|
+
this.array.unshift(rule);
|
|
339
|
+
},
|
|
340
|
+
keep: function(filter) {
|
|
341
|
+
this._keep.unshift({
|
|
342
|
+
filter,
|
|
343
|
+
replacement: this.keepReplacement
|
|
344
|
+
});
|
|
345
|
+
},
|
|
346
|
+
remove: function(filter) {
|
|
347
|
+
this._remove.unshift({
|
|
348
|
+
filter,
|
|
349
|
+
replacement: function() {
|
|
350
|
+
return "";
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
},
|
|
354
|
+
forNode: function(node) {
|
|
355
|
+
if (node.isBlank) return this.blankRule;
|
|
356
|
+
var rule;
|
|
357
|
+
if (rule = findRule(this.array, node, this.options)) return rule;
|
|
358
|
+
if (rule = findRule(this._keep, node, this.options)) return rule;
|
|
359
|
+
if (rule = findRule(this._remove, node, this.options)) return rule;
|
|
360
|
+
return this.defaultRule;
|
|
361
|
+
},
|
|
362
|
+
forEach: function(fn) {
|
|
363
|
+
for (var i = 0; i < this.array.length; i++) fn(this.array[i], i);
|
|
364
|
+
}
|
|
384
365
|
};
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
366
|
+
function findRule(rules2, node, options) {
|
|
367
|
+
for (var i = 0; i < rules2.length; i++) {
|
|
368
|
+
var rule = rules2[i];
|
|
369
|
+
if (filterValue(rule, node, options)) return rule;
|
|
370
|
+
}
|
|
371
|
+
return void 0;
|
|
372
|
+
}
|
|
373
|
+
function filterValue(rule, node, options) {
|
|
374
|
+
var filter = rule.filter;
|
|
375
|
+
if (typeof filter === "string") {
|
|
376
|
+
if (filter === node.nodeName.toLowerCase()) return true;
|
|
377
|
+
} else if (Array.isArray(filter)) {
|
|
378
|
+
if (filter.indexOf(node.nodeName.toLowerCase()) > -1) return true;
|
|
379
|
+
} else if (typeof filter === "function") {
|
|
380
|
+
if (filter.call(rule, node, options)) return true;
|
|
381
|
+
} else {
|
|
382
|
+
throw new TypeError("`filter` needs to be a string, array, or function");
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
function collapseWhitespace(options) {
|
|
386
|
+
var element = options.element;
|
|
387
|
+
var isBlock2 = options.isBlock;
|
|
388
|
+
var isVoid2 = options.isVoid;
|
|
389
|
+
var isPre = options.isPre || function(node2) {
|
|
390
|
+
return node2.nodeName === "PRE";
|
|
391
|
+
};
|
|
392
|
+
if (!element.firstChild || isPre(element)) return;
|
|
393
|
+
var prevText = null;
|
|
394
|
+
var keepLeadingWs = false;
|
|
395
|
+
var prev = null;
|
|
396
|
+
var node = next(prev, element, isPre);
|
|
397
|
+
while (node !== element) {
|
|
398
|
+
if (node.nodeType === 3 || node.nodeType === 4) {
|
|
399
|
+
var text = node.data.replace(/[ \r\n\t]+/g, " ");
|
|
400
|
+
if ((!prevText || / $/.test(prevText.data)) && !keepLeadingWs && text[0] === " ") {
|
|
401
|
+
text = text.substr(1);
|
|
402
|
+
}
|
|
403
|
+
if (!text) {
|
|
404
|
+
node = remove(node);
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
node.data = text;
|
|
408
|
+
prevText = node;
|
|
409
|
+
} else if (node.nodeType === 1) {
|
|
410
|
+
if (isBlock2(node) || node.nodeName === "BR") {
|
|
411
|
+
if (prevText) {
|
|
412
|
+
prevText.data = prevText.data.replace(/ $/, "");
|
|
413
|
+
}
|
|
414
|
+
prevText = null;
|
|
415
|
+
keepLeadingWs = false;
|
|
416
|
+
} else if (isVoid2(node) || isPre(node)) {
|
|
417
|
+
prevText = null;
|
|
418
|
+
keepLeadingWs = true;
|
|
419
|
+
} else if (prevText) {
|
|
420
|
+
keepLeadingWs = false;
|
|
421
|
+
}
|
|
422
|
+
} else {
|
|
397
423
|
node = remove(node);
|
|
398
424
|
continue;
|
|
399
425
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
if (isBlock2(node) || node.nodeName === "BR") {
|
|
404
|
-
if (prevText) {
|
|
405
|
-
prevText.data = prevText.data.replace(/ $/, "");
|
|
406
|
-
}
|
|
407
|
-
prevText = null;
|
|
408
|
-
keepLeadingWs = false;
|
|
409
|
-
} else if (isVoid2(node) || isPre(node)) {
|
|
410
|
-
prevText = null;
|
|
411
|
-
keepLeadingWs = true;
|
|
412
|
-
} else if (prevText) {
|
|
413
|
-
keepLeadingWs = false;
|
|
414
|
-
}
|
|
415
|
-
} else {
|
|
416
|
-
node = remove(node);
|
|
417
|
-
continue;
|
|
426
|
+
var nextNode = next(prev, node, isPre);
|
|
427
|
+
prev = node;
|
|
428
|
+
node = nextNode;
|
|
418
429
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
prevText.data = prevText.data.replace(/ $/, "");
|
|
425
|
-
if (!prevText.data) {
|
|
426
|
-
remove(prevText);
|
|
430
|
+
if (prevText) {
|
|
431
|
+
prevText.data = prevText.data.replace(/ $/, "");
|
|
432
|
+
if (!prevText.data) {
|
|
433
|
+
remove(prevText);
|
|
434
|
+
}
|
|
427
435
|
}
|
|
428
436
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
return next2;
|
|
434
|
-
}
|
|
435
|
-
function next(prev, current, isPre) {
|
|
436
|
-
if (prev && prev.parentNode === current || isPre(current)) {
|
|
437
|
-
return current.nextSibling || current.parentNode;
|
|
437
|
+
function remove(node) {
|
|
438
|
+
var next2 = node.nextSibling || node.parentNode;
|
|
439
|
+
node.parentNode.removeChild(node);
|
|
440
|
+
return next2;
|
|
438
441
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
function canParseHTMLNatively() {
|
|
443
|
-
var Parser = root.DOMParser;
|
|
444
|
-
var canParse = false;
|
|
445
|
-
try {
|
|
446
|
-
if (new Parser().parseFromString("", "text/html")) {
|
|
447
|
-
canParse = true;
|
|
442
|
+
function next(prev, current, isPre) {
|
|
443
|
+
if (prev && prev.parentNode === current || isPre(current)) {
|
|
444
|
+
return current.nextSibling || current.parentNode;
|
|
448
445
|
}
|
|
449
|
-
|
|
446
|
+
return current.firstChild || current.nextSibling || current.parentNode;
|
|
450
447
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
448
|
+
var root = typeof window !== "undefined" ? window : {};
|
|
449
|
+
function canParseHTMLNatively() {
|
|
450
|
+
var Parser = root.DOMParser;
|
|
451
|
+
var canParse = false;
|
|
452
|
+
try {
|
|
453
|
+
if (new Parser().parseFromString("", "text/html")) {
|
|
454
|
+
canParse = true;
|
|
455
|
+
}
|
|
456
|
+
} catch (e) {
|
|
457
|
+
}
|
|
458
|
+
return canParse;
|
|
459
|
+
}
|
|
460
|
+
function createHTMLParser() {
|
|
461
|
+
var Parser = function() {
|
|
460
462
|
};
|
|
463
|
+
{
|
|
464
|
+
var domino = /* @__PURE__ */ requireLib();
|
|
465
|
+
Parser.prototype.parseFromString = function(string) {
|
|
466
|
+
return domino.createDocument(string);
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
return Parser;
|
|
461
470
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
var
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
"
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
});
|
|
485
|
-
return root2;
|
|
486
|
-
}
|
|
487
|
-
var _htmlParser;
|
|
488
|
-
function htmlParser() {
|
|
489
|
-
_htmlParser = _htmlParser || new HTMLParser();
|
|
490
|
-
return _htmlParser;
|
|
491
|
-
}
|
|
492
|
-
function isPreOrCode(node) {
|
|
493
|
-
return node.nodeName === "PRE" || node.nodeName === "CODE";
|
|
494
|
-
}
|
|
495
|
-
function Node(node, options) {
|
|
496
|
-
node.isBlock = isBlock(node);
|
|
497
|
-
node.isCode = node.nodeName === "CODE" || node.parentNode.isCode;
|
|
498
|
-
node.isBlank = isBlank(node);
|
|
499
|
-
node.flankingWhitespace = flankingWhitespace(node, options);
|
|
500
|
-
return node;
|
|
501
|
-
}
|
|
502
|
-
function isBlank(node) {
|
|
503
|
-
return !isVoid(node) && !isMeaningfulWhenBlank(node) && /^\s*$/i.test(node.textContent) && !hasVoid(node) && !hasMeaningfulWhenBlank(node);
|
|
504
|
-
}
|
|
505
|
-
function flankingWhitespace(node, options) {
|
|
506
|
-
if (node.isBlock || options.preformattedCode && node.isCode) {
|
|
507
|
-
return { leading: "", trailing: "" };
|
|
471
|
+
var HTMLParser = canParseHTMLNatively() ? root.DOMParser : createHTMLParser();
|
|
472
|
+
function RootNode(input, options) {
|
|
473
|
+
var root2;
|
|
474
|
+
if (typeof input === "string") {
|
|
475
|
+
var doc = htmlParser().parseFromString(
|
|
476
|
+
// DOM parsers arrange elements in the <head> and <body>.
|
|
477
|
+
// Wrapping in a custom element ensures elements are reliably arranged in
|
|
478
|
+
// a single element.
|
|
479
|
+
'<x-turndown id="turndown-root">' + input + "</x-turndown>",
|
|
480
|
+
"text/html"
|
|
481
|
+
);
|
|
482
|
+
root2 = doc.getElementById("turndown-root");
|
|
483
|
+
} else {
|
|
484
|
+
root2 = input.cloneNode(true);
|
|
485
|
+
}
|
|
486
|
+
collapseWhitespace({
|
|
487
|
+
element: root2,
|
|
488
|
+
isBlock,
|
|
489
|
+
isVoid,
|
|
490
|
+
isPre: options.preformattedCode ? isPreOrCode : null
|
|
491
|
+
});
|
|
492
|
+
return root2;
|
|
508
493
|
}
|
|
509
|
-
var
|
|
510
|
-
|
|
511
|
-
|
|
494
|
+
var _htmlParser;
|
|
495
|
+
function htmlParser() {
|
|
496
|
+
_htmlParser = _htmlParser || new HTMLParser();
|
|
497
|
+
return _htmlParser;
|
|
512
498
|
}
|
|
513
|
-
|
|
514
|
-
|
|
499
|
+
function isPreOrCode(node) {
|
|
500
|
+
return node.nodeName === "PRE" || node.nodeName === "CODE";
|
|
515
501
|
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
// whole string for whitespace-only strings
|
|
523
|
-
leadingAscii: m[2],
|
|
524
|
-
leadingNonAscii: m[3],
|
|
525
|
-
trailing: m[4],
|
|
526
|
-
// empty for whitespace-only strings
|
|
527
|
-
trailingNonAscii: m[5],
|
|
528
|
-
trailingAscii: m[6]
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
function isFlankedByWhitespace(side, node, options) {
|
|
532
|
-
var sibling;
|
|
533
|
-
var regExp;
|
|
534
|
-
var isFlanked;
|
|
535
|
-
if (side === "left") {
|
|
536
|
-
sibling = node.previousSibling;
|
|
537
|
-
regExp = / $/;
|
|
538
|
-
} else {
|
|
539
|
-
sibling = node.nextSibling;
|
|
540
|
-
regExp = /^ /;
|
|
541
|
-
}
|
|
542
|
-
if (sibling) {
|
|
543
|
-
if (sibling.nodeType === 3) {
|
|
544
|
-
isFlanked = regExp.test(sibling.nodeValue);
|
|
545
|
-
} else if (options.preformattedCode && sibling.nodeName === "CODE") {
|
|
546
|
-
isFlanked = false;
|
|
547
|
-
} else if (sibling.nodeType === 1 && !isBlock(sibling)) {
|
|
548
|
-
isFlanked = regExp.test(sibling.textContent);
|
|
549
|
-
}
|
|
502
|
+
function Node(node, options) {
|
|
503
|
+
node.isBlock = isBlock(node);
|
|
504
|
+
node.isCode = node.nodeName === "CODE" || node.parentNode.isCode;
|
|
505
|
+
node.isBlank = isBlank(node);
|
|
506
|
+
node.flankingWhitespace = flankingWhitespace(node, options);
|
|
507
|
+
return node;
|
|
550
508
|
}
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
[/^-/g, "\\-"],
|
|
558
|
-
[/^\+ /g, "\\+ "],
|
|
559
|
-
[/^(=+)/g, "\\$1"],
|
|
560
|
-
[/^(#{1,6}) /g, "\\$1 "],
|
|
561
|
-
[/`/g, "\\`"],
|
|
562
|
-
[/^~~~/g, "\\~~~"],
|
|
563
|
-
[/\[/g, "\\["],
|
|
564
|
-
[/\]/g, "\\]"],
|
|
565
|
-
[/^>/g, "\\>"],
|
|
566
|
-
[/_/g, "\\_"],
|
|
567
|
-
[/^(\d+)\. /g, "$1\\. "]
|
|
568
|
-
];
|
|
569
|
-
function TurndownService(options) {
|
|
570
|
-
if (!(this instanceof TurndownService)) return new TurndownService(options);
|
|
571
|
-
var defaults = {
|
|
572
|
-
rules,
|
|
573
|
-
headingStyle: "setext",
|
|
574
|
-
hr: "* * *",
|
|
575
|
-
bulletListMarker: "*",
|
|
576
|
-
codeBlockStyle: "indented",
|
|
577
|
-
fence: "```",
|
|
578
|
-
emDelimiter: "_",
|
|
579
|
-
strongDelimiter: "**",
|
|
580
|
-
linkStyle: "inlined",
|
|
581
|
-
linkReferenceStyle: "full",
|
|
582
|
-
br: " ",
|
|
583
|
-
preformattedCode: false,
|
|
584
|
-
blankReplacement: function(content, node) {
|
|
585
|
-
return node.isBlock ? "\n\n" : "";
|
|
586
|
-
},
|
|
587
|
-
keepReplacement: function(content, node) {
|
|
588
|
-
return node.isBlock ? "\n\n" + node.outerHTML + "\n\n" : node.outerHTML;
|
|
589
|
-
},
|
|
590
|
-
defaultReplacement: function(content, node) {
|
|
591
|
-
return node.isBlock ? "\n\n" + content + "\n\n" : content;
|
|
509
|
+
function isBlank(node) {
|
|
510
|
+
return !isVoid(node) && !isMeaningfulWhenBlank(node) && /^\s*$/i.test(node.textContent) && !hasVoid(node) && !hasMeaningfulWhenBlank(node);
|
|
511
|
+
}
|
|
512
|
+
function flankingWhitespace(node, options) {
|
|
513
|
+
if (node.isBlock || options.preformattedCode && node.isCode) {
|
|
514
|
+
return { leading: "", trailing: "" };
|
|
592
515
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
}
|
|
597
|
-
TurndownService.prototype = {
|
|
598
|
-
/**
|
|
599
|
-
* The entry point for converting a string or DOM node to Markdown
|
|
600
|
-
* @public
|
|
601
|
-
* @param {String|HTMLElement} input The string or DOM node to convert
|
|
602
|
-
* @returns A Markdown representation of the input
|
|
603
|
-
* @type String
|
|
604
|
-
*/
|
|
605
|
-
turndown: function(input) {
|
|
606
|
-
if (!canConvert(input)) {
|
|
607
|
-
throw new TypeError(
|
|
608
|
-
input + " is not a string, or an element/document/fragment node."
|
|
609
|
-
);
|
|
516
|
+
var edges = edgeWhitespace(node.textContent);
|
|
517
|
+
if (edges.leadingAscii && isFlankedByWhitespace("left", node, options)) {
|
|
518
|
+
edges.leading = edges.leadingNonAscii;
|
|
610
519
|
}
|
|
611
|
-
if (
|
|
612
|
-
|
|
613
|
-
return postProcess.call(this, output);
|
|
614
|
-
},
|
|
615
|
-
/**
|
|
616
|
-
* Add one or more plugins
|
|
617
|
-
* @public
|
|
618
|
-
* @param {Function|Array} plugin The plugin or array of plugins to add
|
|
619
|
-
* @returns The Turndown instance for chaining
|
|
620
|
-
* @type Object
|
|
621
|
-
*/
|
|
622
|
-
use: function(plugin) {
|
|
623
|
-
if (Array.isArray(plugin)) {
|
|
624
|
-
for (var i = 0; i < plugin.length; i++) this.use(plugin[i]);
|
|
625
|
-
} else if (typeof plugin === "function") {
|
|
626
|
-
plugin(this);
|
|
627
|
-
} else {
|
|
628
|
-
throw new TypeError("plugin must be a Function or an Array of Functions");
|
|
520
|
+
if (edges.trailingAscii && isFlankedByWhitespace("right", node, options)) {
|
|
521
|
+
edges.trailing = edges.trailingNonAscii;
|
|
629
522
|
}
|
|
630
|
-
return
|
|
631
|
-
},
|
|
632
|
-
/**
|
|
633
|
-
* Adds a rule
|
|
634
|
-
* @public
|
|
635
|
-
* @param {String} key The unique key of the rule
|
|
636
|
-
* @param {Object} rule The rule
|
|
637
|
-
* @returns The Turndown instance for chaining
|
|
638
|
-
* @type Object
|
|
639
|
-
*/
|
|
640
|
-
addRule: function(key, rule) {
|
|
641
|
-
this.rules.add(key, rule);
|
|
642
|
-
return this;
|
|
643
|
-
},
|
|
644
|
-
/**
|
|
645
|
-
* Keep a node (as HTML) that matches the filter
|
|
646
|
-
* @public
|
|
647
|
-
* @param {String|Array|Function} filter The unique key of the rule
|
|
648
|
-
* @returns The Turndown instance for chaining
|
|
649
|
-
* @type Object
|
|
650
|
-
*/
|
|
651
|
-
keep: function(filter) {
|
|
652
|
-
this.rules.keep(filter);
|
|
653
|
-
return this;
|
|
654
|
-
},
|
|
655
|
-
/**
|
|
656
|
-
* Remove a node that matches the filter
|
|
657
|
-
* @public
|
|
658
|
-
* @param {String|Array|Function} filter The unique key of the rule
|
|
659
|
-
* @returns The Turndown instance for chaining
|
|
660
|
-
* @type Object
|
|
661
|
-
*/
|
|
662
|
-
remove: function(filter) {
|
|
663
|
-
this.rules.remove(filter);
|
|
664
|
-
return this;
|
|
665
|
-
},
|
|
666
|
-
/**
|
|
667
|
-
* Escapes Markdown syntax
|
|
668
|
-
* @public
|
|
669
|
-
* @param {String} string The string to escape
|
|
670
|
-
* @returns A string with Markdown syntax escaped
|
|
671
|
-
* @type String
|
|
672
|
-
*/
|
|
673
|
-
escape: function(string) {
|
|
674
|
-
return escapes.reduce(function(accumulator, escape) {
|
|
675
|
-
return accumulator.replace(escape[0], escape[1]);
|
|
676
|
-
}, string);
|
|
523
|
+
return { leading: edges.leading, trailing: edges.trailing };
|
|
677
524
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
525
|
+
function edgeWhitespace(string) {
|
|
526
|
+
var m = string.match(/^(([ \t\r\n]*)(\s*))(?:(?=\S)[\s\S]*\S)?((\s*?)([ \t\r\n]*))$/);
|
|
527
|
+
return {
|
|
528
|
+
leading: m[1],
|
|
529
|
+
// whole string for whitespace-only strings
|
|
530
|
+
leadingAscii: m[2],
|
|
531
|
+
leadingNonAscii: m[3],
|
|
532
|
+
trailing: m[4],
|
|
533
|
+
// empty for whitespace-only strings
|
|
534
|
+
trailingNonAscii: m[5],
|
|
535
|
+
trailingAscii: m[6]
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
function isFlankedByWhitespace(side, node, options) {
|
|
539
|
+
var sibling;
|
|
540
|
+
var regExp;
|
|
541
|
+
var isFlanked;
|
|
542
|
+
if (side === "left") {
|
|
543
|
+
sibling = node.previousSibling;
|
|
544
|
+
regExp = / $/;
|
|
545
|
+
} else {
|
|
546
|
+
sibling = node.nextSibling;
|
|
547
|
+
regExp = /^ /;
|
|
688
548
|
}
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
549
|
+
if (sibling) {
|
|
550
|
+
if (sibling.nodeType === 3) {
|
|
551
|
+
isFlanked = regExp.test(sibling.nodeValue);
|
|
552
|
+
} else if (options.preformattedCode && sibling.nodeName === "CODE") {
|
|
553
|
+
isFlanked = false;
|
|
554
|
+
} else if (sibling.nodeType === 1 && !isBlock(sibling)) {
|
|
555
|
+
isFlanked = regExp.test(sibling.textContent);
|
|
556
|
+
}
|
|
697
557
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
558
|
+
return isFlanked;
|
|
559
|
+
}
|
|
560
|
+
var reduce = Array.prototype.reduce;
|
|
561
|
+
var escapes = [
|
|
562
|
+
[/\\/g, "\\\\"],
|
|
563
|
+
[/\*/g, "\\*"],
|
|
564
|
+
[/^-/g, "\\-"],
|
|
565
|
+
[/^\+ /g, "\\+ "],
|
|
566
|
+
[/^(=+)/g, "\\$1"],
|
|
567
|
+
[/^(#{1,6}) /g, "\\$1 "],
|
|
568
|
+
[/`/g, "\\`"],
|
|
569
|
+
[/^~~~/g, "\\~~~"],
|
|
570
|
+
[/\[/g, "\\["],
|
|
571
|
+
[/\]/g, "\\]"],
|
|
572
|
+
[/^>/g, "\\>"],
|
|
573
|
+
[/_/g, "\\_"],
|
|
574
|
+
[/^(\d+)\. /g, "$1\\. "]
|
|
575
|
+
];
|
|
576
|
+
function TurndownService2(options) {
|
|
577
|
+
if (!(this instanceof TurndownService2)) return new TurndownService2(options);
|
|
578
|
+
var defaults = {
|
|
579
|
+
rules,
|
|
580
|
+
headingStyle: "setext",
|
|
581
|
+
hr: "* * *",
|
|
582
|
+
bulletListMarker: "*",
|
|
583
|
+
codeBlockStyle: "indented",
|
|
584
|
+
fence: "```",
|
|
585
|
+
emDelimiter: "_",
|
|
586
|
+
strongDelimiter: "**",
|
|
587
|
+
linkStyle: "inlined",
|
|
588
|
+
linkReferenceStyle: "full",
|
|
589
|
+
br: " ",
|
|
590
|
+
preformattedCode: false,
|
|
591
|
+
blankReplacement: function(content, node) {
|
|
592
|
+
return node.isBlock ? "\n\n" : "";
|
|
593
|
+
},
|
|
594
|
+
keepReplacement: function(content, node) {
|
|
595
|
+
return node.isBlock ? "\n\n" + node.outerHTML + "\n\n" : node.outerHTML;
|
|
596
|
+
},
|
|
597
|
+
defaultReplacement: function(content, node) {
|
|
598
|
+
return node.isBlock ? "\n\n" + content + "\n\n" : content;
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
this.options = extend({}, defaults, options);
|
|
602
|
+
this.rules = new Rules(this.options);
|
|
603
|
+
}
|
|
604
|
+
TurndownService2.prototype = {
|
|
605
|
+
/**
|
|
606
|
+
* The entry point for converting a string or DOM node to Markdown
|
|
607
|
+
* @public
|
|
608
|
+
* @param {String|HTMLElement} input The string or DOM node to convert
|
|
609
|
+
* @returns A Markdown representation of the input
|
|
610
|
+
* @type String
|
|
611
|
+
*/
|
|
612
|
+
turndown: function(input) {
|
|
613
|
+
if (!canConvert(input)) {
|
|
614
|
+
throw new TypeError(
|
|
615
|
+
input + " is not a string, or an element/document/fragment node."
|
|
616
|
+
);
|
|
617
|
+
}
|
|
618
|
+
if (input === "") return "";
|
|
619
|
+
var output = process.call(this, new RootNode(input, this.options));
|
|
620
|
+
return postProcess.call(this, output);
|
|
621
|
+
},
|
|
622
|
+
/**
|
|
623
|
+
* Add one or more plugins
|
|
624
|
+
* @public
|
|
625
|
+
* @param {Function|Array} plugin The plugin or array of plugins to add
|
|
626
|
+
* @returns The Turndown instance for chaining
|
|
627
|
+
* @type Object
|
|
628
|
+
*/
|
|
629
|
+
use: function(plugin) {
|
|
630
|
+
if (Array.isArray(plugin)) {
|
|
631
|
+
for (var i = 0; i < plugin.length; i++) this.use(plugin[i]);
|
|
632
|
+
} else if (typeof plugin === "function") {
|
|
633
|
+
plugin(this);
|
|
634
|
+
} else {
|
|
635
|
+
throw new TypeError("plugin must be a Function or an Array of Functions");
|
|
636
|
+
}
|
|
637
|
+
return this;
|
|
638
|
+
},
|
|
639
|
+
/**
|
|
640
|
+
* Adds a rule
|
|
641
|
+
* @public
|
|
642
|
+
* @param {String} key The unique key of the rule
|
|
643
|
+
* @param {Object} rule The rule
|
|
644
|
+
* @returns The Turndown instance for chaining
|
|
645
|
+
* @type Object
|
|
646
|
+
*/
|
|
647
|
+
addRule: function(key, rule) {
|
|
648
|
+
this.rules.add(key, rule);
|
|
649
|
+
return this;
|
|
650
|
+
},
|
|
651
|
+
/**
|
|
652
|
+
* Keep a node (as HTML) that matches the filter
|
|
653
|
+
* @public
|
|
654
|
+
* @param {String|Array|Function} filter The unique key of the rule
|
|
655
|
+
* @returns The Turndown instance for chaining
|
|
656
|
+
* @type Object
|
|
657
|
+
*/
|
|
658
|
+
keep: function(filter) {
|
|
659
|
+
this.rules.keep(filter);
|
|
660
|
+
return this;
|
|
661
|
+
},
|
|
662
|
+
/**
|
|
663
|
+
* Remove a node that matches the filter
|
|
664
|
+
* @public
|
|
665
|
+
* @param {String|Array|Function} filter The unique key of the rule
|
|
666
|
+
* @returns The Turndown instance for chaining
|
|
667
|
+
* @type Object
|
|
668
|
+
*/
|
|
669
|
+
remove: function(filter) {
|
|
670
|
+
this.rules.remove(filter);
|
|
671
|
+
return this;
|
|
672
|
+
},
|
|
673
|
+
/**
|
|
674
|
+
* Escapes Markdown syntax
|
|
675
|
+
* @public
|
|
676
|
+
* @param {String} string The string to escape
|
|
677
|
+
* @returns A string with Markdown syntax escaped
|
|
678
|
+
* @type String
|
|
679
|
+
*/
|
|
680
|
+
escape: function(string) {
|
|
681
|
+
return escapes.reduce(function(accumulator, escape) {
|
|
682
|
+
return accumulator.replace(escape[0], escape[1]);
|
|
683
|
+
}, string);
|
|
684
|
+
}
|
|
685
|
+
};
|
|
686
|
+
function process(parentNode) {
|
|
687
|
+
var self = this;
|
|
688
|
+
return reduce.call(parentNode.childNodes, function(output, node) {
|
|
689
|
+
node = new Node(node, self.options);
|
|
690
|
+
var replacement = "";
|
|
691
|
+
if (node.nodeType === 3) {
|
|
692
|
+
replacement = node.isCode ? node.nodeValue : self.escape(node.nodeValue);
|
|
693
|
+
} else if (node.nodeType === 1) {
|
|
694
|
+
replacement = replacementForNode.call(self, node);
|
|
695
|
+
}
|
|
696
|
+
return join(output, replacement);
|
|
697
|
+
}, "");
|
|
698
|
+
}
|
|
699
|
+
function postProcess(output) {
|
|
700
|
+
var self = this;
|
|
701
|
+
this.rules.forEach(function(rule) {
|
|
702
|
+
if (typeof rule.append === "function") {
|
|
703
|
+
output = join(output, rule.append(self.options));
|
|
704
|
+
}
|
|
705
|
+
});
|
|
706
|
+
return output.replace(/^[\t\r\n]+/, "").replace(/[\t\r\n\s]+$/, "");
|
|
707
|
+
}
|
|
708
|
+
function replacementForNode(node) {
|
|
709
|
+
var rule = this.rules.forNode(node);
|
|
710
|
+
var content = process.call(this, node);
|
|
711
|
+
var whitespace = node.flankingWhitespace;
|
|
712
|
+
if (whitespace.leading || whitespace.trailing) content = content.trim();
|
|
713
|
+
return whitespace.leading + rule.replacement(content, node, this.options) + whitespace.trailing;
|
|
714
|
+
}
|
|
715
|
+
function join(output, replacement) {
|
|
716
|
+
var s1 = trimTrailingNewlines(output);
|
|
717
|
+
var s2 = trimLeadingNewlines(replacement);
|
|
718
|
+
var nls = Math.max(output.length - s1.length, replacement.length - s2.length);
|
|
719
|
+
var separator = "\n\n".substring(0, nls);
|
|
720
|
+
return s1 + separator + s2;
|
|
721
|
+
}
|
|
722
|
+
function canConvert(input) {
|
|
723
|
+
return input != null && (typeof input === "string" || input.nodeType && (input.nodeType === 1 || input.nodeType === 9 || input.nodeType === 11));
|
|
724
|
+
}
|
|
725
|
+
turndown_cjs = TurndownService2;
|
|
726
|
+
return turndown_cjs;
|
|
717
727
|
}
|
|
728
|
+
var turndown_cjsExports = /* @__PURE__ */ requireTurndown_cjs();
|
|
729
|
+
const TurndownService = /* @__PURE__ */ getDefaultExportFromCjs(turndown_cjsExports);
|
|
718
730
|
export {
|
|
719
731
|
TurndownService as T
|
|
720
732
|
};
|