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.
Files changed (199) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +124 -0
  3. package/dist/cjs/cli.js +36 -0
  4. package/dist/cjs/gfm.js +26 -0
  5. package/dist/cjs/index.js +26 -0
  6. package/dist/cjs/parser/block-parser.js +644 -0
  7. package/dist/cjs/parser/blocks/blockquote.js +28 -0
  8. package/dist/cjs/parser/blocks/code-block-fenced.js +58 -0
  9. package/dist/cjs/parser/blocks/code-block-indented.js +47 -0
  10. package/dist/cjs/parser/blocks/heading-atx.js +29 -0
  11. package/dist/cjs/parser/blocks/heading-setext.js +24 -0
  12. package/dist/cjs/parser/blocks/html-block.js +83 -0
  13. package/dist/cjs/parser/blocks/link-reference.js +109 -0
  14. package/dist/cjs/parser/blocks/list.js +155 -0
  15. package/dist/cjs/parser/blocks/paragraph.js +20 -0
  16. package/dist/cjs/parser/blocks/table.js +163 -0
  17. package/dist/cjs/parser/blocks/task-list.js +66 -0
  18. package/dist/cjs/parser/blocks/thematic-break.js +17 -0
  19. package/dist/cjs/parser/entities.js +2133 -0
  20. package/dist/cjs/parser/gfm/block-parser.js +773 -0
  21. package/dist/cjs/parser/gfm/index.js +125 -0
  22. package/dist/cjs/parser/gfm/inline-parser.js +813 -0
  23. package/dist/cjs/parser/gfm/renderer.js +513 -0
  24. package/dist/cjs/parser/index.js +104 -0
  25. package/dist/cjs/parser/inline-parser.js +564 -0
  26. package/dist/cjs/parser/inlines/autolink-extended.js +364 -0
  27. package/dist/cjs/parser/inlines/autolink.js +44 -0
  28. package/dist/cjs/parser/inlines/code-span.js +48 -0
  29. package/dist/cjs/parser/inlines/emphasis.js +64 -0
  30. package/dist/cjs/parser/inlines/entity.js +25 -0
  31. package/dist/cjs/parser/inlines/escape.js +25 -0
  32. package/dist/cjs/parser/inlines/footnote.js +41 -0
  33. package/dist/cjs/parser/inlines/hard-break.js +45 -0
  34. package/dist/cjs/parser/inlines/image.js +9 -0
  35. package/dist/cjs/parser/inlines/link.js +166 -0
  36. package/dist/cjs/parser/inlines/soft-break.js +18 -0
  37. package/dist/cjs/parser/inlines/strikethrough.js +48 -0
  38. package/dist/cjs/parser/inlines/text.js +20 -0
  39. package/dist/cjs/parser/renderer.js +345 -0
  40. package/dist/cjs/parser/types.js +5 -0
  41. package/dist/cjs/parser/utils.js +277 -0
  42. package/dist/cli.d.ts +6 -0
  43. package/dist/cli.js +36 -0
  44. package/dist/esm/cli.js +34 -0
  45. package/dist/esm/gfm.js +5 -0
  46. package/dist/esm/index.js +5 -0
  47. package/dist/esm/package.json +3 -0
  48. package/dist/esm/parser/block-parser.js +640 -0
  49. package/dist/esm/parser/blocks/blockquote.js +22 -0
  50. package/dist/esm/parser/blocks/code-block-fenced.js +52 -0
  51. package/dist/esm/parser/blocks/code-block-indented.js +42 -0
  52. package/dist/esm/parser/blocks/heading-atx.js +24 -0
  53. package/dist/esm/parser/blocks/heading-setext.js +19 -0
  54. package/dist/esm/parser/blocks/html-block.js +77 -0
  55. package/dist/esm/parser/blocks/link-reference.js +105 -0
  56. package/dist/esm/parser/blocks/list.js +145 -0
  57. package/dist/esm/parser/blocks/paragraph.js +15 -0
  58. package/dist/esm/parser/blocks/table.js +152 -0
  59. package/dist/esm/parser/blocks/task-list.js +61 -0
  60. package/dist/esm/parser/blocks/thematic-break.js +13 -0
  61. package/dist/esm/parser/entities.js +2130 -0
  62. package/dist/esm/parser/gfm/block-parser.js +769 -0
  63. package/dist/esm/parser/gfm/index.js +115 -0
  64. package/dist/esm/parser/gfm/inline-parser.js +809 -0
  65. package/dist/esm/parser/gfm/renderer.js +509 -0
  66. package/dist/esm/parser/index.js +80 -0
  67. package/dist/esm/parser/inline-parser.js +560 -0
  68. package/dist/esm/parser/inlines/autolink-extended.js +357 -0
  69. package/dist/esm/parser/inlines/autolink.js +40 -0
  70. package/dist/esm/parser/inlines/code-span.js +44 -0
  71. package/dist/esm/parser/inlines/emphasis.js +59 -0
  72. package/dist/esm/parser/inlines/entity.js +21 -0
  73. package/dist/esm/parser/inlines/escape.js +21 -0
  74. package/dist/esm/parser/inlines/footnote.js +38 -0
  75. package/dist/esm/parser/inlines/hard-break.js +41 -0
  76. package/dist/esm/parser/inlines/image.js +4 -0
  77. package/dist/esm/parser/inlines/link.js +156 -0
  78. package/dist/esm/parser/inlines/soft-break.js +14 -0
  79. package/dist/esm/parser/inlines/strikethrough.js +42 -0
  80. package/dist/esm/parser/inlines/text.js +16 -0
  81. package/dist/esm/parser/renderer.js +341 -0
  82. package/dist/esm/parser/types.js +4 -0
  83. package/dist/esm/parser/utils.js +254 -0
  84. package/dist/gfm.d.ts +6 -0
  85. package/dist/gfm.js +26 -0
  86. package/dist/index.d.ts +5 -0
  87. package/dist/index.js +26 -0
  88. package/dist/parser/block-parser.d.ts +25 -0
  89. package/dist/parser/block-parser.js +644 -0
  90. package/dist/parser/blocks/blockquote.d.ts +8 -0
  91. package/dist/parser/blocks/blockquote.js +28 -0
  92. package/dist/parser/blocks/code-block-fenced.d.ts +14 -0
  93. package/dist/parser/blocks/code-block-fenced.js +58 -0
  94. package/dist/parser/blocks/code-block-indented.d.ts +7 -0
  95. package/dist/parser/blocks/code-block-indented.js +47 -0
  96. package/dist/parser/blocks/heading-atx.d.ts +10 -0
  97. package/dist/parser/blocks/heading-atx.js +29 -0
  98. package/dist/parser/blocks/heading-setext.d.ts +8 -0
  99. package/dist/parser/blocks/heading-setext.js +24 -0
  100. package/dist/parser/blocks/html-block.d.ts +9 -0
  101. package/dist/parser/blocks/html-block.js +83 -0
  102. package/dist/parser/blocks/link-reference.d.ts +11 -0
  103. package/dist/parser/blocks/link-reference.js +109 -0
  104. package/dist/parser/blocks/list.d.ts +25 -0
  105. package/dist/parser/blocks/list.js +155 -0
  106. package/dist/parser/blocks/paragraph.d.ts +7 -0
  107. package/dist/parser/blocks/paragraph.js +20 -0
  108. package/dist/parser/blocks/table.d.ts +13 -0
  109. package/dist/parser/blocks/table.js +163 -0
  110. package/dist/parser/blocks/task-list.d.ts +10 -0
  111. package/dist/parser/blocks/task-list.js +66 -0
  112. package/dist/parser/blocks/thematic-break.d.ts +6 -0
  113. package/dist/parser/blocks/thematic-break.js +17 -0
  114. package/dist/parser/entities.d.ts +4 -0
  115. package/dist/parser/entities.js +2133 -0
  116. package/dist/parser/gfm/block-parser.d.ts +32 -0
  117. package/dist/parser/gfm/block-parser.js +773 -0
  118. package/dist/parser/gfm/index.d.ts +31 -0
  119. package/dist/parser/gfm/index.js +125 -0
  120. package/dist/parser/gfm/inline-parser.d.ts +25 -0
  121. package/dist/parser/gfm/inline-parser.js +813 -0
  122. package/dist/parser/gfm/renderer.d.ts +43 -0
  123. package/dist/parser/gfm/renderer.js +513 -0
  124. package/dist/parser/index.d.ts +33 -0
  125. package/dist/parser/index.js +104 -0
  126. package/dist/parser/inline-parser.d.ts +16 -0
  127. package/dist/parser/inline-parser.js +564 -0
  128. package/dist/parser/inlines/autolink-extended.d.ts +24 -0
  129. package/dist/parser/inlines/autolink-extended.js +364 -0
  130. package/dist/parser/inlines/autolink.d.ts +9 -0
  131. package/dist/parser/inlines/autolink.js +44 -0
  132. package/dist/parser/inlines/code-span.d.ts +9 -0
  133. package/dist/parser/inlines/code-span.js +48 -0
  134. package/dist/parser/inlines/emphasis.d.ts +14 -0
  135. package/dist/parser/inlines/emphasis.js +64 -0
  136. package/dist/parser/inlines/entity.d.ts +8 -0
  137. package/dist/parser/inlines/entity.js +25 -0
  138. package/dist/parser/inlines/escape.d.ts +8 -0
  139. package/dist/parser/inlines/escape.js +25 -0
  140. package/dist/parser/inlines/footnote.d.ts +9 -0
  141. package/dist/parser/inlines/footnote.js +41 -0
  142. package/dist/parser/inlines/hard-break.d.ts +9 -0
  143. package/dist/parser/inlines/hard-break.js +45 -0
  144. package/dist/parser/inlines/image.d.ts +4 -0
  145. package/dist/parser/inlines/image.js +9 -0
  146. package/dist/parser/inlines/link.d.ts +33 -0
  147. package/dist/parser/inlines/link.js +166 -0
  148. package/dist/parser/inlines/soft-break.d.ts +9 -0
  149. package/dist/parser/inlines/soft-break.js +18 -0
  150. package/dist/parser/inlines/strikethrough.d.ts +16 -0
  151. package/dist/parser/inlines/strikethrough.js +48 -0
  152. package/dist/parser/inlines/text.d.ts +6 -0
  153. package/dist/parser/inlines/text.js +20 -0
  154. package/dist/parser/renderer.d.ts +33 -0
  155. package/dist/parser/renderer.js +345 -0
  156. package/dist/parser/types.d.ts +152 -0
  157. package/dist/parser/types.js +5 -0
  158. package/dist/parser/utils.d.ts +32 -0
  159. package/dist/parser/utils.js +277 -0
  160. package/dist/types/cli.d.ts +6 -0
  161. package/dist/types/gfm.d.ts +6 -0
  162. package/dist/types/index.d.ts +5 -0
  163. package/dist/types/parser/block-parser.d.ts +25 -0
  164. package/dist/types/parser/blocks/blockquote.d.ts +8 -0
  165. package/dist/types/parser/blocks/code-block-fenced.d.ts +14 -0
  166. package/dist/types/parser/blocks/code-block-indented.d.ts +7 -0
  167. package/dist/types/parser/blocks/heading-atx.d.ts +10 -0
  168. package/dist/types/parser/blocks/heading-setext.d.ts +8 -0
  169. package/dist/types/parser/blocks/html-block.d.ts +9 -0
  170. package/dist/types/parser/blocks/link-reference.d.ts +11 -0
  171. package/dist/types/parser/blocks/list.d.ts +25 -0
  172. package/dist/types/parser/blocks/paragraph.d.ts +7 -0
  173. package/dist/types/parser/blocks/table.d.ts +13 -0
  174. package/dist/types/parser/blocks/task-list.d.ts +10 -0
  175. package/dist/types/parser/blocks/thematic-break.d.ts +6 -0
  176. package/dist/types/parser/entities.d.ts +4 -0
  177. package/dist/types/parser/gfm/block-parser.d.ts +32 -0
  178. package/dist/types/parser/gfm/index.d.ts +31 -0
  179. package/dist/types/parser/gfm/inline-parser.d.ts +25 -0
  180. package/dist/types/parser/gfm/renderer.d.ts +43 -0
  181. package/dist/types/parser/index.d.ts +33 -0
  182. package/dist/types/parser/inline-parser.d.ts +16 -0
  183. package/dist/types/parser/inlines/autolink-extended.d.ts +24 -0
  184. package/dist/types/parser/inlines/autolink.d.ts +9 -0
  185. package/dist/types/parser/inlines/code-span.d.ts +9 -0
  186. package/dist/types/parser/inlines/emphasis.d.ts +14 -0
  187. package/dist/types/parser/inlines/entity.d.ts +8 -0
  188. package/dist/types/parser/inlines/escape.d.ts +8 -0
  189. package/dist/types/parser/inlines/footnote.d.ts +9 -0
  190. package/dist/types/parser/inlines/hard-break.d.ts +9 -0
  191. package/dist/types/parser/inlines/image.d.ts +4 -0
  192. package/dist/types/parser/inlines/link.d.ts +33 -0
  193. package/dist/types/parser/inlines/soft-break.d.ts +9 -0
  194. package/dist/types/parser/inlines/strikethrough.d.ts +16 -0
  195. package/dist/types/parser/inlines/text.d.ts +6 -0
  196. package/dist/types/parser/renderer.d.ts +33 -0
  197. package/dist/types/parser/types.d.ts +152 -0
  198. package/dist/types/parser/utils.d.ts +32 -0
  199. 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, '&amp;')
