emdp 1.0.0
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 +124 -0
- package/dist/cjs/cli.js +36 -0
- package/dist/cjs/gfm.js +26 -0
- package/dist/cjs/index.js +26 -0
- package/dist/cjs/parser/block-parser.js +644 -0
- package/dist/cjs/parser/blocks/blockquote.js +28 -0
- package/dist/cjs/parser/blocks/code-block-fenced.js +58 -0
- package/dist/cjs/parser/blocks/code-block-indented.js +47 -0
- package/dist/cjs/parser/blocks/heading-atx.js +29 -0
- package/dist/cjs/parser/blocks/heading-setext.js +24 -0
- package/dist/cjs/parser/blocks/html-block.js +83 -0
- package/dist/cjs/parser/blocks/link-reference.js +109 -0
- package/dist/cjs/parser/blocks/list.js +155 -0
- package/dist/cjs/parser/blocks/paragraph.js +20 -0
- package/dist/cjs/parser/blocks/table.js +163 -0
- package/dist/cjs/parser/blocks/task-list.js +66 -0
- package/dist/cjs/parser/blocks/thematic-break.js +17 -0
- package/dist/cjs/parser/entities.js +2133 -0
- package/dist/cjs/parser/gfm/block-parser.js +773 -0
- package/dist/cjs/parser/gfm/index.js +125 -0
- package/dist/cjs/parser/gfm/inline-parser.js +813 -0
- package/dist/cjs/parser/gfm/renderer.js +513 -0
- package/dist/cjs/parser/index.js +104 -0
- package/dist/cjs/parser/inline-parser.js +564 -0
- package/dist/cjs/parser/inlines/autolink-extended.js +364 -0
- package/dist/cjs/parser/inlines/autolink.js +44 -0
- package/dist/cjs/parser/inlines/code-span.js +48 -0
- package/dist/cjs/parser/inlines/emphasis.js +64 -0
- package/dist/cjs/parser/inlines/entity.js +25 -0
- package/dist/cjs/parser/inlines/escape.js +25 -0
- package/dist/cjs/parser/inlines/footnote.js +41 -0
- package/dist/cjs/parser/inlines/hard-break.js +45 -0
- package/dist/cjs/parser/inlines/image.js +9 -0
- package/dist/cjs/parser/inlines/link.js +166 -0
- package/dist/cjs/parser/inlines/soft-break.js +18 -0
- package/dist/cjs/parser/inlines/strikethrough.js +48 -0
- package/dist/cjs/parser/inlines/text.js +20 -0
- package/dist/cjs/parser/renderer.js +345 -0
- package/dist/cjs/parser/types.js +5 -0
- package/dist/cjs/parser/utils.js +277 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +36 -0
- package/dist/esm/cli.js +34 -0
- package/dist/esm/gfm.js +5 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/parser/block-parser.js +640 -0
- package/dist/esm/parser/blocks/blockquote.js +22 -0
- package/dist/esm/parser/blocks/code-block-fenced.js +52 -0
- package/dist/esm/parser/blocks/code-block-indented.js +42 -0
- package/dist/esm/parser/blocks/heading-atx.js +24 -0
- package/dist/esm/parser/blocks/heading-setext.js +19 -0
- package/dist/esm/parser/blocks/html-block.js +77 -0
- package/dist/esm/parser/blocks/link-reference.js +105 -0
- package/dist/esm/parser/blocks/list.js +145 -0
- package/dist/esm/parser/blocks/paragraph.js +15 -0
- package/dist/esm/parser/blocks/table.js +152 -0
- package/dist/esm/parser/blocks/task-list.js +61 -0
- package/dist/esm/parser/blocks/thematic-break.js +13 -0
- package/dist/esm/parser/entities.js +2130 -0
- package/dist/esm/parser/gfm/block-parser.js +769 -0
- package/dist/esm/parser/gfm/index.js +115 -0
- package/dist/esm/parser/gfm/inline-parser.js +809 -0
- package/dist/esm/parser/gfm/renderer.js +509 -0
- package/dist/esm/parser/index.js +80 -0
- package/dist/esm/parser/inline-parser.js +560 -0
- package/dist/esm/parser/inlines/autolink-extended.js +357 -0
- package/dist/esm/parser/inlines/autolink.js +40 -0
- package/dist/esm/parser/inlines/code-span.js +44 -0
- package/dist/esm/parser/inlines/emphasis.js +59 -0
- package/dist/esm/parser/inlines/entity.js +21 -0
- package/dist/esm/parser/inlines/escape.js +21 -0
- package/dist/esm/parser/inlines/footnote.js +38 -0
- package/dist/esm/parser/inlines/hard-break.js +41 -0
- package/dist/esm/parser/inlines/image.js +4 -0
- package/dist/esm/parser/inlines/link.js +156 -0
- package/dist/esm/parser/inlines/soft-break.js +14 -0
- package/dist/esm/parser/inlines/strikethrough.js +42 -0
- package/dist/esm/parser/inlines/text.js +16 -0
- package/dist/esm/parser/renderer.js +341 -0
- package/dist/esm/parser/types.js +4 -0
- package/dist/esm/parser/utils.js +254 -0
- package/dist/gfm.d.ts +6 -0
- package/dist/gfm.js +26 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +26 -0
- package/dist/parser/block-parser.d.ts +25 -0
- package/dist/parser/block-parser.js +644 -0
- package/dist/parser/blocks/blockquote.d.ts +8 -0
- package/dist/parser/blocks/blockquote.js +28 -0
- package/dist/parser/blocks/code-block-fenced.d.ts +14 -0
- package/dist/parser/blocks/code-block-fenced.js +58 -0
- package/dist/parser/blocks/code-block-indented.d.ts +7 -0
- package/dist/parser/blocks/code-block-indented.js +47 -0
- package/dist/parser/blocks/heading-atx.d.ts +10 -0
- package/dist/parser/blocks/heading-atx.js +29 -0
- package/dist/parser/blocks/heading-setext.d.ts +8 -0
- package/dist/parser/blocks/heading-setext.js +24 -0
- package/dist/parser/blocks/html-block.d.ts +9 -0
- package/dist/parser/blocks/html-block.js +83 -0
- package/dist/parser/blocks/link-reference.d.ts +11 -0
- package/dist/parser/blocks/link-reference.js +109 -0
- package/dist/parser/blocks/list.d.ts +25 -0
- package/dist/parser/blocks/list.js +155 -0
- package/dist/parser/blocks/paragraph.d.ts +7 -0
- package/dist/parser/blocks/paragraph.js +20 -0
- package/dist/parser/blocks/table.d.ts +13 -0
- package/dist/parser/blocks/table.js +163 -0
- package/dist/parser/blocks/task-list.d.ts +10 -0
- package/dist/parser/blocks/task-list.js +66 -0
- package/dist/parser/blocks/thematic-break.d.ts +6 -0
- package/dist/parser/blocks/thematic-break.js +17 -0
- package/dist/parser/entities.d.ts +4 -0
- package/dist/parser/entities.js +2133 -0
- package/dist/parser/gfm/block-parser.d.ts +32 -0
- package/dist/parser/gfm/block-parser.js +773 -0
- package/dist/parser/gfm/index.d.ts +31 -0
- package/dist/parser/gfm/index.js +125 -0
- package/dist/parser/gfm/inline-parser.d.ts +25 -0
- package/dist/parser/gfm/inline-parser.js +813 -0
- package/dist/parser/gfm/renderer.d.ts +43 -0
- package/dist/parser/gfm/renderer.js +513 -0
- package/dist/parser/index.d.ts +33 -0
- package/dist/parser/index.js +104 -0
- package/dist/parser/inline-parser.d.ts +16 -0
- package/dist/parser/inline-parser.js +564 -0
- package/dist/parser/inlines/autolink-extended.d.ts +24 -0
- package/dist/parser/inlines/autolink-extended.js +364 -0
- package/dist/parser/inlines/autolink.d.ts +9 -0
- package/dist/parser/inlines/autolink.js +44 -0
- package/dist/parser/inlines/code-span.d.ts +9 -0
- package/dist/parser/inlines/code-span.js +48 -0
- package/dist/parser/inlines/emphasis.d.ts +14 -0
- package/dist/parser/inlines/emphasis.js +64 -0
- package/dist/parser/inlines/entity.d.ts +8 -0
- package/dist/parser/inlines/entity.js +25 -0
- package/dist/parser/inlines/escape.d.ts +8 -0
- package/dist/parser/inlines/escape.js +25 -0
- package/dist/parser/inlines/footnote.d.ts +9 -0
- package/dist/parser/inlines/footnote.js +41 -0
- package/dist/parser/inlines/hard-break.d.ts +9 -0
- package/dist/parser/inlines/hard-break.js +45 -0
- package/dist/parser/inlines/image.d.ts +4 -0
- package/dist/parser/inlines/image.js +9 -0
- package/dist/parser/inlines/link.d.ts +33 -0
- package/dist/parser/inlines/link.js +166 -0
- package/dist/parser/inlines/soft-break.d.ts +9 -0
- package/dist/parser/inlines/soft-break.js +18 -0
- package/dist/parser/inlines/strikethrough.d.ts +16 -0
- package/dist/parser/inlines/strikethrough.js +48 -0
- package/dist/parser/inlines/text.d.ts +6 -0
- package/dist/parser/inlines/text.js +20 -0
- package/dist/parser/renderer.d.ts +33 -0
- package/dist/parser/renderer.js +345 -0
- package/dist/parser/types.d.ts +152 -0
- package/dist/parser/types.js +5 -0
- package/dist/parser/utils.d.ts +32 -0
- package/dist/parser/utils.js +277 -0
- package/dist/types/cli.d.ts +6 -0
- package/dist/types/gfm.d.ts +6 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/parser/block-parser.d.ts +25 -0
- package/dist/types/parser/blocks/blockquote.d.ts +8 -0
- package/dist/types/parser/blocks/code-block-fenced.d.ts +14 -0
- package/dist/types/parser/blocks/code-block-indented.d.ts +7 -0
- package/dist/types/parser/blocks/heading-atx.d.ts +10 -0
- package/dist/types/parser/blocks/heading-setext.d.ts +8 -0
- package/dist/types/parser/blocks/html-block.d.ts +9 -0
- package/dist/types/parser/blocks/link-reference.d.ts +11 -0
- package/dist/types/parser/blocks/list.d.ts +25 -0
- package/dist/types/parser/blocks/paragraph.d.ts +7 -0
- package/dist/types/parser/blocks/table.d.ts +13 -0
- package/dist/types/parser/blocks/task-list.d.ts +10 -0
- package/dist/types/parser/blocks/thematic-break.d.ts +6 -0
- package/dist/types/parser/entities.d.ts +4 -0
- package/dist/types/parser/gfm/block-parser.d.ts +32 -0
- package/dist/types/parser/gfm/index.d.ts +31 -0
- package/dist/types/parser/gfm/inline-parser.d.ts +25 -0
- package/dist/types/parser/gfm/renderer.d.ts +43 -0
- package/dist/types/parser/index.d.ts +33 -0
- package/dist/types/parser/inline-parser.d.ts +16 -0
- package/dist/types/parser/inlines/autolink-extended.d.ts +24 -0
- package/dist/types/parser/inlines/autolink.d.ts +9 -0
- package/dist/types/parser/inlines/code-span.d.ts +9 -0
- package/dist/types/parser/inlines/emphasis.d.ts +14 -0
- package/dist/types/parser/inlines/entity.d.ts +8 -0
- package/dist/types/parser/inlines/escape.d.ts +8 -0
- package/dist/types/parser/inlines/footnote.d.ts +9 -0
- package/dist/types/parser/inlines/hard-break.d.ts +9 -0
- package/dist/types/parser/inlines/image.d.ts +4 -0
- package/dist/types/parser/inlines/link.d.ts +33 -0
- package/dist/types/parser/inlines/soft-break.d.ts +9 -0
- package/dist/types/parser/inlines/strikethrough.d.ts +16 -0
- package/dist/types/parser/inlines/text.d.ts +6 -0
- package/dist/types/parser/renderer.d.ts +33 -0
- package/dist/types/parser/types.d.ts +152 -0
- package/dist/types/parser/utils.d.ts +32 -0
- package/package.json +54 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shared text-processing utilities for the parser, including entity decoding, escaping,
|
|
4
|
+
* whitespace handling, and URI normalization.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.ASCII_PUNCTUATION_CHARS = exports.ASCII_PUNCTUATION_REGEX = void 0;
|
|
8
|
+
exports.decodeHtmlEntities = decodeHtmlEntities;
|
|
9
|
+
exports.escapeXml = escapeXml;
|
|
10
|
+
exports.escapeHtml = escapeHtml;
|
|
11
|
+
exports.isAsciiPunctuation = isAsciiPunctuation;
|
|
12
|
+
exports.isWhitespace = isWhitespace;
|
|
13
|
+
exports.isUnicodeWhitespace = isUnicodeWhitespace;
|
|
14
|
+
exports.isUnicodePunctuation = isUnicodePunctuation;
|
|
15
|
+
exports.normalizeLineEndings = normalizeLineEndings;
|
|
16
|
+
exports.expandTabs = expandTabs;
|
|
17
|
+
exports.expandTabsPartial = expandTabsPartial;
|
|
18
|
+
exports.trimLeadingSpaces = trimLeadingSpaces;
|
|
19
|
+
exports.countLeadingSpaces = countLeadingSpaces;
|
|
20
|
+
exports.countLeadingChars = countLeadingChars;
|
|
21
|
+
exports.removeIndent = removeIndent;
|
|
22
|
+
exports.extractContentAfterMarker = extractContentAfterMarker;
|
|
23
|
+
exports.normalizeUri = normalizeUri;
|
|
24
|
+
exports.unescapeString = unescapeString;
|
|
25
|
+
exports.normalizeLabel = normalizeLabel;
|
|
26
|
+
exports.isTagFilterTag = isTagFilterTag;
|
|
27
|
+
exports.applyTagFilter = applyTagFilter;
|
|
28
|
+
const entities_js_1 = require("./entities.js");
|
|
29
|
+
function decodeHtmlEntities(str) {
|
|
30
|
+
return str.replace(/&(#[xX]?[0-9a-fA-F]+|[a-zA-Z][a-zA-Z0-9]*);/g, (match, capture) => {
|
|
31
|
+
if (capture.startsWith('#x') || capture.startsWith('#X')) {
|
|
32
|
+
const code = parseInt(capture.slice(2), 16);
|
|
33
|
+
if (!isNaN(code) && code >= 0 && code <= 0x10ffff) {
|
|
34
|
+
if (code === 0)
|
|
35
|
+
return '\uFFFD';
|
|
36
|
+
return String.fromCodePoint(code);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else if (capture.startsWith('#')) {
|
|
40
|
+
const code = parseInt(capture.slice(1), 10);
|
|
41
|
+
if (!isNaN(code) && code >= 0 && code <= 0x10ffff) {
|
|
42
|
+
if (code === 0)
|
|
43
|
+
return '\uFFFD';
|
|
44
|
+
return String.fromCodePoint(code);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else if (entities_js_1.HTML_ENTITIES[capture]) {
|
|
48
|
+
return entities_js_1.HTML_ENTITIES[capture];
|
|
49
|
+
}
|
|
50
|
+
return match;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function escapeXml(str) {
|
|
54
|
+
return str
|
|
55
|
+
.replace(/&/g, '&')
|
|
56
|
+
.replace(/</g, '<')
|
|
57
|
+
.replace(/>/g, '>')
|
|
58
|
+
.replace(/"/g, '"');
|
|
59
|
+
}
|
|
60
|
+
function escapeHtml(str, preserveEntities = false) {
|
|
61
|
+
if (preserveEntities) {
|
|
62
|
+
return str
|
|
63
|
+
.replace(/&(?![#a-zA-Z0-9]+;)/g, '&')
|
|
64
|
+
.replace(/</g, '<')
|
|
65
|
+
.replace(/>/g, '>')
|
|
66
|
+
.replace(/"/g, '"');
|
|
67
|
+
}
|
|
68
|
+
return escapeXml(str);
|
|
69
|
+
}
|
|
70
|
+
exports.ASCII_PUNCTUATION_REGEX = /[!"#$%&'()*+,\-./:;<=>?@\[\\\]^_`{|}~]/;
|
|
71
|
+
exports.ASCII_PUNCTUATION_CHARS = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~';
|
|
72
|
+
function isAsciiPunctuation(char) {
|
|
73
|
+
return exports.ASCII_PUNCTUATION_REGEX.test(char);
|
|
74
|
+
}
|
|
75
|
+
function isWhitespace(char) {
|
|
76
|
+
return char === ' ' || char === '\t' || char === '\n' || char === '\r' || char === '\f';
|
|
77
|
+
}
|
|
78
|
+
function isUnicodeWhitespace(char) {
|
|
79
|
+
return /\s/.test(char);
|
|
80
|
+
}
|
|
81
|
+
function isUnicodePunctuation(char) {
|
|
82
|
+
return /[\p{P}\p{S}]/u.test(char);
|
|
83
|
+
}
|
|
84
|
+
function normalizeLineEndings(str) {
|
|
85
|
+
return str.replace(/\r\n?/g, '\n');
|
|
86
|
+
}
|
|
87
|
+
function expandTabs(line, tabStop = 4) {
|
|
88
|
+
let result = '';
|
|
89
|
+
let column = 0;
|
|
90
|
+
for (const char of line) {
|
|
91
|
+
if (char === '\t') {
|
|
92
|
+
const spaces = tabStop - (column % tabStop);
|
|
93
|
+
result += ' '.repeat(spaces);
|
|
94
|
+
column += spaces;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
result += char;
|
|
98
|
+
column++;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
function expandTabsPartial(line, startColumn, tabStop = 4) {
|
|
104
|
+
let result = '';
|
|
105
|
+
let column = startColumn;
|
|
106
|
+
for (const char of line) {
|
|
107
|
+
if (char === '\t') {
|
|
108
|
+
const spaces = tabStop - (column % tabStop);
|
|
109
|
+
result += ' '.repeat(spaces);
|
|
110
|
+
column += spaces;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
result += char;
|
|
114
|
+
column++;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
function trimLeadingSpaces(line, max = 3) {
|
|
120
|
+
let count = 0;
|
|
121
|
+
let i = 0;
|
|
122
|
+
while (i < line.length && line[i] === ' ' && count < max) {
|
|
123
|
+
count++;
|
|
124
|
+
i++;
|
|
125
|
+
}
|
|
126
|
+
return { trimmed: line.slice(i), count };
|
|
127
|
+
}
|
|
128
|
+
function countLeadingSpaces(line) {
|
|
129
|
+
let count = 0;
|
|
130
|
+
for (const char of line) {
|
|
131
|
+
if (char === ' ')
|
|
132
|
+
count++;
|
|
133
|
+
else if (char === '\t')
|
|
134
|
+
count += 4 - (count % 4);
|
|
135
|
+
else
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
return count;
|
|
139
|
+
}
|
|
140
|
+
function countLeadingChars(line) {
|
|
141
|
+
let spaces = 0;
|
|
142
|
+
let chars = 0;
|
|
143
|
+
for (const char of line) {
|
|
144
|
+
if (char === ' ') {
|
|
145
|
+
spaces++;
|
|
146
|
+
chars++;
|
|
147
|
+
}
|
|
148
|
+
else if (char === '\t') {
|
|
149
|
+
const tabWidth = 4 - (spaces % 4);
|
|
150
|
+
spaces += tabWidth;
|
|
151
|
+
chars++;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return { spaces, chars };
|
|
158
|
+
}
|
|
159
|
+
function removeIndent(line, indent) {
|
|
160
|
+
let removed = 0;
|
|
161
|
+
let i = 0;
|
|
162
|
+
while (i < line.length && removed < indent) {
|
|
163
|
+
if (line[i] === ' ') {
|
|
164
|
+
removed++;
|
|
165
|
+
i++;
|
|
166
|
+
}
|
|
167
|
+
else if (line[i] === '\t') {
|
|
168
|
+
const tabWidth = 4 - (removed % 4);
|
|
169
|
+
if (removed + tabWidth <= indent) {
|
|
170
|
+
removed += tabWidth;
|
|
171
|
+
i++;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
const remaining = indent - removed;
|
|
175
|
+
const spacesFromTab = tabWidth - remaining;
|
|
176
|
+
const originalColumn = removed + tabWidth;
|
|
177
|
+
return ' '.repeat(spacesFromTab) + expandRestOfLine(line, i + 1, originalColumn);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return line.slice(i);
|
|
185
|
+
}
|
|
186
|
+
function expandRestOfLine(line, startIdx, startColumn) {
|
|
187
|
+
let result = '';
|
|
188
|
+
let column = startColumn;
|
|
189
|
+
for (let i = startIdx; i < line.length; i++) {
|
|
190
|
+
const char = line[i];
|
|
191
|
+
if (char === '\t') {
|
|
192
|
+
const tabWidth = 4 - (column % 4);
|
|
193
|
+
result += ' '.repeat(tabWidth);
|
|
194
|
+
column += tabWidth;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
result += char;
|
|
198
|
+
column++;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return result;
|
|
202
|
+
}
|
|
203
|
+
function extractContentAfterMarker(line, startColumn, charIndex) {
|
|
204
|
+
if (charIndex > 0 && line[charIndex - 1] === '\t') {
|
|
205
|
+
let col = 0;
|
|
206
|
+
let idx = 0;
|
|
207
|
+
while (idx < charIndex - 1) {
|
|
208
|
+
if (line[idx] === '\t') {
|
|
209
|
+
col = col + (4 - (col % 4));
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
col++;
|
|
213
|
+
}
|
|
214
|
+
idx++;
|
|
215
|
+
}
|
|
216
|
+
const tabEndColumn = col + (4 - (col % 4));
|
|
217
|
+
if (startColumn > col && startColumn < tabEndColumn) {
|
|
218
|
+
const remainingSpaces = tabEndColumn - startColumn;
|
|
219
|
+
return ' '.repeat(remainingSpaces) + line.slice(charIndex);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return line.slice(charIndex);
|
|
223
|
+
}
|
|
224
|
+
function normalizeUri(uri) {
|
|
225
|
+
try {
|
|
226
|
+
let result = '';
|
|
227
|
+
let i = 0;
|
|
228
|
+
while (i < uri.length) {
|
|
229
|
+
const char = uri[i];
|
|
230
|
+
if (char === '%' && i + 2 < uri.length && /^[0-9a-fA-F]{2}$/.test(uri.slice(i + 1, i + 3))) {
|
|
231
|
+
result += uri.slice(i, i + 3).toUpperCase();
|
|
232
|
+
i += 3;
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
const code = char.charCodeAt(0);
|
|
236
|
+
if (code > 0x7f || char === ' ') {
|
|
237
|
+
result += encodeURIComponent(char);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
result += char;
|
|
241
|
+
}
|
|
242
|
+
i++;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return result;
|
|
246
|
+
}
|
|
247
|
+
catch {
|
|
248
|
+
return uri;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
function unescapeString(str) {
|
|
252
|
+
return str.replace(/\\([!"#$%&'()*+,\-./:;<=>?@\[\\\]^_`{|}~])/g, '$1');
|
|
253
|
+
}
|
|
254
|
+
function normalizeLabel(label) {
|
|
255
|
+
return label
|
|
256
|
+
.trim()
|
|
257
|
+
.replace(/[ \t\r\n]+/g, ' ')
|
|
258
|
+
.replace(/\u1e9e/g, 'ss')
|
|
259
|
+
.toLowerCase();
|
|
260
|
+
}
|
|
261
|
+
const TAG_FILTER = new Set([
|
|
262
|
+
'title',
|
|
263
|
+
'textarea',
|
|
264
|
+
'style',
|
|
265
|
+
'xmp',
|
|
266
|
+
'iframe',
|
|
267
|
+
'noembed',
|
|
268
|
+
'noframes',
|
|
269
|
+
'script',
|
|
270
|
+
'plaintext',
|
|
271
|
+
]);
|
|
272
|
+
function isTagFilterTag(tagName) {
|
|
273
|
+
return TAG_FILTER.has(tagName.toLowerCase());
|
|
274
|
+
}
|
|
275
|
+
function applyTagFilter(html) {
|
|
276
|
+
return html.replace(/<(?=[ \t\n\r]*\/?[ \t\n\r]*(?:title|textarea|style|xmp|iframe|noembed|noframes|script|plaintext)\b)/gi, '<');
|
|
277
|
+
}
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* Command-line interface for the Markdown parser that reads Markdown from stdin and writes rendered
|
|
5
|
+
* HTML to stdout with optional GFM flags.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
const index_js_1 = require("./parser/index.js");
|
|
9
|
+
const index_js_2 = require("./parser/gfm/index.js");
|
|
10
|
+
const args = process.argv.slice(2);
|
|
11
|
+
const extensions = [];
|
|
12
|
+
for (let i = 0; i < args.length; i++) {
|
|
13
|
+
if (args[i] === '-e' && i + 1 < args.length) {
|
|
14
|
+
extensions.push(args[i + 1]);
|
|
15
|
+
i++;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const useGfm = args.includes('--gfm') || extensions.length > 0;
|
|
19
|
+
const renderOptions = {
|
|
20
|
+
tablePreferStyleAttributes: args.includes('--table-prefer-style-attributes') ||
|
|
21
|
+
extensions.includes('table-prefer-style-attributes'),
|
|
22
|
+
fullInfoString: args.includes('--full-info-string') || extensions.includes('full-info-string'),
|
|
23
|
+
smart: args.includes('--smart') || extensions.includes('smart'),
|
|
24
|
+
softbreak: '\n',
|
|
25
|
+
};
|
|
26
|
+
let input = '';
|
|
27
|
+
process.stdin.setEncoding('utf8');
|
|
28
|
+
process.stdin.on('data', (chunk) => {
|
|
29
|
+
input += chunk;
|
|
30
|
+
});
|
|
31
|
+
process.stdin.on('end', () => {
|
|
32
|
+
const html = useGfm
|
|
33
|
+
? (0, index_js_2.gfm)(input, { ...renderOptions, extensions })
|
|
34
|
+
: (0, index_js_1.markdown)(input, renderOptions);
|
|
35
|
+
process.stdout.write(html);
|
|
36
|
+
});
|
package/dist/esm/cli.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Command-line interface for the Markdown parser that reads Markdown from stdin and writes rendered
|
|
4
|
+
* HTML to stdout with optional GFM flags.
|
|
5
|
+
*/
|
|
6
|
+
import { markdown } from './parser/index.js';
|
|
7
|
+
import { gfm } from './parser/gfm/index.js';
|
|
8
|
+
const args = process.argv.slice(2);
|
|
9
|
+
const extensions = [];
|
|
10
|
+
for (let i = 0; i < args.length; i++) {
|
|
11
|
+
if (args[i] === '-e' && i + 1 < args.length) {
|
|
12
|
+
extensions.push(args[i + 1]);
|
|
13
|
+
i++;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const useGfm = args.includes('--gfm') || extensions.length > 0;
|
|
17
|
+
const renderOptions = {
|
|
18
|
+
tablePreferStyleAttributes: args.includes('--table-prefer-style-attributes') ||
|
|
19
|
+
extensions.includes('table-prefer-style-attributes'),
|
|
20
|
+
fullInfoString: args.includes('--full-info-string') || extensions.includes('full-info-string'),
|
|
21
|
+
smart: args.includes('--smart') || extensions.includes('smart'),
|
|
22
|
+
softbreak: '\n',
|
|
23
|
+
};
|
|
24
|
+
let input = '';
|
|
25
|
+
process.stdin.setEncoding('utf8');
|
|
26
|
+
process.stdin.on('data', (chunk) => {
|
|
27
|
+
input += chunk;
|
|
28
|
+
});
|
|
29
|
+
process.stdin.on('end', () => {
|
|
30
|
+
const html = useGfm
|
|
31
|
+
? gfm(input, { ...renderOptions, extensions })
|
|
32
|
+
: markdown(input, renderOptions);
|
|
33
|
+
process.stdout.write(html);
|
|
34
|
+
});
|
package/dist/esm/gfm.js
ADDED