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,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Parser for hard line breaks created by backslash-newline or trailing spaces.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parseHardBreak = parseHardBreak;
|
|
7
|
+
exports.isHardBreakStart = isHardBreakStart;
|
|
8
|
+
function parseHardBreak(text, pos) {
|
|
9
|
+
if (text[pos] === '\\' && text[pos + 1] === '\n') {
|
|
10
|
+
return {
|
|
11
|
+
node: { type: 'hardbreak' },
|
|
12
|
+
length: 2,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
if (text[pos] === ' ') {
|
|
16
|
+
let spaces = 0;
|
|
17
|
+
let i = pos;
|
|
18
|
+
while (i < text.length && text[i] === ' ') {
|
|
19
|
+
spaces++;
|
|
20
|
+
i++;
|
|
21
|
+
}
|
|
22
|
+
if (spaces >= 2 && text[i] === '\n') {
|
|
23
|
+
return {
|
|
24
|
+
node: { type: 'hardbreak' },
|
|
25
|
+
length: spaces + 1,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
function isHardBreakStart(text, pos) {
|
|
32
|
+
if (text[pos] === '\\' && text[pos + 1] === '\n')
|
|
33
|
+
return true;
|
|
34
|
+
if (text[pos] === ' ') {
|
|
35
|
+
let i = pos;
|
|
36
|
+
let spaces = 0;
|
|
37
|
+
while (i < text.length && text[i] === ' ') {
|
|
38
|
+
spaces++;
|
|
39
|
+
i++;
|
|
40
|
+
}
|
|
41
|
+
if (spaces >= 2 && text[i] === '\n')
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Image parsing helpers that reuse link logic and create image nodes.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isImageStart = exports.createImageNode = void 0;
|
|
7
|
+
var link_js_1 = require("./link.js");
|
|
8
|
+
Object.defineProperty(exports, "createImageNode", { enumerable: true, get: function () { return link_js_1.createImageNode; } });
|
|
9
|
+
Object.defineProperty(exports, "isImageStart", { enumerable: true, get: function () { return link_js_1.isImageStart; } });
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser for inline links and images, including destinations, titles, and reference labels.
|
|
3
|
+
*/
|
|
4
|
+
import type { LinkNode, ImageNode } from '../types.js';
|
|
5
|
+
export interface LinkMatch {
|
|
6
|
+
type: 'link' | 'image';
|
|
7
|
+
destination: string;
|
|
8
|
+
title: string;
|
|
9
|
+
textStart: number;
|
|
10
|
+
textEnd: number;
|
|
11
|
+
fullEnd: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function parseLinkDestination(text: string): {
|
|
14
|
+
destination: string;
|
|
15
|
+
length: number;
|
|
16
|
+
} | null;
|
|
17
|
+
export declare function parseLinkTitle(text: string): {
|
|
18
|
+
title: string;
|
|
19
|
+
length: number;
|
|
20
|
+
} | null;
|
|
21
|
+
export declare function parseInlineLink(text: string, pos: number): {
|
|
22
|
+
destination: string;
|
|
23
|
+
title: string;
|
|
24
|
+
length: number;
|
|
25
|
+
} | null;
|
|
26
|
+
export declare function parseLinkLabel(text: string, pos: number): {
|
|
27
|
+
label: string;
|
|
28
|
+
length: number;
|
|
29
|
+
} | null;
|
|
30
|
+
export declare function createLinkNode(destination: string, title: string): LinkNode;
|
|
31
|
+
export declare function createImageNode(destination: string, title: string, alt: string): ImageNode;
|
|
32
|
+
export declare function isLinkStart(text: string, pos: number): boolean;
|
|
33
|
+
export declare function isImageStart(text: string, pos: number): boolean;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Parser for inline links and images, including destinations, titles, and reference labels.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parseLinkDestination = parseLinkDestination;
|
|
7
|
+
exports.parseLinkTitle = parseLinkTitle;
|
|
8
|
+
exports.parseInlineLink = parseInlineLink;
|
|
9
|
+
exports.parseLinkLabel = parseLinkLabel;
|
|
10
|
+
exports.createLinkNode = createLinkNode;
|
|
11
|
+
exports.createImageNode = createImageNode;
|
|
12
|
+
exports.isLinkStart = isLinkStart;
|
|
13
|
+
exports.isImageStart = isImageStart;
|
|
14
|
+
const utils_js_1 = require("../utils.js");
|
|
15
|
+
const LINK_DESTINATION_ANGLE_REGEX = /^<([^<>\n\\]|\\.)*>/;
|
|
16
|
+
const LINK_DESTINATION_BARE_REGEX = /^[^\s\x00-\x1f]*?(?:\([^\s\x00-\x1f]*?\)[^\s\x00-\x1f]*?)*[^\s\x00-\x1f)]/;
|
|
17
|
+
const LINK_TITLE_REGEX = /^(?:"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)'|\(([^()\\]*(?:\\.[^()\\]*)*)\))/;
|
|
18
|
+
function parseLinkDestination(text) {
|
|
19
|
+
if (text[0] === '<') {
|
|
20
|
+
const match = text.match(LINK_DESTINATION_ANGLE_REGEX);
|
|
21
|
+
if (match) {
|
|
22
|
+
return {
|
|
23
|
+
destination: (0, utils_js_1.decodeHtmlEntities)((0, utils_js_1.unescapeString)(match[0].slice(1, -1))),
|
|
24
|
+
length: match[0].length,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
let parenDepth = 0;
|
|
30
|
+
let i = 0;
|
|
31
|
+
while (i < text.length) {
|
|
32
|
+
const char = text[i];
|
|
33
|
+
if (char === '\\' && i + 1 < text.length) {
|
|
34
|
+
const nextChar = text[i + 1];
|
|
35
|
+
if (nextChar === ' ' || nextChar === '\t' || nextChar === '\n' || nextChar === '\r') {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
i += 2;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (char === '(') {
|
|
42
|
+
parenDepth++;
|
|
43
|
+
}
|
|
44
|
+
else if (char === ')') {
|
|
45
|
+
if (parenDepth === 0)
|
|
46
|
+
break;
|
|
47
|
+
parenDepth--;
|
|
48
|
+
}
|
|
49
|
+
else if (char === ' ' || char === '\t' || char === '\n' || char === '\r' || char.charCodeAt(0) < 0x20) {
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
i++;
|
|
53
|
+
}
|
|
54
|
+
if (i === 0)
|
|
55
|
+
return null;
|
|
56
|
+
return {
|
|
57
|
+
destination: (0, utils_js_1.decodeHtmlEntities)((0, utils_js_1.unescapeString)(text.slice(0, i))),
|
|
58
|
+
length: i,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function parseLinkTitle(text) {
|
|
62
|
+
const match = text.match(LINK_TITLE_REGEX);
|
|
63
|
+
if (!match)
|
|
64
|
+
return null;
|
|
65
|
+
const title = match[1] ?? match[2] ?? match[3] ?? '';
|
|
66
|
+
return {
|
|
67
|
+
title: (0, utils_js_1.decodeHtmlEntities)((0, utils_js_1.unescapeString)(title)),
|
|
68
|
+
length: match[0].length,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function parseInlineLink(text, pos) {
|
|
72
|
+
if (text[pos] !== '(')
|
|
73
|
+
return null;
|
|
74
|
+
let i = pos + 1;
|
|
75
|
+
while (i < text.length && /[ \t\n]/.test(text[i]))
|
|
76
|
+
i++;
|
|
77
|
+
if (text[i] === ')') {
|
|
78
|
+
return { destination: '', title: '', length: i - pos + 1 };
|
|
79
|
+
}
|
|
80
|
+
const destResult = parseLinkDestination(text.slice(i));
|
|
81
|
+
if (!destResult)
|
|
82
|
+
return null;
|
|
83
|
+
const destination = destResult.destination;
|
|
84
|
+
i += destResult.length;
|
|
85
|
+
while (i < text.length && /[ \t]/.test(text[i]))
|
|
86
|
+
i++;
|
|
87
|
+
let title = '';
|
|
88
|
+
if (text[i] === '\n') {
|
|
89
|
+
i++;
|
|
90
|
+
while (i < text.length && /[ \t]/.test(text[i]))
|
|
91
|
+
i++;
|
|
92
|
+
}
|
|
93
|
+
if (text[i] === '"' || text[i] === "'" || text[i] === '(') {
|
|
94
|
+
const titleResult = parseLinkTitle(text.slice(i));
|
|
95
|
+
if (titleResult) {
|
|
96
|
+
title = titleResult.title;
|
|
97
|
+
i += titleResult.length;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
while (i < text.length && /[ \t\n]/.test(text[i]))
|
|
101
|
+
i++;
|
|
102
|
+
if (text[i] !== ')')
|
|
103
|
+
return null;
|
|
104
|
+
return { destination, title, length: i - pos + 1 };
|
|
105
|
+
}
|
|
106
|
+
function parseLinkLabel(text, pos) {
|
|
107
|
+
if (text[pos] !== '[')
|
|
108
|
+
return null;
|
|
109
|
+
let i = pos + 1;
|
|
110
|
+
let depth = 1;
|
|
111
|
+
let label = '';
|
|
112
|
+
while (i < text.length && depth > 0) {
|
|
113
|
+
const char = text[i];
|
|
114
|
+
if (char === '\\' && i + 1 < text.length) {
|
|
115
|
+
const next = text[i + 1];
|
|
116
|
+
if (next === '[' || next === ']' || next === '\\') {
|
|
117
|
+
label += next;
|
|
118
|
+
i += 2;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
label += '\\';
|
|
122
|
+
i++;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (char === '[') {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
if (char === ']') {
|
|
129
|
+
depth--;
|
|
130
|
+
if (depth === 0)
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
label += char;
|
|
134
|
+
i++;
|
|
135
|
+
}
|
|
136
|
+
if (depth !== 0)
|
|
137
|
+
return null;
|
|
138
|
+
if (label.length > 999)
|
|
139
|
+
return null;
|
|
140
|
+
if (label.trim() === '') {
|
|
141
|
+
return { label: '', length: i - pos + 1 };
|
|
142
|
+
}
|
|
143
|
+
return { label: (0, utils_js_1.normalizeLabel)(label), length: i - pos + 1 };
|
|
144
|
+
}
|
|
145
|
+
function createLinkNode(destination, title) {
|
|
146
|
+
return {
|
|
147
|
+
type: 'link',
|
|
148
|
+
destination,
|
|
149
|
+
title,
|
|
150
|
+
children: [],
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function createImageNode(destination, title, alt) {
|
|
154
|
+
return {
|
|
155
|
+
type: 'image',
|
|
156
|
+
destination,
|
|
157
|
+
title,
|
|
158
|
+
alt,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function isLinkStart(text, pos) {
|
|
162
|
+
return text[pos] === '[';
|
|
163
|
+
}
|
|
164
|
+
function isImageStart(text, pos) {
|
|
165
|
+
return text[pos] === '!' && text[pos + 1] === '[';
|
|
166
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser for soft line breaks created by single newlines.
|
|
3
|
+
*/
|
|
4
|
+
import type { SoftbreakNode } from '../types.js';
|
|
5
|
+
export declare function parseSoftBreak(text: string, pos: number): {
|
|
6
|
+
node: SoftbreakNode;
|
|
7
|
+
length: number;
|
|
8
|
+
} | null;
|
|
9
|
+
export declare function isSoftBreak(text: string, pos: number): boolean;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Parser for soft line breaks created by single newlines.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parseSoftBreak = parseSoftBreak;
|
|
7
|
+
exports.isSoftBreak = isSoftBreak;
|
|
8
|
+
function parseSoftBreak(text, pos) {
|
|
9
|
+
if (text[pos] !== '\n')
|
|
10
|
+
return null;
|
|
11
|
+
return {
|
|
12
|
+
node: { type: 'softbreak' },
|
|
13
|
+
length: 1,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function isSoftBreak(text, pos) {
|
|
17
|
+
return text[pos] === '\n';
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser for GFM strikethrough using ~ delimiters.
|
|
3
|
+
*/
|
|
4
|
+
import type { StrikethroughNode, InlineNode } from '../types.js';
|
|
5
|
+
export interface StrikethroughDelimiter {
|
|
6
|
+
char: '~';
|
|
7
|
+
length: number;
|
|
8
|
+
canOpen: boolean;
|
|
9
|
+
canClose: boolean;
|
|
10
|
+
position: number;
|
|
11
|
+
origLength: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function parseStrikethroughDelimiter(text: string, pos: number): StrikethroughDelimiter | null;
|
|
14
|
+
export declare function isStrikethroughDelimiter(text: string, pos: number): boolean;
|
|
15
|
+
export declare function createStrikethroughNode(children?: InlineNode[]): StrikethroughNode;
|
|
16
|
+
export declare function canStrikethroughDelimitersMatch(opener: StrikethroughDelimiter, closer: StrikethroughDelimiter): boolean;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Parser for GFM strikethrough using ~ delimiters.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parseStrikethroughDelimiter = parseStrikethroughDelimiter;
|
|
7
|
+
exports.isStrikethroughDelimiter = isStrikethroughDelimiter;
|
|
8
|
+
exports.createStrikethroughNode = createStrikethroughNode;
|
|
9
|
+
exports.canStrikethroughDelimitersMatch = canStrikethroughDelimitersMatch;
|
|
10
|
+
function parseStrikethroughDelimiter(text, pos) {
|
|
11
|
+
if (text[pos] !== '~')
|
|
12
|
+
return null;
|
|
13
|
+
let length = 0;
|
|
14
|
+
let i = pos;
|
|
15
|
+
while (i < text.length && text[i] === '~') {
|
|
16
|
+
length++;
|
|
17
|
+
i++;
|
|
18
|
+
}
|
|
19
|
+
if (length > 2)
|
|
20
|
+
return null;
|
|
21
|
+
const charBefore = pos > 0 ? text[pos - 1] : '\n';
|
|
22
|
+
const charAfter = i < text.length ? text[i] : '\n';
|
|
23
|
+
const isWhitespace = (c) => /\s/.test(c) || c === '\n';
|
|
24
|
+
const beforeIsWhitespace = isWhitespace(charBefore);
|
|
25
|
+
const afterIsWhitespace = isWhitespace(charAfter);
|
|
26
|
+
const canOpen = !afterIsWhitespace;
|
|
27
|
+
const canClose = !beforeIsWhitespace;
|
|
28
|
+
return {
|
|
29
|
+
char: '~',
|
|
30
|
+
length,
|
|
31
|
+
canOpen,
|
|
32
|
+
canClose,
|
|
33
|
+
position: pos,
|
|
34
|
+
origLength: length,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function isStrikethroughDelimiter(text, pos) {
|
|
38
|
+
return text[pos] === '~';
|
|
39
|
+
}
|
|
40
|
+
function createStrikethroughNode(children = []) {
|
|
41
|
+
return {
|
|
42
|
+
type: 'strikethrough',
|
|
43
|
+
children,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function canStrikethroughDelimitersMatch(opener, closer) {
|
|
47
|
+
return opener.length === closer.length;
|
|
48
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Text node factories for literal inline content.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createTextNode = createTextNode;
|
|
7
|
+
exports.mergeTextNodes = mergeTextNodes;
|
|
8
|
+
function createTextNode(literal, noDelim = false) {
|
|
9
|
+
return {
|
|
10
|
+
type: 'text',
|
|
11
|
+
literal,
|
|
12
|
+
...(noDelim ? { noDelim: true } : {}),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function mergeTextNodes(nodes) {
|
|
16
|
+
return {
|
|
17
|
+
type: 'text',
|
|
18
|
+
literal: nodes.map(n => n.literal).join(''),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML renderer that converts a Markdown AST into HTML with configurable list, URL safety,
|
|
3
|
+
* and soft-break handling.
|
|
4
|
+
*/
|
|
5
|
+
import type { DocumentNode, RenderOptions } from './types.js';
|
|
6
|
+
export declare class HtmlRenderer {
|
|
7
|
+
private options;
|
|
8
|
+
constructor(options?: RenderOptions);
|
|
9
|
+
render(document: DocumentNode): string;
|
|
10
|
+
private renderBlocks;
|
|
11
|
+
private renderBlock;
|
|
12
|
+
private renderParagraph;
|
|
13
|
+
private renderHeading;
|
|
14
|
+
private renderThematicBreak;
|
|
15
|
+
private renderCodeBlock;
|
|
16
|
+
private renderBlockquote;
|
|
17
|
+
private renderList;
|
|
18
|
+
private renderListItem;
|
|
19
|
+
private renderHtmlBlock;
|
|
20
|
+
private renderInlines;
|
|
21
|
+
private renderInline;
|
|
22
|
+
private renderText;
|
|
23
|
+
private renderSoftbreak;
|
|
24
|
+
private renderHardbreak;
|
|
25
|
+
private renderCodeSpan;
|
|
26
|
+
private renderEmphasis;
|
|
27
|
+
private renderStrong;
|
|
28
|
+
private renderLink;
|
|
29
|
+
private renderImage;
|
|
30
|
+
private renderHtmlInline;
|
|
31
|
+
private renderInlinesSmart;
|
|
32
|
+
private applyDashesAndEllipses;
|
|
33
|
+
}
|