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,58 @@
1
+ "use strict";
2
+ /**
3
+ * Parser for fenced code blocks with optional info strings.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parseFenceOpen = parseFenceOpen;
7
+ exports.isFenceClose = isFenceClose;
8
+ exports.isFencedCodeStart = isFencedCodeStart;
9
+ exports.createFencedCodeBlock = createFencedCodeBlock;
10
+ const BACKTICK_FENCE_OPEN_REGEX = /^( {0,3})(`{3,})([^`]*)$/;
11
+ const TILDE_FENCE_OPEN_REGEX = /^( {0,3})(~{3,})(.*)$/;
12
+ function parseFenceOpen(line) {
13
+ let match = line.match(BACKTICK_FENCE_OPEN_REGEX);
14
+ if (!match) {
15
+ match = line.match(TILDE_FENCE_OPEN_REGEX);
16
+ }
17
+ if (!match)
18
+ return null;
19
+ const indent = match[1].length;
20
+ const fence = match[2];
21
+ const char = fence[0];
22
+ const length = fence.length;
23
+ const info = match[3].trim();
24
+ return { indent, char, length, info };
25
+ }
26
+ function isFenceClose(line, fence) {
27
+ const trimmed = line.replace(/^( {0,3})/, '');
28
+ const closeRegex = new RegExp(`^${fence.char}{${fence.length},}[ \\t]*$`);
29
+ return closeRegex.test(trimmed);
30
+ }
31
+ function isFencedCodeStart(line) {
32
+ return BACKTICK_FENCE_OPEN_REGEX.test(line) || TILDE_FENCE_OPEN_REGEX.test(line);
33
+ }
34
+ function createFencedCodeBlock(info, lines, indent) {
35
+ const content = lines
36
+ .map(line => {
37
+ let removed = 0;
38
+ let i = 0;
39
+ while (i < line.length && removed < indent) {
40
+ if (line[i] === ' ') {
41
+ removed++;
42
+ i++;
43
+ }
44
+ else {
45
+ break;
46
+ }
47
+ }
48
+ return line.slice(i);
49
+ })
50
+ .join('\n');
51
+ const hasContent = lines.length > 0 && (lines.length > 1 || lines[0] !== '');
52
+ return {
53
+ type: 'code_block',
54
+ info,
55
+ literal: hasContent ? content + '\n' : '',
56
+ fenced: true,
57
+ };
58
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ /**
3
+ * Parser for indented code blocks.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isIndentedCodeLine = isIndentedCodeLine;
7
+ exports.removeIndentation = removeIndentation;
8
+ exports.createIndentedCodeBlock = createIndentedCodeBlock;
9
+ const utils_js_1 = require("../utils.js");
10
+ function isIndentedCodeLine(line) {
11
+ if (line.trim() === '')
12
+ return false;
13
+ return (0, utils_js_1.countLeadingSpaces)(line) >= 4;
14
+ }
15
+ function removeIndentation(line, amount = 4) {
16
+ let removed = 0;
17
+ let i = 0;
18
+ while (i < line.length && removed < amount) {
19
+ if (line[i] === ' ') {
20
+ removed++;
21
+ i++;
22
+ }
23
+ else if (line[i] === '\t') {
24
+ const tabWidth = 4 - (removed % 4);
25
+ if (removed + tabWidth <= amount) {
26
+ removed += tabWidth;
27
+ i++;
28
+ }
29
+ else {
30
+ break;
31
+ }
32
+ }
33
+ else {
34
+ break;
35
+ }
36
+ }
37
+ return line.slice(i);
38
+ }
39
+ function createIndentedCodeBlock(lines) {
40
+ const content = lines.join('\n');
41
+ return {
42
+ type: 'code_block',
43
+ info: '',
44
+ literal: content + '\n',
45
+ fenced: false,
46
+ };
47
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ /**
3
+ * Parser for ATX headings using leading # markers.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parseAtxHeading = parseAtxHeading;
7
+ exports.isAtxHeading = isAtxHeading;
8
+ exports.createHeadingNode = createHeadingNode;
9
+ const ATX_HEADING_REGEX = /^( {0,3})(#{1,6})([ \t].*|[ \t]*)$/;
10
+ function parseAtxHeading(line) {
11
+ const match = line.match(ATX_HEADING_REGEX);
12
+ if (!match)
13
+ return null;
14
+ const level = match[2].length;
15
+ let content = match[3];
16
+ content = content.replace(/[ \t]+#+[ \t]*$/, '');
17
+ content = content.trim();
18
+ return { level, content };
19
+ }
20
+ function isAtxHeading(line) {
21
+ return ATX_HEADING_REGEX.test(line);
22
+ }
23
+ function createHeadingNode(level) {
24
+ return {
25
+ type: 'heading',
26
+ level,
27
+ children: [],
28
+ };
29
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /**
3
+ * Parser for setext headings underlined with = or -.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parseSetextHeading = parseSetextHeading;
7
+ exports.isSetextHeadingUnderline = isSetextHeadingUnderline;
8
+ exports.getSetextLevel = getSetextLevel;
9
+ const SETEXT_HEADING_REGEX = /^( {0,3})(=+|-+)[ \t]*$/;
10
+ function parseSetextHeading(line) {
11
+ const match = line.match(SETEXT_HEADING_REGEX);
12
+ if (!match)
13
+ return null;
14
+ const char = match[2][0];
15
+ const level = char === '=' ? 1 : 2;
16
+ return { level: level };
17
+ }
18
+ function isSetextHeadingUnderline(line) {
19
+ return SETEXT_HEADING_REGEX.test(line);
20
+ }
21
+ function getSetextLevel(line) {
22
+ const result = parseSetextHeading(line);
23
+ return result?.level ?? null;
24
+ }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ /**
3
+ * Parser for raw HTML blocks defined by the CommonMark spec.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getHtmlBlockType = getHtmlBlockType;
7
+ exports.isHtmlBlockClose = isHtmlBlockClose;
8
+ exports.isHtmlBlockStart = isHtmlBlockStart;
9
+ exports.createHtmlBlockNode = createHtmlBlockNode;
10
+ const TYPE_6_TAGS = new Set([
11
+ 'address', 'article', 'aside', 'base', 'basefont', 'blockquote', 'body',
12
+ 'caption', 'center', 'col', 'colgroup', 'dd', 'details', 'dialog', 'dir',
13
+ 'div', 'dl', 'dt', 'fieldset', 'figcaption', 'figure', 'footer', 'form',
14
+ 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header',
15
+ 'hr', 'html', 'iframe', 'legend', 'li', 'link', 'main', 'menu', 'menuitem',
16
+ 'nav', 'noframes', 'ol', 'optgroup', 'option', 'p', 'param', 'search',
17
+ 'section', 'summary', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead',
18
+ 'title', 'tr', 'track', 'ul'
19
+ ]);
20
+ const TYPE_1_OPEN_REGEX = /^<(?:pre|script|style|textarea)(?:\s|>|$)/i;
21
+ const TYPE_1_CLOSE_REGEX = /<\/(?:pre|script|style|textarea)>/i;
22
+ const TYPE_2_OPEN_REGEX = /^<!--/;
23
+ const TYPE_2_CLOSE_REGEX = /-->/;
24
+ const TYPE_3_OPEN_REGEX = /^<\?/;
25
+ const TYPE_3_CLOSE_REGEX = /\?>/;
26
+ const TYPE_4_OPEN_REGEX = /^<![a-zA-Z]/;
27
+ const TYPE_4_CLOSE_REGEX = />/;
28
+ const TYPE_5_OPEN_REGEX = /^<!\[CDATA\[/i;
29
+ const TYPE_5_CLOSE_REGEX = /\]\]>/;
30
+ const TYPE_6_OPEN_REGEX = /^<\/?([a-zA-Z][a-zA-Z0-9-]*)(?:\s|\/?>|$)/i;
31
+ const TYPE_7_OPEN_TAG_REGEX = /^<([a-zA-Z][a-zA-Z0-9-]*)(?:\s+[a-zA-Z_:][a-zA-Z0-9_.:-]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*\/?>\s*$/i;
32
+ const TYPE_7_CLOSE_TAG_REGEX = /^<\/([a-zA-Z][a-zA-Z0-9-]*)\s*>\s*$/i;
33
+ function getHtmlBlockType(line, canInterruptParagraph) {
34
+ const trimmed = line.replace(/^ {0,3}/, '');
35
+ if (TYPE_1_OPEN_REGEX.test(trimmed))
36
+ return 1;
37
+ if (TYPE_2_OPEN_REGEX.test(trimmed))
38
+ return 2;
39
+ if (TYPE_3_OPEN_REGEX.test(trimmed))
40
+ return 3;
41
+ if (TYPE_4_OPEN_REGEX.test(trimmed))
42
+ return 4;
43
+ if (TYPE_5_OPEN_REGEX.test(trimmed))
44
+ return 5;
45
+ const type6Match = trimmed.match(TYPE_6_OPEN_REGEX);
46
+ if (type6Match && TYPE_6_TAGS.has(type6Match[1].toLowerCase())) {
47
+ return 6;
48
+ }
49
+ if (canInterruptParagraph) {
50
+ if (TYPE_7_OPEN_TAG_REGEX.test(trimmed) || TYPE_7_CLOSE_TAG_REGEX.test(trimmed)) {
51
+ return 7;
52
+ }
53
+ }
54
+ return null;
55
+ }
56
+ function isHtmlBlockClose(line, type) {
57
+ switch (type) {
58
+ case 1:
59
+ return TYPE_1_CLOSE_REGEX.test(line);
60
+ case 2:
61
+ return TYPE_2_CLOSE_REGEX.test(line);
62
+ case 3:
63
+ return TYPE_3_CLOSE_REGEX.test(line);
64
+ case 4:
65
+ return TYPE_4_CLOSE_REGEX.test(line);
66
+ case 5:
67
+ return TYPE_5_CLOSE_REGEX.test(line);
68
+ case 6:
69
+ case 7:
70
+ return line.trim() === '';
71
+ default:
72
+ return false;
73
+ }
74
+ }
75
+ function isHtmlBlockStart(line, canInterruptParagraph = true) {
76
+ return getHtmlBlockType(line, canInterruptParagraph) !== null;
77
+ }
78
+ function createHtmlBlockNode(content) {
79
+ return {
80
+ type: 'html_block',
81
+ literal: content,
82
+ };
83
+ }
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ /**
3
+ * Parser for link reference definitions used by reference-style links.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parseLinkReferenceDefinition = parseLinkReferenceDefinition;
7
+ exports.isLinkReferenceStart = isLinkReferenceStart;
8
+ const utils_js_1 = require("../utils.js");
9
+ const LINK_LABEL_REGEX = /^\[((?:[^\[\]\\]|\\.){0,999})\]/;
10
+ const LINK_DESTINATION_ANGLE_REGEX = /^<([^<>\n\\]|\\.)*>/;
11
+ const LINK_DESTINATION_BARE_REGEX = /^[^\s<\[\]]*(?:\([^\s<\[\]]*\)[^\s<\[\]]*)*[^\s<\[\]]*/;
12
+ const LINK_TITLE_DOUBLE_REGEX = /^"((?:[^"\\]|\\[\s\S])*)"/;
13
+ const LINK_TITLE_SINGLE_REGEX = /^'((?:[^'\\]|\\[\s\S])*)'/;
14
+ const LINK_TITLE_PAREN_REGEX = /^\(((?:[^()\\]|\\[\s\S])*)\)/;
15
+ function parseLinkReferenceDefinition(text) {
16
+ let pos = 0;
17
+ const indentMatch = text.match(/^( {0,3})/);
18
+ if (indentMatch)
19
+ pos += indentMatch[1].length;
20
+ const labelMatch = text.slice(pos).match(LINK_LABEL_REGEX);
21
+ if (!labelMatch)
22
+ return null;
23
+ const rawLabel = labelMatch[1];
24
+ if (rawLabel.trim() === '')
25
+ return null;
26
+ pos += labelMatch[0].length;
27
+ if (text[pos] !== ':')
28
+ return null;
29
+ pos++;
30
+ const beforeDest = text.slice(pos).match(/^[ \t]*\n?[ \t]*/);
31
+ if (beforeDest)
32
+ pos += beforeDest[0].length;
33
+ let destination;
34
+ const angleMatch = text.slice(pos).match(LINK_DESTINATION_ANGLE_REGEX);
35
+ if (angleMatch) {
36
+ destination = angleMatch[0].slice(1, -1);
37
+ pos += angleMatch[0].length;
38
+ }
39
+ else {
40
+ const bareMatch = text.slice(pos).match(LINK_DESTINATION_BARE_REGEX);
41
+ if (!bareMatch || bareMatch[0] === '')
42
+ return null;
43
+ destination = bareMatch[0];
44
+ pos += bareMatch[0].length;
45
+ }
46
+ let title = '';
47
+ let titleFound = false;
48
+ const tryMatchTitle = (titlePos) => {
49
+ const remaining = text.slice(titlePos);
50
+ const doubleMatch = remaining.match(LINK_TITLE_DOUBLE_REGEX);
51
+ const singleMatch = remaining.match(LINK_TITLE_SINGLE_REGEX);
52
+ const parenMatch = remaining.match(LINK_TITLE_PAREN_REGEX);
53
+ const titleMatch = doubleMatch || singleMatch || parenMatch;
54
+ if (titleMatch) {
55
+ const afterTitlePos = titlePos + titleMatch[0].length;
56
+ const afterTitle = text.slice(afterTitlePos).match(/^[ \t]*(?:\n|$)/);
57
+ if (afterTitle) {
58
+ return { title: titleMatch[1], endPos: afterTitlePos + afterTitle[0].length };
59
+ }
60
+ }
61
+ return null;
62
+ };
63
+ const spaceBeforeTitle = text.slice(pos).match(/^[ \t]+/);
64
+ if (spaceBeforeTitle) {
65
+ const result = tryMatchTitle(pos + spaceBeforeTitle[0].length);
66
+ if (result) {
67
+ title = result.title;
68
+ pos = result.endPos;
69
+ titleFound = true;
70
+ }
71
+ }
72
+ if (!titleFound) {
73
+ const newlineBeforeTitle = text.slice(pos).match(/^[ \t]*\n[ \t]*/);
74
+ if (newlineBeforeTitle) {
75
+ const result = tryMatchTitle(pos + newlineBeforeTitle[0].length);
76
+ if (result) {
77
+ title = result.title;
78
+ pos = result.endPos;
79
+ titleFound = true;
80
+ }
81
+ }
82
+ }
83
+ if (!titleFound) {
84
+ const endAfterDest = text.slice(pos).match(/^[ \t]*(?:\n|$)/);
85
+ if (endAfterDest) {
86
+ pos += endAfterDest[0].length;
87
+ return {
88
+ label: (0, utils_js_1.normalizeLabel)((0, utils_js_1.unescapeString)(rawLabel)),
89
+ definition: {
90
+ destination: (0, utils_js_1.decodeHtmlEntities)((0, utils_js_1.unescapeString)(destination)),
91
+ title: '',
92
+ },
93
+ consumed: pos,
94
+ };
95
+ }
96
+ return null;
97
+ }
98
+ return {
99
+ label: (0, utils_js_1.normalizeLabel)((0, utils_js_1.unescapeString)(rawLabel)),
100
+ definition: {
101
+ destination: (0, utils_js_1.decodeHtmlEntities)((0, utils_js_1.unescapeString)(destination)),
102
+ title: (0, utils_js_1.decodeHtmlEntities)((0, utils_js_1.unescapeString)(title)),
103
+ },
104
+ consumed: pos,
105
+ };
106
+ }
107
+ function isLinkReferenceStart(line) {
108
+ return /^ {0,3}\[/.test(line);
109
+ }
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ /**
3
+ * Parser for ordered and unordered lists with nesting and tight/loose detection.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parseListMarker = parseListMarker;
7
+ exports.isListItemStart = isListItemStart;
8
+ exports.isBulletListStart = isBulletListStart;
9
+ exports.isOrderedListStart = isOrderedListStart;
10
+ exports.canStartList = canStartList;
11
+ exports.createListNode = createListNode;
12
+ exports.createListItemNode = createListItemNode;
13
+ exports.listsMatch = listsMatch;
14
+ const BULLET_LIST_REGEX = /^( {0,3})([-+*])( +|\t|$)/;
15
+ const ORDERED_LIST_REGEX = /^( {0,3})(\d{1,9})([.)])( +|\t|$)/;
16
+ function parseListMarker(line) {
17
+ const bulletMatch = line.match(BULLET_LIST_REGEX);
18
+ if (bulletMatch) {
19
+ const indentChars = bulletMatch[1].length;
20
+ const indent = indentChars;
21
+ const marker = bulletMatch[2];
22
+ const spacesAfter = bulletMatch[3];
23
+ let paddingChars = spacesAfter.length;
24
+ const columnAfterMarker = indent + 1;
25
+ let padding;
26
+ if (spacesAfter === '\t') {
27
+ padding = 4 - (columnAfterMarker % 4);
28
+ }
29
+ else if (spacesAfter === '') {
30
+ padding = 1;
31
+ }
32
+ else {
33
+ padding = spacesAfter.length;
34
+ }
35
+ let paddingToConsume = padding;
36
+ if (spacesAfter === '\t') {
37
+ paddingToConsume = 1;
38
+ paddingChars = 1;
39
+ }
40
+ else if (padding >= 5) {
41
+ paddingToConsume = 1;
42
+ paddingChars = 1;
43
+ }
44
+ const contentIndent = indent + 1 + paddingToConsume;
45
+ const contentCharIndex = indentChars + 1 + paddingChars;
46
+ return {
47
+ type: 'bullet',
48
+ indent,
49
+ indentChars,
50
+ marker,
51
+ bulletChar: marker,
52
+ padding: Math.min(paddingToConsume, 4),
53
+ paddingChars,
54
+ contentIndent,
55
+ contentCharIndex,
56
+ };
57
+ }
58
+ const orderedMatch = line.match(ORDERED_LIST_REGEX);
59
+ if (orderedMatch) {
60
+ const indentChars = orderedMatch[1].length;
61
+ const indent = indentChars;
62
+ const start = parseInt(orderedMatch[2], 10);
63
+ const delimiter = orderedMatch[3];
64
+ const marker = orderedMatch[2] + delimiter;
65
+ const spacesAfter = orderedMatch[4];
66
+ let paddingChars = spacesAfter.length;
67
+ const columnAfterMarker = indent + marker.length;
68
+ let padding;
69
+ if (spacesAfter === '\t') {
70
+ padding = 4 - (columnAfterMarker % 4);
71
+ }
72
+ else if (spacesAfter === '') {
73
+ padding = 1;
74
+ }
75
+ else {
76
+ padding = spacesAfter.length;
77
+ }
78
+ let paddingToConsume = padding;
79
+ if (spacesAfter === '\t') {
80
+ paddingToConsume = 1;
81
+ paddingChars = 1;
82
+ }
83
+ else if (padding >= 5) {
84
+ paddingToConsume = 1;
85
+ paddingChars = 1;
86
+ }
87
+ const contentIndent = indent + marker.length + paddingToConsume;
88
+ const contentCharIndex = indentChars + marker.length + paddingChars;
89
+ return {
90
+ type: 'ordered',
91
+ indent,
92
+ indentChars,
93
+ marker,
94
+ start,
95
+ delimiter,
96
+ padding: Math.min(paddingToConsume, 4),
97
+ paddingChars,
98
+ contentIndent,
99
+ contentCharIndex,
100
+ };
101
+ }
102
+ return null;
103
+ }
104
+ function isListItemStart(line) {
105
+ return BULLET_LIST_REGEX.test(line) || ORDERED_LIST_REGEX.test(line);
106
+ }
107
+ function isBulletListStart(line) {
108
+ return BULLET_LIST_REGEX.test(line);
109
+ }
110
+ function isOrderedListStart(line) {
111
+ return ORDERED_LIST_REGEX.test(line);
112
+ }
113
+ function canStartList(line, interruptingParagraph) {
114
+ if (!interruptingParagraph)
115
+ return isListItemStart(line);
116
+ const marker = parseListMarker(line);
117
+ if (!marker)
118
+ return false;
119
+ if (marker.type === 'ordered' && marker.start !== 1) {
120
+ return false;
121
+ }
122
+ const content = line.slice(marker.indent + marker.marker.length + marker.padding);
123
+ if (content.trim() === '') {
124
+ return false;
125
+ }
126
+ return true;
127
+ }
128
+ function createListNode(marker) {
129
+ return {
130
+ type: 'list',
131
+ listType: marker.type,
132
+ start: marker.start ?? 1,
133
+ tight: true,
134
+ delimiter: marker.delimiter ?? null,
135
+ bulletChar: marker.bulletChar ?? null,
136
+ children: [],
137
+ };
138
+ }
139
+ function createListItemNode() {
140
+ return {
141
+ type: 'list_item',
142
+ children: [],
143
+ };
144
+ }
145
+ function listsMatch(a, b) {
146
+ if (a.type !== b.type)
147
+ return false;
148
+ if (a.type === 'bullet' && b.type === 'bullet') {
149
+ return a.bulletChar === b.bulletChar;
150
+ }
151
+ if (a.type === 'ordered' && b.type === 'ordered') {
152
+ return a.delimiter === b.delimiter;
153
+ }
154
+ return false;
155
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ /**
3
+ * Parser for paragraph blocks as the default block type.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createParagraphNode = createParagraphNode;
7
+ exports.isParagraphContinuation = isParagraphContinuation;
8
+ exports.trimParagraphLine = trimParagraphLine;
9
+ function createParagraphNode() {
10
+ return {
11
+ type: 'paragraph',
12
+ children: [],
13
+ };
14
+ }
15
+ function isParagraphContinuation(line) {
16
+ return line.trim() !== '';
17
+ }
18
+ function trimParagraphLine(line) {
19
+ return line.replace(/^ {0,3}/, '').replace(/[ \t]+$/, '');
20
+ }
@@ -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
+ }