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,163 @@
1
+ "use strict";
2
+ /**
3
+ * Parser for GFM tables built from pipe-delimited rows.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parseDelimiterRow = parseDelimiterRow;
7
+ exports.splitTableRow = splitTableRow;
8
+ exports.isTableRow = isTableRow;
9
+ exports.couldBeTableHeader = couldBeTableHeader;
10
+ exports.isTableStart = isTableStart;
11
+ exports.createTableCellNode = createTableCellNode;
12
+ exports.createTableRowNode = createTableRowNode;
13
+ exports.createTableNode = createTableNode;
14
+ exports.parseTableRowCells = parseTableRowCells;
15
+ function parseDelimiterRow(line) {
16
+ const trimmed = line.trim();
17
+ let cells = splitTableRow(trimmed);
18
+ if (cells.length === 0)
19
+ return null;
20
+ const alignments = [];
21
+ for (const cell of cells) {
22
+ const content = cell.trim();
23
+ if (!/^:?-+:?$/.test(content)) {
24
+ return null;
25
+ }
26
+ const hasLeftColon = content.startsWith(':');
27
+ const hasRightColon = content.endsWith(':');
28
+ if (hasLeftColon && hasRightColon) {
29
+ alignments.push('center');
30
+ }
31
+ else if (hasRightColon) {
32
+ alignments.push('right');
33
+ }
34
+ else if (hasLeftColon) {
35
+ alignments.push('left');
36
+ }
37
+ else {
38
+ alignments.push(null);
39
+ }
40
+ }
41
+ return alignments;
42
+ }
43
+ function splitTableRow(line) {
44
+ const cells = [];
45
+ let current = '';
46
+ let i = 0;
47
+ let inBackticks = false;
48
+ let backtickCount = 0;
49
+ let trimmed = line.trim();
50
+ if (trimmed.startsWith('|')) {
51
+ trimmed = trimmed.slice(1);
52
+ }
53
+ if (trimmed.endsWith('|') && !trimmed.endsWith('\\|')) {
54
+ trimmed = trimmed.slice(0, -1);
55
+ }
56
+ while (i < trimmed.length) {
57
+ const char = trimmed[i];
58
+ if (char === '`') {
59
+ if (!inBackticks) {
60
+ inBackticks = true;
61
+ backtickCount = 1;
62
+ let j = i + 1;
63
+ while (j < trimmed.length && trimmed[j] === '`') {
64
+ backtickCount++;
65
+ j++;
66
+ }
67
+ current += trimmed.slice(i, j);
68
+ i = j;
69
+ continue;
70
+ }
71
+ else {
72
+ let closeCount = 1;
73
+ let j = i + 1;
74
+ while (j < trimmed.length && trimmed[j] === '`') {
75
+ closeCount++;
76
+ j++;
77
+ }
78
+ if (closeCount === backtickCount) {
79
+ inBackticks = false;
80
+ }
81
+ current += trimmed.slice(i, j);
82
+ i = j;
83
+ continue;
84
+ }
85
+ }
86
+ if (char === '\\' && i + 1 < trimmed.length && trimmed[i + 1] === '|') {
87
+ current += '|';
88
+ i += 2;
89
+ continue;
90
+ }
91
+ if (char === '|' && !inBackticks) {
92
+ cells.push(current);
93
+ current = '';
94
+ i++;
95
+ continue;
96
+ }
97
+ current += char;
98
+ i++;
99
+ }
100
+ cells.push(current);
101
+ return cells;
102
+ }
103
+ function isTableRow(line) {
104
+ const trimmed = line.trim();
105
+ for (let i = 0; i < trimmed.length; i++) {
106
+ if (trimmed[i] === '|') {
107
+ if (i === 0 || trimmed[i - 1] !== '\\') {
108
+ return true;
109
+ }
110
+ }
111
+ }
112
+ return false;
113
+ }
114
+ function couldBeTableHeader(line) {
115
+ return isTableRow(line);
116
+ }
117
+ function isTableStart(headerLine, delimiterLine) {
118
+ if (!isTableRow(headerLine))
119
+ return null;
120
+ const headerCells = splitTableRow(headerLine);
121
+ const hasContent = headerCells.some(cell => cell.trim() !== '');
122
+ if (!hasContent)
123
+ return null;
124
+ const alignments = parseDelimiterRow(delimiterLine);
125
+ if (!alignments)
126
+ return null;
127
+ if (headerCells.length !== alignments.length)
128
+ return null;
129
+ return alignments;
130
+ }
131
+ function createTableCellNode(align, isHeader, children = []) {
132
+ return {
133
+ type: 'table_cell',
134
+ children,
135
+ align,
136
+ isHeader,
137
+ };
138
+ }
139
+ function createTableRowNode(isHeader, cells = []) {
140
+ return {
141
+ type: 'table_row',
142
+ children: cells,
143
+ isHeader,
144
+ };
145
+ }
146
+ function createTableNode(alignments) {
147
+ return {
148
+ type: 'table',
149
+ alignments,
150
+ children: [],
151
+ };
152
+ }
153
+ function parseTableRowCells(line, alignments, isHeader) {
154
+ const cellContents = splitTableRow(line);
155
+ const cells = [];
156
+ for (let i = 0; i < alignments.length; i++) {
157
+ const content = cellContents[i]?.trim() ?? '';
158
+ const cell = createTableCellNode(alignments[i], isHeader);
159
+ cell.rawContent = content;
160
+ cells.push(cell);
161
+ }
162
+ return cells;
163
+ }
@@ -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,66 @@
1
+ "use strict";
2
+ /**
3
+ * Parser for GFM task list items that recognize [ ] and [x] markers.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parseTaskListMarker = parseTaskListMarker;
7
+ exports.processTaskListItem = processTaskListItem;
8
+ exports.processTaskLists = processTaskLists;
9
+ const TASK_LIST_MARKER = /^\[([ xX])\](?=\s)/;
10
+ function parseTaskListMarker(text) {
11
+ const match = text.match(TASK_LIST_MARKER);
12
+ if (!match)
13
+ return null;
14
+ const char = match[1];
15
+ const checked = char === 'x' || char === 'X';
16
+ return {
17
+ checked,
18
+ length: 3,
19
+ };
20
+ }
21
+ function processTaskListItem(item) {
22
+ if (item.children.length === 0)
23
+ return;
24
+ const firstChild = item.children[0];
25
+ if (firstChild.type !== 'paragraph')
26
+ return;
27
+ const para = firstChild;
28
+ const rawContent = para.rawContent;
29
+ if (typeof rawContent === 'string') {
30
+ const result = parseTaskListMarker(rawContent);
31
+ if (result) {
32
+ item.checked = result.checked;
33
+ para.rawContent = rawContent.slice(result.length).replace(/^\s/, '');
34
+ }
35
+ return;
36
+ }
37
+ if (para.children && para.children.length > 0) {
38
+ const firstInline = para.children[0];
39
+ if (firstInline.type === 'text') {
40
+ const textNode = firstInline;
41
+ const result = parseTaskListMarker(textNode.literal);
42
+ if (result) {
43
+ item.checked = result.checked;
44
+ textNode.literal = textNode.literal.slice(result.length).replace(/^\s/, '');
45
+ if (textNode.literal === '') {
46
+ para.children.shift();
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
52
+ function processTaskLists(blocks) {
53
+ for (const block of blocks) {
54
+ if (block.type === 'list') {
55
+ for (const item of block.children) {
56
+ processTaskListItem(item);
57
+ if (item.children) {
58
+ processTaskLists(item.children);
59
+ }
60
+ }
61
+ }
62
+ else if (block.type === 'blockquote' && block.children) {
63
+ processTaskLists(block.children);
64
+ }
65
+ }
66
+ }
@@ -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,17 @@
1
+ "use strict";
2
+ /**
3
+ * Parser for thematic breaks (horizontal rules).
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parseThematicBreak = parseThematicBreak;
7
+ exports.isThematicBreak = isThematicBreak;
8
+ const THEMATIC_BREAK_REGEX = /^( {0,3})([-*_])(?:[ \t]*\2){2,}[ \t]*$/;
9
+ function parseThematicBreak(line) {
10
+ if (THEMATIC_BREAK_REGEX.test(line)) {
11
+ return { type: 'thematic_break' };
12
+ }
13
+ return null;
14
+ }
15
+ function isThematicBreak(line) {
16
+ return THEMATIC_BREAK_REGEX.test(line);
17
+ }
@@ -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>;