56
+ .replace(/</g, '&lt;')
57
+ .replace(/>/g, '&gt;')
58
+ .replace(/"/g, '&quot;');
59
+ }
60
+ function escapeHtml(str, preserveEntities = false) {
61
+ if (preserveEntities) {
62
+ return str
63
+ .replace(/&(?![#a-zA-Z0-9]+;)/g, '&amp;')
64
+ .replace(/</g, '&lt;')
65
+ .replace(/>/g, '&gt;')
66
+ .replace(/"/g, '&quot;');
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, '&lt;');
277
+ }
@@ -0,0 +1,6 @@
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
+ export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Entry point for GitHub Flavored Markdown that re-exports GFM helpers, renderer, and AST types.
3
+ */
4
+ export * from './parser/gfm/index.js';
5
+ export { default } from './parser/gfm/index.js';
6
+ export type { DocumentNode, BlockNode, InlineNode, ParagraphNode, HeadingNode, ThematicBreakNode, CodeBlockNode, BlockquoteNode, ListNode, ListItemNode, HtmlBlockNode, TableNode, TableRowNode, TableCellNode, TableAlignment, TextNode, SoftbreakNode, HardbreakNode, CodeSpanNode, EmphasisNode, StrongNode, StrikethroughNode, LinkNode, ImageNode, HtmlInlineNode, ParseOptions, RenderOptions, } from './parser/types.js';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Main entry point for the CommonMark parser that re-exports public APIs.
3
+ */
4
+ export * from './parser/index.js';
5
+ export { default } from './parser/index.js';
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Block parsing phase that builds block nodes like paragraphs, headings, lists, code blocks,
3
+ * blockquotes, and HTML blocks while collecting link reference definitions.
4
+ */
5
+ import type { DocumentNode, LinkReferenceDefinition } from './types.js';
6
+ export declare class BlockParser {
7
+ private lines;
8
+ private lineIndex;
9
+ private linkReferences;
10
+ private static readonly LAZY_PREFIX;
11
+ parse(input: string): {
12
+ document: DocumentNode;
13
+ linkReferences: Map<string, LinkReferenceDefinition>;
14
+ };
15
+ private currentLine;
16
+ private advance;
17
+ private parseBlocks;
18
+ private parseList;
19
+ private parseListItem;
20
+ private lastNonBlankLine;
21
+ private getBlockquotePrefix;
22
+ private allowsLazyAfterListMarker;
23
+ private extractBlockquoteContent;
24
+ private extractListItemContent;
25
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Parser for blockquote elements prefixed with >.
3
+ */
4
+ import type { BlockquoteNode } from '../types.js';
5
+ export declare function isBlockquoteStart(line: string): boolean;
6
+ export declare function removeBlockquotePrefix(line: string): string;
7
+ export declare function createBlockquoteNode(): BlockquoteNode;
8
+ export declare function getBlockquoteContent(line: string): string | null;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Parser for fenced code blocks with optional info strings.
3
+ */
4
+ import type { CodeBlockNode } from '../types.js';
5
+ export interface FenceInfo {
6
+ indent: number;
7
+ char: '`' | '~';
8
+ length: number;
9
+ info: string;
10
+ }
11
+ export declare function parseFenceOpen(line: string): FenceInfo | null;
12
+ export declare function isFenceClose(line: string, fence: FenceInfo): boolean;
13
+ export declare function isFencedCodeStart(line: string): boolean;
14
+ export declare function createFencedCodeBlock(info: string, lines: string[], indent: number): CodeBlockNode;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Parser for indented code blocks.
3
+ */
4
+ import type { CodeBlockNode } from '../types.js';
5
+ export declare function isIndentedCodeLine(line: string): boolean;
6
+ export declare function removeIndentation(line: string, amount?: number): string;
7
+ export declare function createIndentedCodeBlock(lines: string[]): CodeBlockNode;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Parser for ATX headings using leading # markers.
3
+ */
4
+ import type { HeadingNode } from '../types.js';
5
+ export declare function parseAtxHeading(line: string): {
6
+ level: 1 | 2 | 3 | 4 | 5 | 6;
7
+ content: string;
8
+ } | null;
9
+ export declare function isAtxHeading(line: string): boolean;
10
+ export declare function createHeadingNode(level: 1 | 2 | 3 | 4 | 5 | 6): HeadingNode;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Parser for setext headings underlined with = or -.
3
+ */
4
+ export declare function parseSetextHeading(line: string): {
5
+ level: 1 | 2;
6
+ } | null;
7
+ export declare function isSetextHeadingUnderline(line: string): boolean;
8
+ export declare function getSetextLevel(line: string): 1 | 2 | null;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Parser for raw HTML blocks defined by the CommonMark spec.
3
+ */
4
+ import type { HtmlBlockNode } from '../types.js';
5
+ export type HtmlBlockType = 1 | 2 | 3 | 4 | 5 | 6 | 7 | null;
6
+ export declare function getHtmlBlockType(line: string, canInterruptParagraph: boolean): HtmlBlockType;
7
+ export declare function isHtmlBlockClose(line: string, type: HtmlBlockType): boolean;
8
+ export declare function isHtmlBlockStart(line: string, canInterruptParagraph?: boolean): boolean;
9
+ export declare function createHtmlBlockNode(content: string): HtmlBlockNode;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Parser for link reference definitions used by reference-style links.
3
+ */
4
+ import type { LinkReferenceDefinition } from '../types.js';
5
+ export interface LinkRefResult {
6
+ label: string;
7
+ definition: LinkReferenceDefinition;
8
+ consumed: number;
9
+ }
10
+ export declare function parseLinkReferenceDefinition(text: string): LinkRefResult | null;
11
+ export declare function isLinkReferenceStart(line: string): boolean;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Parser for ordered and unordered lists with nesting and tight/loose detection.
3
+ */
4
+ import type { ListNode, ListItemNode } from '../types.js';
5
+ export interface ListMarker {
6
+ type: 'bullet' | 'ordered';
7
+ indent: number;
8
+ indentChars: number;
9
+ marker: string;
10
+ bulletChar?: '-' | '+' | '*';
11
+ start?: number;
12
+ delimiter?: '.' | ')';
13
+ padding: number;
14
+ paddingChars: number;
15
+ contentIndent: number;
16
+ contentCharIndex: number;
17
+ }
18
+ export declare function parseListMarker(line: string): ListMarker | null;
19
+ export declare function isListItemStart(line: string): boolean;
20
+ export declare function isBulletListStart(line: string): boolean;
21
+ export declare function isOrderedListStart(line: string): boolean;
22
+ export declare function canStartList(line: string, interruptingParagraph: boolean): boolean;
23
+ export declare function createListNode(marker: ListMarker): ListNode;
24
+ export declare function createListItemNode(): ListItemNode;
25
+ export declare function listsMatch(a: ListMarker, b: ListMarker): boolean;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Parser for paragraph blocks as the default block type.
3
+ */
4
+ import type { ParagraphNode } from '../types.js';
5
+ export declare function createParagraphNode(): ParagraphNode;
6
+ export declare function isParagraphContinuation(line: string): boolean;
7
+ export declare function trimParagraphLine(line: string): string;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Parser for GFM tables built from pipe-delimited rows.
3
+ */
4
+ import type { TableNode, TableRowNode, TableCellNode, TableAlignment, InlineNode } from '../types.js';
5
+ export declare function parseDelimiterRow(line: string): TableAlignment[] | null;
6
+ export declare function splitTableRow(line: string): string[];
7
+ export declare function isTableRow(line: string): boolean;
8
+ export declare function couldBeTableHeader(line: string): boolean;
9
+ export declare function isTableStart(headerLine: string, delimiterLine: string): TableAlignment[] | null;
10
+ export declare function createTableCellNode(align: TableAlignment, isHeader: boolean, children?: InlineNode[]): TableCellNode;
11
+ export declare function createTableRowNode(isHeader: boolean, cells?: TableCellNode[]): TableRowNode;
12
+ export declare function createTableNode(alignments: TableAlignment[]): TableNode;
13
+ export declare function parseTableRowCells(line: string, alignments: TableAlignment[], isHeader: boolean): TableCellNode[];
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Parser for GFM task list items that recognize [ ] and [x] markers.
3
+ */
4
+ import type { ListItemNode } from '../types.js';
5
+ export declare function parseTaskListMarker(text: string): {
6
+ checked: boolean;
7
+ length: number;
8
+ } | null;
9
+ export declare function processTaskListItem(item: ListItemNode): void;
10
+ export declare function processTaskLists(blocks: any[]): void;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Parser for thematic breaks (horizontal rules).
3
+ */
4
+ import type { ThematicBreakNode } from '../types.js';
5
+ export declare function parseThematicBreak(line: string): ThematicBreakNode | null;
6
+ export declare function isThematicBreak(line: string): boolean;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * HTML named character reference map used to decode entities in Markdown content.
3
+ */
4
+ export declare const HTML_ENTITIES: Record<string, string>;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * GFM block parser that extends CommonMark with table support.
3
+ */
4
+ import type { DocumentNode, LinkReferenceDefinition, FootnoteDefinition } from '../types.js';
5
+ export declare class GFMBlockParser {
6
+ private lines;
7
+ private lineIndex;
8
+ private linkReferences;
9
+ private footnoteDefinitions;
10
+ private static readonly LAZY_PREFIX;
11
+ private enableTables;
12
+ private enableTaskLists;
13
+ private enableFootnotes;
14
+ constructor(extensions?: Set<string>);
15
+ parse(input: string): {
16
+ document: DocumentNode;
17
+ linkReferences: Map<string, LinkReferenceDefinition>;
18
+ footnoteDefinitions: Map<string, FootnoteDefinition>;
19
+ };
20
+ private currentLine;
21
+ private advance;
22
+ private parseBlocks;
23
+ private parseTable;
24
+ private parseFootnoteDefinition;
25
+ private parseList;
26
+ private parseListItem;
27
+ private lastNonBlankLine;
28
+ private getBlockquotePrefix;
29
+ private allowsLazyAfterListMarker;
30
+ private extractBlockquoteContent;
31
+ private extractListItemContent;
32
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * GFM parser entry point that exposes the CommonMark superset with GFM extensions.
3
+ */
4
+ import type { DocumentNode, ParseOptions, RenderOptions } from '../types.js';
5
+ import { GFMBlockParser } from './block-parser.js';
6
+ import { GFMInlineParser } from './inline-parser.js';
7
+ import { GFMHtmlRenderer } from './renderer.js';
8
+ export { GFMBlockParser } from './block-parser.js';
9
+ export { GFMInlineParser } from './inline-parser.js';
10
+ export { GFMHtmlRenderer } from './renderer.js';
11
+ export declare class GFMParser {
12
+ private blockParser;
13
+ private inlineParser;
14
+ private options;
15
+ constructor(options?: ParseOptions);
16
+ parse(input: string): DocumentNode;
17
+ private processInlines;
18
+ }
19
+ export declare function parse(input: string, options?: ParseOptions): DocumentNode;
20
+ export declare function render(document: DocumentNode, options?: RenderOptions): string;
21
+ export declare function gfm(input: string, options?: ParseOptions & RenderOptions): string;
22
+ declare const _default: {
23
+ parse: typeof parse;
24
+ render: typeof render;
25
+ gfm: typeof gfm;
26
+ GFMParser: typeof GFMParser;
27
+ GFMBlockParser: typeof GFMBlockParser;
28
+ GFMInlineParser: typeof GFMInlineParser;
29
+ GFMHtmlRenderer: typeof GFMHtmlRenderer;
30
+ };
31
+ export default _default;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * GFM inline parser that extends CommonMark with strikethrough and extended autolinks.
3
+ */
4
+ import type { InlineNode, LinkReferenceDefinition, FootnoteDefinition } from '../types.js';
5
+ export declare class GFMInlineParser {
6
+ private linkReferences;
7
+ private footnoteDefinitions;
8
+ private enableAutolink;
9
+ private enableStrikethrough;
10
+ private enableFootnotes;
11
+ private enableTagfilter;
12
+ constructor(extensions?: Set<string>);
13
+ setLinkReferences(refs: Map<string, LinkReferenceDefinition>): void;
14
+ setFootnoteDefinitions(defs: Map<string, FootnoteDefinition>): void;
15
+ parse(text: string): InlineNode[];
16
+ private extractTextFromNodes;
17
+ private normalizeLabelForMatching;
18
+ private processEmphasisAndStrikethrough;
19
+ private processStrikethrough;
20
+ private processEmphasis;
21
+ private flattenNestedEmphasis;
22
+ private computeDelimiterRun;
23
+ private getFirstChar;
24
+ private getLastChar;
25
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * GFM HTML renderer that adds tables, strikethrough, and task list rendering on top of CommonMark.
3
+ */
4
+ import type { DocumentNode, RenderOptions } from '../types.js';
5
+ export declare class GFMHtmlRenderer {
6
+ private options;
7
+ private footnoteDefinitions;
8
+ private footnoteOrder;
9
+ private footnoteRefCounts;
10
+ private footnoteRefIds;
11
+ constructor(options?: RenderOptions);
12
+ render(document: DocumentNode): string;
13
+ private renderBlocks;
14
+ private renderBlock;
15
+ private renderParagraph;
16
+ private renderHeading;
17
+ private renderThematicBreak;
18
+ private renderCodeBlock;
19
+ private renderBlockquote;
20
+ private renderList;
21
+ private renderListItem;
22
+ private renderHtmlBlock;
23
+ private renderTable;
24
+ private renderTableRow;
25
+ private renderTableCell;
26
+ private renderInlines;
27
+ private renderInline;
28
+ private renderText;
29
+ private renderSoftbreak;
30
+ private renderHardbreak;
31
+ private renderCodeSpan;
32
+ private renderEmphasis;
33
+ private renderStrong;
34
+ private renderStrikethrough;
35
+ private renderFootnoteRef;
36
+ private renderLink;
37
+ private renderImage;
38
+ private renderHtmlInline;
39
+ private renderInlinesSmart;
40
+ private applyDashesAndEllipses;
41
+ private renderFootnotes;
42
+ private renderFootnoteBackrefs;
43
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Core parser module that coordinates block and inline parsing and exposes the main parser
3
+ * class and convenience helpers.
4
+ */
5
+ import type { DocumentNode, ParseOptions, RenderOptions } from './types.js';
6
+ import { BlockParser } from './block-parser.js';
7
+ import { InlineParser } from './inline-parser.js';
8
+ import { HtmlRenderer } from './renderer.js';
9
+ export * from './types.js';
10
+ export { BlockParser } from './block-parser.js';
11
+ export { InlineParser } from './inline-parser.js';
12
+ export { HtmlRenderer } from './renderer.js';
13
+ export declare class MarkdownParser {
14
+ private blockParser;
15
+ private inlineParser;
16
+ private options;
17
+ constructor(options?: ParseOptions);
18
+ parse(input: string): DocumentNode;
19
+ private processInlines;
20
+ }
21
+ export declare function parse(input: string, options?: ParseOptions): DocumentNode;
22
+ export declare function render(document: DocumentNode, options?: RenderOptions): string;
23
+ export declare function markdown(input: string, options?: ParseOptions & RenderOptions): string;
24
+ declare const _default: {
25
+ parse: typeof parse;
26
+ render: typeof render;
27
+ markdown: typeof markdown;
28
+ MarkdownParser: typeof MarkdownParser;
29
+ BlockParser: typeof BlockParser;
30
+ InlineParser: typeof InlineParser;
31
+ HtmlRenderer: typeof HtmlRenderer;
32
+ };
33
+ export default _default;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Inline parsing phase that builds inline nodes such as emphasis, links, images, code spans,
3
+ * autolinks, and HTML.
4
+ */
5
+ import type { InlineNode, LinkReferenceDefinition } from './types.js';
6
+ export declare class InlineParser {
7
+ private linkReferences;
8
+ setLinkReferences(refs: Map<string, LinkReferenceDefinition>): void;
9
+ parse(text: string): InlineNode[];
10
+ private extractTextFromNodes;
11
+ private normalizeLabelForMatching;
12
+ private processEmphasis;
13
+ private computeDelimiterRun;
14
+ private getFirstChar;
15
+ private getLastChar;
16
+ }