markdown-codec 0.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +215 -0
- package/dist/ast/ast.cjs +25 -0
- package/dist/ast/ast.d.cts +2 -0
- package/dist/ast/ast.d.ts +2 -0
- package/dist/ast/ast.js +23 -0
- package/dist/ast-BXYwy08e.d.cts +160 -0
- package/dist/ast-BXYwy08e.d.ts +160 -0
- package/dist/block/block.cjs +530 -0
- package/dist/block/block.d.cts +18 -0
- package/dist/block/block.d.ts +18 -0
- package/dist/block/block.js +529 -0
- package/dist/block/definitions.cjs +59 -0
- package/dist/block/definitions.d.cts +6 -0
- package/dist/block/definitions.d.ts +6 -0
- package/dist/block/definitions.js +58 -0
- package/dist/block/line.cjs +76 -0
- package/dist/block/line.d.cts +28 -0
- package/dist/block/line.d.ts +28 -0
- package/dist/block/line.js +74 -0
- package/dist/block/list.cjs +110 -0
- package/dist/block/list.d.cts +8 -0
- package/dist/block/list.d.ts +8 -0
- package/dist/block/list.js +107 -0
- package/dist/block/node.cjs +68 -0
- package/dist/block/node.d.cts +45 -0
- package/dist/block/node.d.ts +45 -0
- package/dist/block/node.js +65 -0
- package/dist/block/table.cjs +64 -0
- package/dist/block/table.d.cts +7 -0
- package/dist/block/table.d.ts +7 -0
- package/dist/block/table.js +61 -0
- package/dist/codec.cjs +22 -0
- package/dist/codec.d.cts +492 -0
- package/dist/codec.d.ts +492 -0
- package/dist/codec.js +20 -0
- package/dist/defaults/defaults.cjs +31 -0
- package/dist/defaults/defaults.d.cts +16 -0
- package/dist/defaults/defaults.d.ts +16 -0
- package/dist/defaults/defaults.js +20 -0
- package/dist/diagnostics/diagnostics.cjs +85 -0
- package/dist/diagnostics/diagnostics.d.cts +2 -0
- package/dist/diagnostics/diagnostics.d.ts +2 -0
- package/dist/diagnostics/diagnostics.js +77 -0
- package/dist/diagnostics-DmuWc7d8.d.cts +61 -0
- package/dist/diagnostics-DmuWc7d8.d.ts +61 -0
- package/dist/emit/emit.cjs +228 -0
- package/dist/emit/emit.d.cts +6 -0
- package/dist/emit/emit.d.ts +6 -0
- package/dist/emit/emit.js +227 -0
- package/dist/emit/front-matter.cjs +24 -0
- package/dist/emit/front-matter.d.cts +5 -0
- package/dist/emit/front-matter.d.ts +5 -0
- package/dist/emit/front-matter.js +23 -0
- package/dist/emit/image.cjs +10 -0
- package/dist/emit/image.d.cts +5 -0
- package/dist/emit/image.d.ts +5 -0
- package/dist/emit/image.js +9 -0
- package/dist/emit/inline.cjs +183 -0
- package/dist/emit/inline.d.cts +12 -0
- package/dist/emit/inline.d.ts +12 -0
- package/dist/emit/inline.js +180 -0
- package/dist/emit/table.cjs +73 -0
- package/dist/emit/table.d.cts +10 -0
- package/dist/emit/table.d.ts +10 -0
- package/dist/emit/table.js +72 -0
- package/dist/html/html.cjs +116 -0
- package/dist/html/html.d.cts +2 -0
- package/dist/html/html.d.ts +2 -0
- package/dist/html/html.js +113 -0
- package/dist/html/render.cjs +193 -0
- package/dist/html/render.d.cts +8 -0
- package/dist/html/render.d.ts +8 -0
- package/dist/html/render.js +189 -0
- package/dist/html-bkz2QTuq.d.cts +7 -0
- package/dist/html-bkz2QTuq.d.ts +7 -0
- package/dist/image/image.cjs +129 -0
- package/dist/image/image.d.cts +2 -0
- package/dist/image/image.d.ts +2 -0
- package/dist/image/image.js +125 -0
- package/dist/image-C4KYmz_L.d.cts +19 -0
- package/dist/image-Cm3hT5PS.d.ts +19 -0
- package/dist/image-DescdRgq.d.cts +12 -0
- package/dist/image-DescdRgq.d.ts +12 -0
- package/dist/index.cjs +17 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +5 -0
- package/dist/inline/chars.cjs +50 -0
- package/dist/inline/chars.d.cts +11 -0
- package/dist/inline/chars.d.ts +11 -0
- package/dist/inline/chars.js +42 -0
- package/dist/inline/delimiter.cjs +136 -0
- package/dist/inline/delimiter.d.cts +29 -0
- package/dist/inline/delimiter.d.ts +29 -0
- package/dist/inline/delimiter.js +132 -0
- package/dist/inline/entity.cjs +67 -0
- package/dist/inline/entity.d.cts +9 -0
- package/dist/inline/entity.d.ts +9 -0
- package/dist/inline/entity.js +65 -0
- package/dist/inline/gfm-autolink.cjs +156 -0
- package/dist/inline/gfm-autolink.d.cts +5 -0
- package/dist/inline/gfm-autolink.d.ts +5 -0
- package/dist/inline/gfm-autolink.js +155 -0
- package/dist/inline/inline.cjs +457 -0
- package/dist/inline/inline.d.cts +2 -0
- package/dist/inline/inline.d.ts +2 -0
- package/dist/inline/inline.js +456 -0
- package/dist/inline/link.cjs +130 -0
- package/dist/inline/link.d.cts +2 -0
- package/dist/inline/link.d.ts +2 -0
- package/dist/inline/link.js +124 -0
- package/dist/inline/node.cjs +57 -0
- package/dist/inline/node.d.cts +23 -0
- package/dist/inline/node.d.ts +23 -0
- package/dist/inline/node.js +55 -0
- package/dist/inline-B50cM6cn.d.ts +10 -0
- package/dist/inline-C9YEGDV5.d.cts +10 -0
- package/dist/link-Dv4kxVjk.d.cts +18 -0
- package/dist/link-Dv4kxVjk.d.ts +18 -0
- package/dist/lower/front-matter.cjs +75 -0
- package/dist/lower/front-matter.d.cts +10 -0
- package/dist/lower/front-matter.d.ts +10 -0
- package/dist/lower/front-matter.js +74 -0
- package/dist/lower/image.cjs +29 -0
- package/dist/lower/image.d.cts +2 -0
- package/dist/lower/image.d.ts +2 -0
- package/dist/lower/image.js +28 -0
- package/dist/lower/inline.cjs +96 -0
- package/dist/lower/inline.d.cts +19 -0
- package/dist/lower/inline.d.ts +19 -0
- package/dist/lower/inline.js +93 -0
- package/dist/lower/lower.cjs +293 -0
- package/dist/lower/lower.d.cts +8 -0
- package/dist/lower/lower.d.ts +8 -0
- package/dist/lower/lower.js +291 -0
- package/dist/lower/table.cjs +27 -0
- package/dist/lower/table.d.cts +7 -0
- package/dist/lower/table.d.ts +7 -0
- package/dist/lower/table.js +26 -0
- package/dist/options/options.cjs +0 -0
- package/dist/options/options.d.cts +43 -0
- package/dist/options/options.d.ts +43 -0
- package/dist/options/options.js +0 -0
- package/dist/read.cjs +20 -0
- package/dist/read.d.cts +11 -0
- package/dist/read.d.ts +11 -0
- package/dist/read.js +19 -0
- package/dist/scan/entity-table.cjs +2131 -0
- package/dist/scan/entity-table.d.cts +4 -0
- package/dist/scan/entity-table.d.ts +4 -0
- package/dist/scan/entity-table.js +2130 -0
- package/dist/scan/scan.cjs +80 -0
- package/dist/scan/scan.d.cts +2 -0
- package/dist/scan/scan.d.ts +2 -0
- package/dist/scan/scan.js +78 -0
- package/dist/scan-DeBxgG-r.d.cts +30 -0
- package/dist/scan-DeBxgG-r.d.ts +30 -0
- package/dist/shared/list-id.cjs +36 -0
- package/dist/shared/list-id.d.cts +22 -0
- package/dist/shared/list-id.d.ts +22 -0
- package/dist/shared/list-id.js +32 -0
- package/dist/shared/style-constants.cjs +34 -0
- package/dist/shared/style-constants.d.cts +14 -0
- package/dist/shared/style-constants.d.ts +14 -0
- package/dist/shared/style-constants.js +23 -0
- package/dist/write.cjs +9 -0
- package/dist/write.d.cts +6 -0
- package/dist/write.d.ts +6 -0
- package/dist/write.js +8 -0
- package/package.json +92 -2
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/html/html.ts
|
|
3
|
+
const TAG_NAME = "[A-Za-z][A-Za-z0-9-]*";
|
|
4
|
+
const OPEN_TAG = `<${TAG_NAME}(?:\\s+[a-zA-Z_:][a-zA-Z0-9:._-]*(?:\\s*=\\s*(?:[^"'=<>\`\\x00-\\x20]+|'[^']*'|"[^"]*"))?)*\\s*/?>`;
|
|
5
|
+
const CLOSING_TAG = `</${TAG_NAME}\\s*>`;
|
|
6
|
+
const HTML_TAG_PATTERN = new RegExp(`^(?:${OPEN_TAG}|${CLOSING_TAG}|<!-->|<!--->|<!--[\\s\\S]*?-->|<\\?[\\s\\S]*?\\?>|<![A-Za-z][^>]*>|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>)`);
|
|
7
|
+
function matchHtmlTag(text, start) {
|
|
8
|
+
if (text.charAt(start) !== "<") return;
|
|
9
|
+
const match = HTML_TAG_PATTERN.exec(text.slice(start));
|
|
10
|
+
return match === null ? void 0 : match[0];
|
|
11
|
+
}
|
|
12
|
+
const HTML_BLOCK_START_PATTERNS = [
|
|
13
|
+
/^(?!)/,
|
|
14
|
+
/^<(?:pre|script|style|textarea)(?:[ \t]|>|$)/i,
|
|
15
|
+
/^<!--/,
|
|
16
|
+
/^<\?/,
|
|
17
|
+
/^<![A-Za-z]/,
|
|
18
|
+
/^<!\[CDATA\[/,
|
|
19
|
+
new RegExp(`^</?(?:${[
|
|
20
|
+
"address",
|
|
21
|
+
"article",
|
|
22
|
+
"aside",
|
|
23
|
+
"base",
|
|
24
|
+
"basefont",
|
|
25
|
+
"blockquote",
|
|
26
|
+
"body",
|
|
27
|
+
"caption",
|
|
28
|
+
"center",
|
|
29
|
+
"col",
|
|
30
|
+
"colgroup",
|
|
31
|
+
"dd",
|
|
32
|
+
"details",
|
|
33
|
+
"dialog",
|
|
34
|
+
"dir",
|
|
35
|
+
"div",
|
|
36
|
+
"dl",
|
|
37
|
+
"dt",
|
|
38
|
+
"fieldset",
|
|
39
|
+
"figcaption",
|
|
40
|
+
"figure",
|
|
41
|
+
"footer",
|
|
42
|
+
"form",
|
|
43
|
+
"frame",
|
|
44
|
+
"frameset",
|
|
45
|
+
"h1",
|
|
46
|
+
"h2",
|
|
47
|
+
"h3",
|
|
48
|
+
"h4",
|
|
49
|
+
"h5",
|
|
50
|
+
"h6",
|
|
51
|
+
"head",
|
|
52
|
+
"header",
|
|
53
|
+
"hr",
|
|
54
|
+
"html",
|
|
55
|
+
"iframe",
|
|
56
|
+
"legend",
|
|
57
|
+
"li",
|
|
58
|
+
"link",
|
|
59
|
+
"main",
|
|
60
|
+
"menu",
|
|
61
|
+
"menuitem",
|
|
62
|
+
"nav",
|
|
63
|
+
"noframes",
|
|
64
|
+
"ol",
|
|
65
|
+
"optgroup",
|
|
66
|
+
"option",
|
|
67
|
+
"p",
|
|
68
|
+
"param",
|
|
69
|
+
"search",
|
|
70
|
+
"section",
|
|
71
|
+
"summary",
|
|
72
|
+
"table",
|
|
73
|
+
"tbody",
|
|
74
|
+
"td",
|
|
75
|
+
"tfoot",
|
|
76
|
+
"th",
|
|
77
|
+
"thead",
|
|
78
|
+
"title",
|
|
79
|
+
"tr",
|
|
80
|
+
"track",
|
|
81
|
+
"ul"
|
|
82
|
+
].join("|")})(?:[ \\t]|/?>|$)`, "i"),
|
|
83
|
+
new RegExp(`^(?:${OPEN_TAG}|${CLOSING_TAG})[ \\t]*$`, "i")
|
|
84
|
+
];
|
|
85
|
+
const HTML_BLOCK_END_PATTERNS = [
|
|
86
|
+
/^(?!)/,
|
|
87
|
+
/<\/(?:pre|script|style|textarea)>/i,
|
|
88
|
+
/-->/,
|
|
89
|
+
/\?>/,
|
|
90
|
+
/>/,
|
|
91
|
+
/\]\]>/
|
|
92
|
+
];
|
|
93
|
+
const HTML_BLOCK_TYPES = [
|
|
94
|
+
1,
|
|
95
|
+
2,
|
|
96
|
+
3,
|
|
97
|
+
4,
|
|
98
|
+
5,
|
|
99
|
+
6,
|
|
100
|
+
7
|
|
101
|
+
];
|
|
102
|
+
const LAST_HTML_BLOCK_TYPE = 7;
|
|
103
|
+
function matchHtmlBlockStart(line, interruptsParagraph) {
|
|
104
|
+
if (!line.startsWith("<")) return;
|
|
105
|
+
for (const type of HTML_BLOCK_TYPES) {
|
|
106
|
+
if (type === LAST_HTML_BLOCK_TYPE && interruptsParagraph) continue;
|
|
107
|
+
if (HTML_BLOCK_START_PATTERNS[type]?.test(line) === true) return type;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function matchesHtmlBlockEnd(line, type) {
|
|
111
|
+
return HTML_BLOCK_END_PATTERNS[type]?.test(line) === true;
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
exports.matchHtmlBlockStart = matchHtmlBlockStart;
|
|
115
|
+
exports.matchHtmlTag = matchHtmlTag;
|
|
116
|
+
exports.matchesHtmlBlockEnd = matchesHtmlBlockEnd;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
//#region src/html/html.ts
|
|
2
|
+
const TAG_NAME = "[A-Za-z][A-Za-z0-9-]*";
|
|
3
|
+
const OPEN_TAG = `<${TAG_NAME}(?:\\s+[a-zA-Z_:][a-zA-Z0-9:._-]*(?:\\s*=\\s*(?:[^"'=<>\`\\x00-\\x20]+|'[^']*'|"[^"]*"))?)*\\s*/?>`;
|
|
4
|
+
const CLOSING_TAG = `</${TAG_NAME}\\s*>`;
|
|
5
|
+
const HTML_TAG_PATTERN = new RegExp(`^(?:${OPEN_TAG}|${CLOSING_TAG}|<!-->|<!--->|<!--[\\s\\S]*?-->|<\\?[\\s\\S]*?\\?>|<![A-Za-z][^>]*>|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>)`);
|
|
6
|
+
function matchHtmlTag(text, start) {
|
|
7
|
+
if (text.charAt(start) !== "<") return;
|
|
8
|
+
const match = HTML_TAG_PATTERN.exec(text.slice(start));
|
|
9
|
+
return match === null ? void 0 : match[0];
|
|
10
|
+
}
|
|
11
|
+
const HTML_BLOCK_START_PATTERNS = [
|
|
12
|
+
/^(?!)/,
|
|
13
|
+
/^<(?:pre|script|style|textarea)(?:[ \t]|>|$)/i,
|
|
14
|
+
/^<!--/,
|
|
15
|
+
/^<\?/,
|
|
16
|
+
/^<![A-Za-z]/,
|
|
17
|
+
/^<!\[CDATA\[/,
|
|
18
|
+
new RegExp(`^</?(?:${[
|
|
19
|
+
"address",
|
|
20
|
+
"article",
|
|
21
|
+
"aside",
|
|
22
|
+
"base",
|
|
23
|
+
"basefont",
|
|
24
|
+
"blockquote",
|
|
25
|
+
"body",
|
|
26
|
+
"caption",
|
|
27
|
+
"center",
|
|
28
|
+
"col",
|
|
29
|
+
"colgroup",
|
|
30
|
+
"dd",
|
|
31
|
+
"details",
|
|
32
|
+
"dialog",
|
|
33
|
+
"dir",
|
|
34
|
+
"div",
|
|
35
|
+
"dl",
|
|
36
|
+
"dt",
|
|
37
|
+
"fieldset",
|
|
38
|
+
"figcaption",
|
|
39
|
+
"figure",
|
|
40
|
+
"footer",
|
|
41
|
+
"form",
|
|
42
|
+
"frame",
|
|
43
|
+
"frameset",
|
|
44
|
+
"h1",
|
|
45
|
+
"h2",
|
|
46
|
+
"h3",
|
|
47
|
+
"h4",
|
|
48
|
+
"h5",
|
|
49
|
+
"h6",
|
|
50
|
+
"head",
|
|
51
|
+
"header",
|
|
52
|
+
"hr",
|
|
53
|
+
"html",
|
|
54
|
+
"iframe",
|
|
55
|
+
"legend",
|
|
56
|
+
"li",
|
|
57
|
+
"link",
|
|
58
|
+
"main",
|
|
59
|
+
"menu",
|
|
60
|
+
"menuitem",
|
|
61
|
+
"nav",
|
|
62
|
+
"noframes",
|
|
63
|
+
"ol",
|
|
64
|
+
"optgroup",
|
|
65
|
+
"option",
|
|
66
|
+
"p",
|
|
67
|
+
"param",
|
|
68
|
+
"search",
|
|
69
|
+
"section",
|
|
70
|
+
"summary",
|
|
71
|
+
"table",
|
|
72
|
+
"tbody",
|
|
73
|
+
"td",
|
|
74
|
+
"tfoot",
|
|
75
|
+
"th",
|
|
76
|
+
"thead",
|
|
77
|
+
"title",
|
|
78
|
+
"tr",
|
|
79
|
+
"track",
|
|
80
|
+
"ul"
|
|
81
|
+
].join("|")})(?:[ \\t]|/?>|$)`, "i"),
|
|
82
|
+
new RegExp(`^(?:${OPEN_TAG}|${CLOSING_TAG})[ \\t]*$`, "i")
|
|
83
|
+
];
|
|
84
|
+
const HTML_BLOCK_END_PATTERNS = [
|
|
85
|
+
/^(?!)/,
|
|
86
|
+
/<\/(?:pre|script|style|textarea)>/i,
|
|
87
|
+
/-->/,
|
|
88
|
+
/\?>/,
|
|
89
|
+
/>/,
|
|
90
|
+
/\]\]>/
|
|
91
|
+
];
|
|
92
|
+
const HTML_BLOCK_TYPES = [
|
|
93
|
+
1,
|
|
94
|
+
2,
|
|
95
|
+
3,
|
|
96
|
+
4,
|
|
97
|
+
5,
|
|
98
|
+
6,
|
|
99
|
+
7
|
|
100
|
+
];
|
|
101
|
+
const LAST_HTML_BLOCK_TYPE = 7;
|
|
102
|
+
function matchHtmlBlockStart(line, interruptsParagraph) {
|
|
103
|
+
if (!line.startsWith("<")) return;
|
|
104
|
+
for (const type of HTML_BLOCK_TYPES) {
|
|
105
|
+
if (type === LAST_HTML_BLOCK_TYPE && interruptsParagraph) continue;
|
|
106
|
+
if (HTML_BLOCK_START_PATTERNS[type]?.test(line) === true) return type;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function matchesHtmlBlockEnd(line, type) {
|
|
110
|
+
return HTML_BLOCK_END_PATTERNS[type]?.test(line) === true;
|
|
111
|
+
}
|
|
112
|
+
//#endregion
|
|
113
|
+
export { matchHtmlBlockStart, matchHtmlTag, matchesHtmlBlockEnd };
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/html/render.ts
|
|
3
|
+
const HREF_SAFE_PUNCTUATION = /* @__PURE__ */ new Set([
|
|
4
|
+
"-",
|
|
5
|
+
"_",
|
|
6
|
+
".",
|
|
7
|
+
"+",
|
|
8
|
+
"!",
|
|
9
|
+
"*",
|
|
10
|
+
"(",
|
|
11
|
+
")",
|
|
12
|
+
",",
|
|
13
|
+
"%",
|
|
14
|
+
"#",
|
|
15
|
+
"@",
|
|
16
|
+
"?",
|
|
17
|
+
"=",
|
|
18
|
+
";",
|
|
19
|
+
":",
|
|
20
|
+
"/",
|
|
21
|
+
"$",
|
|
22
|
+
"~"
|
|
23
|
+
]);
|
|
24
|
+
const ALPHANUMERIC_PATTERN = /^[A-Za-z0-9]$/;
|
|
25
|
+
const HEX_RADIX = 16;
|
|
26
|
+
const PERCENT_ESCAPE_DIGITS = 2;
|
|
27
|
+
const DEFAULT_ORDERED_LIST_START = 1;
|
|
28
|
+
function escapeHtml(text) {
|
|
29
|
+
return text.replace(/[&<>"]/g, (char) => {
|
|
30
|
+
switch (char) {
|
|
31
|
+
case "&": return "&";
|
|
32
|
+
case "<": return "<";
|
|
33
|
+
case ">": return ">";
|
|
34
|
+
default: return """;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function escapeHref(href) {
|
|
39
|
+
const bytes = new TextEncoder().encode(href);
|
|
40
|
+
let result = "";
|
|
41
|
+
for (const byte of bytes) {
|
|
42
|
+
const char = String.fromCharCode(byte);
|
|
43
|
+
if (byte < 128 && (ALPHANUMERIC_PATTERN.test(char) || HREF_SAFE_PUNCTUATION.has(char))) {
|
|
44
|
+
result += char;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (char === "&") {
|
|
48
|
+
result += "&";
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (char === "'") {
|
|
52
|
+
result += "'";
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
result += `%${byte.toString(HEX_RADIX).toUpperCase().padStart(PERCENT_ESCAPE_DIGITS, "0")}`;
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
function renderTitleAttribute(title) {
|
|
60
|
+
return title === void 0 ? "" : ` title="${escapeHtml(title)}"`;
|
|
61
|
+
}
|
|
62
|
+
function renderAlignmentAttribute(alignment) {
|
|
63
|
+
return alignment === void 0 || alignment === "none" ? "" : ` align="${alignment}"`;
|
|
64
|
+
}
|
|
65
|
+
function renderTaskCheckbox(checked) {
|
|
66
|
+
return checked ? "<input checked=\"\" disabled=\"\" type=\"checkbox\"> " : "<input disabled=\"\" type=\"checkbox\"> ";
|
|
67
|
+
}
|
|
68
|
+
function renderInline(node) {
|
|
69
|
+
switch (node.type) {
|
|
70
|
+
case "text": return escapeHtml(node.value);
|
|
71
|
+
case "entity": return escapeHtml(node.value);
|
|
72
|
+
case "codeSpan": return `<code>${escapeHtml(node.literal)}</code>`;
|
|
73
|
+
case "emphasis": return `<em>${renderInlines(node.children)}</em>`;
|
|
74
|
+
case "strong": return `<strong>${renderInlines(node.children)}</strong>`;
|
|
75
|
+
case "strikethrough": return `<del>${renderInlines(node.children)}</del>`;
|
|
76
|
+
case "link": return `<a href="${escapeHref(node.destination)}"${renderTitleAttribute(node.title)}>${renderInlines(node.children)}</a>`;
|
|
77
|
+
case "image": return `<img src="${escapeHref(node.destination)}" alt="${escapeHtml(node.alt)}"${renderTitleAttribute(node.title)} />`;
|
|
78
|
+
case "autolink": return `<a href="${escapeHref(node.email ? `mailto:${node.destination}` : node.destination)}">${escapeHtml(node.destination)}</a>`;
|
|
79
|
+
case "rawHtml": return node.literal;
|
|
80
|
+
case "hardBreak": return "<br />\n";
|
|
81
|
+
case "softBreak": return "\n";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function renderInlines(nodes) {
|
|
85
|
+
return nodes.map(renderInline).join("");
|
|
86
|
+
}
|
|
87
|
+
var HtmlRenderer = class {
|
|
88
|
+
out = "";
|
|
89
|
+
render(blocks, tight) {
|
|
90
|
+
for (const block of blocks) this.renderBlock(block, tight);
|
|
91
|
+
}
|
|
92
|
+
result() {
|
|
93
|
+
return this.out;
|
|
94
|
+
}
|
|
95
|
+
cr() {
|
|
96
|
+
if (this.out.length > 0 && !this.out.endsWith("\n")) this.out += "\n";
|
|
97
|
+
}
|
|
98
|
+
renderBlock(node, tight) {
|
|
99
|
+
switch (node.type) {
|
|
100
|
+
case "paragraph":
|
|
101
|
+
if (tight) {
|
|
102
|
+
this.out += renderInlines(node.children);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
this.cr();
|
|
106
|
+
this.out += `<p>${renderInlines(node.children)}</p>\n`;
|
|
107
|
+
return;
|
|
108
|
+
case "heading":
|
|
109
|
+
this.cr();
|
|
110
|
+
this.out += `<h${String(node.level)}>${renderInlines(node.children)}</h${String(node.level)}>\n`;
|
|
111
|
+
return;
|
|
112
|
+
case "thematicBreak":
|
|
113
|
+
this.cr();
|
|
114
|
+
this.out += "<hr />\n";
|
|
115
|
+
return;
|
|
116
|
+
case "codeBlock":
|
|
117
|
+
this.renderCodeBlock(node.infoString, node.literal);
|
|
118
|
+
return;
|
|
119
|
+
case "htmlBlock":
|
|
120
|
+
this.cr();
|
|
121
|
+
this.out += node.literal;
|
|
122
|
+
this.cr();
|
|
123
|
+
return;
|
|
124
|
+
case "blockquote":
|
|
125
|
+
this.cr();
|
|
126
|
+
this.out += "<blockquote>\n";
|
|
127
|
+
this.render(node.children, false);
|
|
128
|
+
this.cr();
|
|
129
|
+
this.out += "</blockquote>\n";
|
|
130
|
+
return;
|
|
131
|
+
case "list":
|
|
132
|
+
this.renderList(node);
|
|
133
|
+
return;
|
|
134
|
+
case "table":
|
|
135
|
+
this.renderTable(node);
|
|
136
|
+
return;
|
|
137
|
+
case "document":
|
|
138
|
+
case "listItem":
|
|
139
|
+
case "tableRow":
|
|
140
|
+
case "tableCell": return;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
renderCodeBlock(infoString, literal) {
|
|
144
|
+
this.cr();
|
|
145
|
+
const language = infoString === void 0 ? "" : infoString.split(/[ \t]/)[0] ?? "";
|
|
146
|
+
const attribute = language.length === 0 ? "" : ` class="language-${escapeHtml(language)}"`;
|
|
147
|
+
this.out += `<pre><code${attribute}>${escapeHtml(literal)}</code></pre>\n`;
|
|
148
|
+
}
|
|
149
|
+
renderList(node) {
|
|
150
|
+
this.cr();
|
|
151
|
+
const start = node.start ?? DEFAULT_ORDERED_LIST_START;
|
|
152
|
+
const orderedOpenTag = start === DEFAULT_ORDERED_LIST_START ? "<ol>" : `<ol start="${String(start)}">`;
|
|
153
|
+
this.out += `${node.markerType === "bullet" ? "<ul>" : orderedOpenTag}\n`;
|
|
154
|
+
for (const item of node.children) {
|
|
155
|
+
this.cr();
|
|
156
|
+
this.out += "<li>";
|
|
157
|
+
if (item.checked !== void 0) this.out += renderTaskCheckbox(item.checked);
|
|
158
|
+
this.render(item.children, node.tight);
|
|
159
|
+
this.out += "</li>\n";
|
|
160
|
+
}
|
|
161
|
+
this.out += node.markerType === "bullet" ? "</ul>\n" : "</ol>\n";
|
|
162
|
+
}
|
|
163
|
+
renderTable(node) {
|
|
164
|
+
this.cr();
|
|
165
|
+
this.out += "<table>\n";
|
|
166
|
+
const [header, ...body] = node.children;
|
|
167
|
+
if (header !== void 0) {
|
|
168
|
+
this.out += "<thead>\n<tr>\n";
|
|
169
|
+
for (const [index, cell] of header.children.entries()) this.out += `<th${renderAlignmentAttribute(node.alignments[index])}>${renderInlines(cell.children)}</th>\n`;
|
|
170
|
+
this.out += "</tr>\n</thead>\n";
|
|
171
|
+
}
|
|
172
|
+
if (body.length > 0) {
|
|
173
|
+
this.out += "<tbody>\n";
|
|
174
|
+
for (const row of body) {
|
|
175
|
+
this.out += "<tr>\n";
|
|
176
|
+
for (const [index, cell] of row.children.entries()) this.out += `<td${renderAlignmentAttribute(node.alignments[index])}>${renderInlines(cell.children)}</td>\n`;
|
|
177
|
+
this.out += "</tr>\n";
|
|
178
|
+
}
|
|
179
|
+
this.out += "</tbody>\n";
|
|
180
|
+
}
|
|
181
|
+
this.out += "</table>\n";
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
function renderDocumentToHtml(document) {
|
|
185
|
+
const renderer = new HtmlRenderer();
|
|
186
|
+
renderer.render(document.children, false);
|
|
187
|
+
return renderer.result();
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
exports.escapeHref = escapeHref;
|
|
191
|
+
exports.escapeHtml = escapeHtml;
|
|
192
|
+
exports.renderDocumentToHtml = renderDocumentToHtml;
|
|
193
|
+
exports.renderInlines = renderInlines;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { g as MarkdownInlineNode, s as MarkdownDocumentNode } from "../ast-BXYwy08e.cjs";
|
|
2
|
+
//#region src/html/render.d.ts
|
|
3
|
+
declare function escapeHtml(text: string): string;
|
|
4
|
+
declare function escapeHref(href: string): string;
|
|
5
|
+
declare function renderInlines(nodes: readonly MarkdownInlineNode[]): string;
|
|
6
|
+
declare function renderDocumentToHtml(document: MarkdownDocumentNode): string;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { escapeHref, escapeHtml, renderDocumentToHtml, renderInlines };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { g as MarkdownInlineNode, s as MarkdownDocumentNode } from "../ast-BXYwy08e.js";
|
|
2
|
+
//#region src/html/render.d.ts
|
|
3
|
+
declare function escapeHtml(text: string): string;
|
|
4
|
+
declare function escapeHref(href: string): string;
|
|
5
|
+
declare function renderInlines(nodes: readonly MarkdownInlineNode[]): string;
|
|
6
|
+
declare function renderDocumentToHtml(document: MarkdownDocumentNode): string;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { escapeHref, escapeHtml, renderDocumentToHtml, renderInlines };
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
//#region src/html/render.ts
|
|
2
|
+
const HREF_SAFE_PUNCTUATION = /* @__PURE__ */ new Set([
|
|
3
|
+
"-",
|
|
4
|
+
"_",
|
|
5
|
+
".",
|
|
6
|
+
"+",
|
|
7
|
+
"!",
|
|
8
|
+
"*",
|
|
9
|
+
"(",
|
|
10
|
+
")",
|
|
11
|
+
",",
|
|
12
|
+
"%",
|
|
13
|
+
"#",
|
|
14
|
+
"@",
|
|
15
|
+
"?",
|
|
16
|
+
"=",
|
|
17
|
+
";",
|
|
18
|
+
":",
|
|
19
|
+
"/",
|
|
20
|
+
"$",
|
|
21
|
+
"~"
|
|
22
|
+
]);
|
|
23
|
+
const ALPHANUMERIC_PATTERN = /^[A-Za-z0-9]$/;
|
|
24
|
+
const HEX_RADIX = 16;
|
|
25
|
+
const PERCENT_ESCAPE_DIGITS = 2;
|
|
26
|
+
const DEFAULT_ORDERED_LIST_START = 1;
|
|
27
|
+
function escapeHtml(text) {
|
|
28
|
+
return text.replace(/[&<>"]/g, (char) => {
|
|
29
|
+
switch (char) {
|
|
30
|
+
case "&": return "&";
|
|
31
|
+
case "<": return "<";
|
|
32
|
+
case ">": return ">";
|
|
33
|
+
default: return """;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function escapeHref(href) {
|
|
38
|
+
const bytes = new TextEncoder().encode(href);
|
|
39
|
+
let result = "";
|
|
40
|
+
for (const byte of bytes) {
|
|
41
|
+
const char = String.fromCharCode(byte);
|
|
42
|
+
if (byte < 128 && (ALPHANUMERIC_PATTERN.test(char) || HREF_SAFE_PUNCTUATION.has(char))) {
|
|
43
|
+
result += char;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (char === "&") {
|
|
47
|
+
result += "&";
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (char === "'") {
|
|
51
|
+
result += "'";
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
result += `%${byte.toString(HEX_RADIX).toUpperCase().padStart(PERCENT_ESCAPE_DIGITS, "0")}`;
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
function renderTitleAttribute(title) {
|
|
59
|
+
return title === void 0 ? "" : ` title="${escapeHtml(title)}"`;
|
|
60
|
+
}
|
|
61
|
+
function renderAlignmentAttribute(alignment) {
|
|
62
|
+
return alignment === void 0 || alignment === "none" ? "" : ` align="${alignment}"`;
|
|
63
|
+
}
|
|
64
|
+
function renderTaskCheckbox(checked) {
|
|
65
|
+
return checked ? "<input checked=\"\" disabled=\"\" type=\"checkbox\"> " : "<input disabled=\"\" type=\"checkbox\"> ";
|
|
66
|
+
}
|
|
67
|
+
function renderInline(node) {
|
|
68
|
+
switch (node.type) {
|
|
69
|
+
case "text": return escapeHtml(node.value);
|
|
70
|
+
case "entity": return escapeHtml(node.value);
|
|
71
|
+
case "codeSpan": return `<code>${escapeHtml(node.literal)}</code>`;
|
|
72
|
+
case "emphasis": return `<em>${renderInlines(node.children)}</em>`;
|
|
73
|
+
case "strong": return `<strong>${renderInlines(node.children)}</strong>`;
|
|
74
|
+
case "strikethrough": return `<del>${renderInlines(node.children)}</del>`;
|
|
75
|
+
case "link": return `<a href="${escapeHref(node.destination)}"${renderTitleAttribute(node.title)}>${renderInlines(node.children)}</a>`;
|
|
76
|
+
case "image": return `<img src="${escapeHref(node.destination)}" alt="${escapeHtml(node.alt)}"${renderTitleAttribute(node.title)} />`;
|
|
77
|
+
case "autolink": return `<a href="${escapeHref(node.email ? `mailto:${node.destination}` : node.destination)}">${escapeHtml(node.destination)}</a>`;
|
|
78
|
+
case "rawHtml": return node.literal;
|
|
79
|
+
case "hardBreak": return "<br />\n";
|
|
80
|
+
case "softBreak": return "\n";
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function renderInlines(nodes) {
|
|
84
|
+
return nodes.map(renderInline).join("");
|
|
85
|
+
}
|
|
86
|
+
var HtmlRenderer = class {
|
|
87
|
+
out = "";
|
|
88
|
+
render(blocks, tight) {
|
|
89
|
+
for (const block of blocks) this.renderBlock(block, tight);
|
|
90
|
+
}
|
|
91
|
+
result() {
|
|
92
|
+
return this.out;
|
|
93
|
+
}
|
|
94
|
+
cr() {
|
|
95
|
+
if (this.out.length > 0 && !this.out.endsWith("\n")) this.out += "\n";
|
|
96
|
+
}
|
|
97
|
+
renderBlock(node, tight) {
|
|
98
|
+
switch (node.type) {
|
|
99
|
+
case "paragraph":
|
|
100
|
+
if (tight) {
|
|
101
|
+
this.out += renderInlines(node.children);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
this.cr();
|
|
105
|
+
this.out += `<p>${renderInlines(node.children)}</p>\n`;
|
|
106
|
+
return;
|
|
107
|
+
case "heading":
|
|
108
|
+
this.cr();
|
|
109
|
+
this.out += `<h${String(node.level)}>${renderInlines(node.children)}</h${String(node.level)}>\n`;
|
|
110
|
+
return;
|
|
111
|
+
case "thematicBreak":
|
|
112
|
+
this.cr();
|
|
113
|
+
this.out += "<hr />\n";
|
|
114
|
+
return;
|
|
115
|
+
case "codeBlock":
|
|
116
|
+
this.renderCodeBlock(node.infoString, node.literal);
|
|
117
|
+
return;
|
|
118
|
+
case "htmlBlock":
|
|
119
|
+
this.cr();
|
|
120
|
+
this.out += node.literal;
|
|
121
|
+
this.cr();
|
|
122
|
+
return;
|
|
123
|
+
case "blockquote":
|
|
124
|
+
this.cr();
|
|
125
|
+
this.out += "<blockquote>\n";
|
|
126
|
+
this.render(node.children, false);
|
|
127
|
+
this.cr();
|
|
128
|
+
this.out += "</blockquote>\n";
|
|
129
|
+
return;
|
|
130
|
+
case "list":
|
|
131
|
+
this.renderList(node);
|
|
132
|
+
return;
|
|
133
|
+
case "table":
|
|
134
|
+
this.renderTable(node);
|
|
135
|
+
return;
|
|
136
|
+
case "document":
|
|
137
|
+
case "listItem":
|
|
138
|
+
case "tableRow":
|
|
139
|
+
case "tableCell": return;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
renderCodeBlock(infoString, literal) {
|
|
143
|
+
this.cr();
|
|
144
|
+
const language = infoString === void 0 ? "" : infoString.split(/[ \t]/)[0] ?? "";
|
|
145
|
+
const attribute = language.length === 0 ? "" : ` class="language-${escapeHtml(language)}"`;
|
|
146
|
+
this.out += `<pre><code${attribute}>${escapeHtml(literal)}</code></pre>\n`;
|
|
147
|
+
}
|
|
148
|
+
renderList(node) {
|
|
149
|
+
this.cr();
|
|
150
|
+
const start = node.start ?? DEFAULT_ORDERED_LIST_START;
|
|
151
|
+
const orderedOpenTag = start === DEFAULT_ORDERED_LIST_START ? "<ol>" : `<ol start="${String(start)}">`;
|
|
152
|
+
this.out += `${node.markerType === "bullet" ? "<ul>" : orderedOpenTag}\n`;
|
|
153
|
+
for (const item of node.children) {
|
|
154
|
+
this.cr();
|
|
155
|
+
this.out += "<li>";
|
|
156
|
+
if (item.checked !== void 0) this.out += renderTaskCheckbox(item.checked);
|
|
157
|
+
this.render(item.children, node.tight);
|
|
158
|
+
this.out += "</li>\n";
|
|
159
|
+
}
|
|
160
|
+
this.out += node.markerType === "bullet" ? "</ul>\n" : "</ol>\n";
|
|
161
|
+
}
|
|
162
|
+
renderTable(node) {
|
|
163
|
+
this.cr();
|
|
164
|
+
this.out += "<table>\n";
|
|
165
|
+
const [header, ...body] = node.children;
|
|
166
|
+
if (header !== void 0) {
|
|
167
|
+
this.out += "<thead>\n<tr>\n";
|
|
168
|
+
for (const [index, cell] of header.children.entries()) this.out += `<th${renderAlignmentAttribute(node.alignments[index])}>${renderInlines(cell.children)}</th>\n`;
|
|
169
|
+
this.out += "</tr>\n</thead>\n";
|
|
170
|
+
}
|
|
171
|
+
if (body.length > 0) {
|
|
172
|
+
this.out += "<tbody>\n";
|
|
173
|
+
for (const row of body) {
|
|
174
|
+
this.out += "<tr>\n";
|
|
175
|
+
for (const [index, cell] of row.children.entries()) this.out += `<td${renderAlignmentAttribute(node.alignments[index])}>${renderInlines(cell.children)}</td>\n`;
|
|
176
|
+
this.out += "</tr>\n";
|
|
177
|
+
}
|
|
178
|
+
this.out += "</tbody>\n";
|
|
179
|
+
}
|
|
180
|
+
this.out += "</table>\n";
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
function renderDocumentToHtml(document) {
|
|
184
|
+
const renderer = new HtmlRenderer();
|
|
185
|
+
renderer.render(document.children, false);
|
|
186
|
+
return renderer.result();
|
|
187
|
+
}
|
|
188
|
+
//#endregion
|
|
189
|
+
export { escapeHref, escapeHtml, renderDocumentToHtml, renderInlines };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/html/html.d.ts
|
|
2
|
+
declare function matchHtmlTag(text: string, start: number): string | undefined;
|
|
3
|
+
type HtmlBlockType = 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
|
4
|
+
declare function matchHtmlBlockStart(line: string, interruptsParagraph: boolean): HtmlBlockType | undefined;
|
|
5
|
+
declare function matchesHtmlBlockEnd(line: string, type: HtmlBlockType): boolean;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { matchesHtmlBlockEnd as i, matchHtmlBlockStart as n, matchHtmlTag as r, HtmlBlockType as t };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/html/html.d.ts
|
|
2
|
+
declare function matchHtmlTag(text: string, start: number): string | undefined;
|
|
3
|
+
type HtmlBlockType = 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
|
4
|
+
declare function matchHtmlBlockStart(line: string, interruptsParagraph: boolean): HtmlBlockType | undefined;
|
|
5
|
+
declare function matchesHtmlBlockEnd(line: string, type: HtmlBlockType): boolean;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { matchesHtmlBlockEnd as i, matchHtmlBlockStart as n, matchHtmlTag as r, HtmlBlockType as t };
|