markdown-codec 0.0.0 → 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 +215 -0
- package/dist/ast/ast.cjs +25 -0
- package/dist/ast/ast.d.cts +2 -0
- package/dist/ast/ast.d.ts +2 -0
- package/dist/ast/ast.js +23 -0
- package/dist/ast-BXYwy08e.d.cts +160 -0
- package/dist/ast-BXYwy08e.d.ts +160 -0
- package/dist/block/block.cjs +530 -0
- package/dist/block/block.d.cts +18 -0
- package/dist/block/block.d.ts +18 -0
- package/dist/block/block.js +529 -0
- package/dist/block/definitions.cjs +59 -0
- package/dist/block/definitions.d.cts +6 -0
- package/dist/block/definitions.d.ts +6 -0
- package/dist/block/definitions.js +58 -0
- package/dist/block/line.cjs +76 -0
- package/dist/block/line.d.cts +28 -0
- package/dist/block/line.d.ts +28 -0
- package/dist/block/line.js +74 -0
- package/dist/block/list.cjs +110 -0
- package/dist/block/list.d.cts +8 -0
- package/dist/block/list.d.ts +8 -0
- package/dist/block/list.js +107 -0
- package/dist/block/node.cjs +68 -0
- package/dist/block/node.d.cts +45 -0
- package/dist/block/node.d.ts +45 -0
- package/dist/block/node.js +65 -0
- package/dist/block/table.cjs +64 -0
- package/dist/block/table.d.cts +7 -0
- package/dist/block/table.d.ts +7 -0
- package/dist/block/table.js +61 -0
- package/dist/codec.cjs +22 -0
- package/dist/codec.d.cts +361 -0
- package/dist/codec.d.ts +361 -0
- package/dist/codec.js +20 -0
- package/dist/defaults/defaults.cjs +31 -0
- package/dist/defaults/defaults.d.cts +16 -0
- package/dist/defaults/defaults.d.ts +16 -0
- package/dist/defaults/defaults.js +20 -0
- package/dist/diagnostics/diagnostics.cjs +85 -0
- package/dist/diagnostics/diagnostics.d.cts +2 -0
- package/dist/diagnostics/diagnostics.d.ts +2 -0
- package/dist/diagnostics/diagnostics.js +77 -0
- package/dist/diagnostics-DmuWc7d8.d.cts +61 -0
- package/dist/diagnostics-DmuWc7d8.d.ts +61 -0
- package/dist/emit/emit.cjs +228 -0
- package/dist/emit/emit.d.cts +6 -0
- package/dist/emit/emit.d.ts +6 -0
- package/dist/emit/emit.js +227 -0
- package/dist/emit/front-matter.cjs +24 -0
- package/dist/emit/front-matter.d.cts +5 -0
- package/dist/emit/front-matter.d.ts +5 -0
- package/dist/emit/front-matter.js +23 -0
- package/dist/emit/image.cjs +10 -0
- package/dist/emit/image.d.cts +5 -0
- package/dist/emit/image.d.ts +5 -0
- package/dist/emit/image.js +9 -0
- package/dist/emit/inline.cjs +183 -0
- package/dist/emit/inline.d.cts +12 -0
- package/dist/emit/inline.d.ts +12 -0
- package/dist/emit/inline.js +180 -0
- package/dist/emit/table.cjs +73 -0
- package/dist/emit/table.d.cts +10 -0
- package/dist/emit/table.d.ts +10 -0
- package/dist/emit/table.js +72 -0
- package/dist/html/html.cjs +116 -0
- package/dist/html/html.d.cts +2 -0
- package/dist/html/html.d.ts +2 -0
- package/dist/html/html.js +113 -0
- package/dist/html/render.cjs +193 -0
- package/dist/html/render.d.cts +8 -0
- package/dist/html/render.d.ts +8 -0
- package/dist/html/render.js +189 -0
- package/dist/html-bkz2QTuq.d.cts +7 -0
- package/dist/html-bkz2QTuq.d.ts +7 -0
- package/dist/image/image.cjs +129 -0
- package/dist/image/image.d.cts +2 -0
- package/dist/image/image.d.ts +2 -0
- package/dist/image/image.js +125 -0
- package/dist/image-C4KYmz_L.d.cts +19 -0
- package/dist/image-Cm3hT5PS.d.ts +19 -0
- package/dist/image-DescdRgq.d.cts +12 -0
- package/dist/image-DescdRgq.d.ts +12 -0
- package/dist/index.cjs +17 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +5 -0
- package/dist/inline/chars.cjs +50 -0
- package/dist/inline/chars.d.cts +11 -0
- package/dist/inline/chars.d.ts +11 -0
- package/dist/inline/chars.js +42 -0
- package/dist/inline/delimiter.cjs +136 -0
- package/dist/inline/delimiter.d.cts +29 -0
- package/dist/inline/delimiter.d.ts +29 -0
- package/dist/inline/delimiter.js +132 -0
- package/dist/inline/entity.cjs +67 -0
- package/dist/inline/entity.d.cts +9 -0
- package/dist/inline/entity.d.ts +9 -0
- package/dist/inline/entity.js +65 -0
- package/dist/inline/gfm-autolink.cjs +156 -0
- package/dist/inline/gfm-autolink.d.cts +5 -0
- package/dist/inline/gfm-autolink.d.ts +5 -0
- package/dist/inline/gfm-autolink.js +155 -0
- package/dist/inline/inline.cjs +457 -0
- package/dist/inline/inline.d.cts +2 -0
- package/dist/inline/inline.d.ts +2 -0
- package/dist/inline/inline.js +456 -0
- package/dist/inline/link.cjs +130 -0
- package/dist/inline/link.d.cts +2 -0
- package/dist/inline/link.d.ts +2 -0
- package/dist/inline/link.js +124 -0
- package/dist/inline/node.cjs +57 -0
- package/dist/inline/node.d.cts +23 -0
- package/dist/inline/node.d.ts +23 -0
- package/dist/inline/node.js +55 -0
- package/dist/inline-B50cM6cn.d.ts +10 -0
- package/dist/inline-C9YEGDV5.d.cts +10 -0
- package/dist/link-Dv4kxVjk.d.cts +18 -0
- package/dist/link-Dv4kxVjk.d.ts +18 -0
- package/dist/lower/front-matter.cjs +75 -0
- package/dist/lower/front-matter.d.cts +10 -0
- package/dist/lower/front-matter.d.ts +10 -0
- package/dist/lower/front-matter.js +74 -0
- package/dist/lower/image.cjs +29 -0
- package/dist/lower/image.d.cts +2 -0
- package/dist/lower/image.d.ts +2 -0
- package/dist/lower/image.js +28 -0
- package/dist/lower/inline.cjs +96 -0
- package/dist/lower/inline.d.cts +19 -0
- package/dist/lower/inline.d.ts +19 -0
- package/dist/lower/inline.js +93 -0
- package/dist/lower/lower.cjs +293 -0
- package/dist/lower/lower.d.cts +8 -0
- package/dist/lower/lower.d.ts +8 -0
- package/dist/lower/lower.js +291 -0
- package/dist/lower/table.cjs +27 -0
- package/dist/lower/table.d.cts +7 -0
- package/dist/lower/table.d.ts +7 -0
- package/dist/lower/table.js +26 -0
- package/dist/options/options.cjs +0 -0
- package/dist/options/options.d.cts +43 -0
- package/dist/options/options.d.ts +43 -0
- package/dist/options/options.js +0 -0
- package/dist/read.cjs +20 -0
- package/dist/read.d.cts +11 -0
- package/dist/read.d.ts +11 -0
- package/dist/read.js +19 -0
- package/dist/scan/entity-table.cjs +2131 -0
- package/dist/scan/entity-table.d.cts +4 -0
- package/dist/scan/entity-table.d.ts +4 -0
- package/dist/scan/entity-table.js +2130 -0
- package/dist/scan/scan.cjs +80 -0
- package/dist/scan/scan.d.cts +2 -0
- package/dist/scan/scan.d.ts +2 -0
- package/dist/scan/scan.js +78 -0
- package/dist/scan-DeBxgG-r.d.cts +30 -0
- package/dist/scan-DeBxgG-r.d.ts +30 -0
- package/dist/shared/list-id.cjs +36 -0
- package/dist/shared/list-id.d.cts +22 -0
- package/dist/shared/list-id.d.ts +22 -0
- package/dist/shared/list-id.js +32 -0
- package/dist/shared/style-constants.cjs +34 -0
- package/dist/shared/style-constants.d.cts +14 -0
- package/dist/shared/style-constants.d.ts +14 -0
- package/dist/shared/style-constants.js +23 -0
- package/dist/write.cjs +9 -0
- package/dist/write.d.cts +6 -0
- package/dist/write.d.ts +6 -0
- package/dist/write.js +8 -0
- package/package.json +92 -2
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_scan_scan = require("../scan/scan.cjs");
|
|
3
|
+
//#region src/block/line.ts
|
|
4
|
+
const CODE_INDENT_COLUMNS = 4;
|
|
5
|
+
var LineCursor = class {
|
|
6
|
+
text;
|
|
7
|
+
cursor;
|
|
8
|
+
nextNonspaceMark;
|
|
9
|
+
nextNonspaceColumn = 0;
|
|
10
|
+
lineIsBlank = false;
|
|
11
|
+
constructor(text) {
|
|
12
|
+
this.text = text;
|
|
13
|
+
this.cursor = new require_scan_scan.MarkdownScanCursor(text);
|
|
14
|
+
this.nextNonspaceMark = this.cursor.mark();
|
|
15
|
+
this.findNextNonspace();
|
|
16
|
+
}
|
|
17
|
+
get column() {
|
|
18
|
+
return this.cursor.position.column;
|
|
19
|
+
}
|
|
20
|
+
get indent() {
|
|
21
|
+
return this.nextNonspaceColumn - this.cursor.position.column;
|
|
22
|
+
}
|
|
23
|
+
get indented() {
|
|
24
|
+
return this.indent >= 4;
|
|
25
|
+
}
|
|
26
|
+
get blank() {
|
|
27
|
+
return this.lineIsBlank;
|
|
28
|
+
}
|
|
29
|
+
get atEnd() {
|
|
30
|
+
return this.cursor.atEnd();
|
|
31
|
+
}
|
|
32
|
+
peek() {
|
|
33
|
+
return this.cursor.peek();
|
|
34
|
+
}
|
|
35
|
+
peekNextNonspace() {
|
|
36
|
+
const saved = this.cursor.mark();
|
|
37
|
+
this.cursor.reset(this.nextNonspaceMark);
|
|
38
|
+
const char = this.cursor.peek();
|
|
39
|
+
this.cursor.reset(saved);
|
|
40
|
+
return char;
|
|
41
|
+
}
|
|
42
|
+
findNextNonspace() {
|
|
43
|
+
const saved = this.cursor.mark();
|
|
44
|
+
while (this.cursor.peek() === " ") this.cursor.next();
|
|
45
|
+
this.nextNonspaceMark = this.cursor.mark();
|
|
46
|
+
this.nextNonspaceColumn = this.cursor.position.column;
|
|
47
|
+
this.lineIsBlank = this.cursor.peek() === void 0;
|
|
48
|
+
this.cursor.reset(saved);
|
|
49
|
+
}
|
|
50
|
+
advanceToNextNonspace() {
|
|
51
|
+
this.cursor.reset(this.nextNonspaceMark);
|
|
52
|
+
}
|
|
53
|
+
advance(columns) {
|
|
54
|
+
for (let remaining = columns; remaining > 0; remaining -= 1) if (this.cursor.next() === void 0) return;
|
|
55
|
+
}
|
|
56
|
+
advanceToEndOfLine() {
|
|
57
|
+
while (this.cursor.next() !== void 0);
|
|
58
|
+
}
|
|
59
|
+
rest() {
|
|
60
|
+
const mark = this.cursor.mark();
|
|
61
|
+
if (mark.pendingTabColumns > 0) return " ".repeat(mark.pendingTabColumns) + this.text.slice(mark.rawOffset + 1);
|
|
62
|
+
return this.text.slice(mark.rawOffset);
|
|
63
|
+
}
|
|
64
|
+
restFromNextNonspace() {
|
|
65
|
+
return this.text.slice(this.nextNonspaceMark.rawOffset);
|
|
66
|
+
}
|
|
67
|
+
mark() {
|
|
68
|
+
return this.cursor.mark();
|
|
69
|
+
}
|
|
70
|
+
reset(mark) {
|
|
71
|
+
this.cursor.reset(mark);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
//#endregion
|
|
75
|
+
exports.CODE_INDENT_COLUMNS = CODE_INDENT_COLUMNS;
|
|
76
|
+
exports.LineCursor = LineCursor;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { r as MarkdownScanMark } from "../scan-DeBxgG-r.cjs";
|
|
2
|
+
//#region src/block/line.d.ts
|
|
3
|
+
declare const CODE_INDENT_COLUMNS = 4;
|
|
4
|
+
declare class LineCursor {
|
|
5
|
+
readonly text: string;
|
|
6
|
+
private readonly cursor;
|
|
7
|
+
private nextNonspaceMark;
|
|
8
|
+
private nextNonspaceColumn;
|
|
9
|
+
private lineIsBlank;
|
|
10
|
+
constructor(text: string);
|
|
11
|
+
get column(): number;
|
|
12
|
+
get indent(): number;
|
|
13
|
+
get indented(): boolean;
|
|
14
|
+
get blank(): boolean;
|
|
15
|
+
get atEnd(): boolean;
|
|
16
|
+
peek(): string | undefined;
|
|
17
|
+
peekNextNonspace(): string | undefined;
|
|
18
|
+
findNextNonspace(): void;
|
|
19
|
+
advanceToNextNonspace(): void;
|
|
20
|
+
advance(columns: number): void;
|
|
21
|
+
advanceToEndOfLine(): void;
|
|
22
|
+
rest(): string;
|
|
23
|
+
restFromNextNonspace(): string;
|
|
24
|
+
mark(): MarkdownScanMark;
|
|
25
|
+
reset(mark: MarkdownScanMark): void;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { CODE_INDENT_COLUMNS, LineCursor };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { r as MarkdownScanMark } from "../scan-DeBxgG-r.js";
|
|
2
|
+
//#region src/block/line.d.ts
|
|
3
|
+
declare const CODE_INDENT_COLUMNS = 4;
|
|
4
|
+
declare class LineCursor {
|
|
5
|
+
readonly text: string;
|
|
6
|
+
private readonly cursor;
|
|
7
|
+
private nextNonspaceMark;
|
|
8
|
+
private nextNonspaceColumn;
|
|
9
|
+
private lineIsBlank;
|
|
10
|
+
constructor(text: string);
|
|
11
|
+
get column(): number;
|
|
12
|
+
get indent(): number;
|
|
13
|
+
get indented(): boolean;
|
|
14
|
+
get blank(): boolean;
|
|
15
|
+
get atEnd(): boolean;
|
|
16
|
+
peek(): string | undefined;
|
|
17
|
+
peekNextNonspace(): string | undefined;
|
|
18
|
+
findNextNonspace(): void;
|
|
19
|
+
advanceToNextNonspace(): void;
|
|
20
|
+
advance(columns: number): void;
|
|
21
|
+
advanceToEndOfLine(): void;
|
|
22
|
+
rest(): string;
|
|
23
|
+
restFromNextNonspace(): string;
|
|
24
|
+
mark(): MarkdownScanMark;
|
|
25
|
+
reset(mark: MarkdownScanMark): void;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { CODE_INDENT_COLUMNS, LineCursor };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { MarkdownScanCursor } from "../scan/scan.js";
|
|
2
|
+
//#region src/block/line.ts
|
|
3
|
+
const CODE_INDENT_COLUMNS = 4;
|
|
4
|
+
var LineCursor = class {
|
|
5
|
+
text;
|
|
6
|
+
cursor;
|
|
7
|
+
nextNonspaceMark;
|
|
8
|
+
nextNonspaceColumn = 0;
|
|
9
|
+
lineIsBlank = false;
|
|
10
|
+
constructor(text) {
|
|
11
|
+
this.text = text;
|
|
12
|
+
this.cursor = new MarkdownScanCursor(text);
|
|
13
|
+
this.nextNonspaceMark = this.cursor.mark();
|
|
14
|
+
this.findNextNonspace();
|
|
15
|
+
}
|
|
16
|
+
get column() {
|
|
17
|
+
return this.cursor.position.column;
|
|
18
|
+
}
|
|
19
|
+
get indent() {
|
|
20
|
+
return this.nextNonspaceColumn - this.cursor.position.column;
|
|
21
|
+
}
|
|
22
|
+
get indented() {
|
|
23
|
+
return this.indent >= 4;
|
|
24
|
+
}
|
|
25
|
+
get blank() {
|
|
26
|
+
return this.lineIsBlank;
|
|
27
|
+
}
|
|
28
|
+
get atEnd() {
|
|
29
|
+
return this.cursor.atEnd();
|
|
30
|
+
}
|
|
31
|
+
peek() {
|
|
32
|
+
return this.cursor.peek();
|
|
33
|
+
}
|
|
34
|
+
peekNextNonspace() {
|
|
35
|
+
const saved = this.cursor.mark();
|
|
36
|
+
this.cursor.reset(this.nextNonspaceMark);
|
|
37
|
+
const char = this.cursor.peek();
|
|
38
|
+
this.cursor.reset(saved);
|
|
39
|
+
return char;
|
|
40
|
+
}
|
|
41
|
+
findNextNonspace() {
|
|
42
|
+
const saved = this.cursor.mark();
|
|
43
|
+
while (this.cursor.peek() === " ") this.cursor.next();
|
|
44
|
+
this.nextNonspaceMark = this.cursor.mark();
|
|
45
|
+
this.nextNonspaceColumn = this.cursor.position.column;
|
|
46
|
+
this.lineIsBlank = this.cursor.peek() === void 0;
|
|
47
|
+
this.cursor.reset(saved);
|
|
48
|
+
}
|
|
49
|
+
advanceToNextNonspace() {
|
|
50
|
+
this.cursor.reset(this.nextNonspaceMark);
|
|
51
|
+
}
|
|
52
|
+
advance(columns) {
|
|
53
|
+
for (let remaining = columns; remaining > 0; remaining -= 1) if (this.cursor.next() === void 0) return;
|
|
54
|
+
}
|
|
55
|
+
advanceToEndOfLine() {
|
|
56
|
+
while (this.cursor.next() !== void 0);
|
|
57
|
+
}
|
|
58
|
+
rest() {
|
|
59
|
+
const mark = this.cursor.mark();
|
|
60
|
+
if (mark.pendingTabColumns > 0) return " ".repeat(mark.pendingTabColumns) + this.text.slice(mark.rawOffset + 1);
|
|
61
|
+
return this.text.slice(mark.rawOffset);
|
|
62
|
+
}
|
|
63
|
+
restFromNextNonspace() {
|
|
64
|
+
return this.text.slice(this.nextNonspaceMark.rawOffset);
|
|
65
|
+
}
|
|
66
|
+
mark() {
|
|
67
|
+
return this.cursor.mark();
|
|
68
|
+
}
|
|
69
|
+
reset(mark) {
|
|
70
|
+
this.cursor.reset(mark);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
//#endregion
|
|
74
|
+
export { CODE_INDENT_COLUMNS, LineCursor };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("./line.cjs");
|
|
3
|
+
//#region src/block/list.ts
|
|
4
|
+
const BULLET_MARKER_PATTERN = /^[*+-]/;
|
|
5
|
+
const ORDERED_MARKER_PATTERN = /^(\d{1,9})([.)])/;
|
|
6
|
+
const NON_SPACE_PATTERN = /[^ \t\f\v\r\n]/;
|
|
7
|
+
const INTERRUPTING_ORDERED_START = 1;
|
|
8
|
+
function isBulletMarker(char) {
|
|
9
|
+
return char === "-" || char === "*" || char === "+";
|
|
10
|
+
}
|
|
11
|
+
function isOrderedDelimiter(char) {
|
|
12
|
+
return char === "." || char === ")";
|
|
13
|
+
}
|
|
14
|
+
function matchMarker(rest, indent, containerIsParagraph) {
|
|
15
|
+
const bullet = BULLET_MARKER_PATTERN.exec(rest);
|
|
16
|
+
if (bullet !== null) {
|
|
17
|
+
const char = bullet[0];
|
|
18
|
+
if (!isBulletMarker(char)) return;
|
|
19
|
+
return {
|
|
20
|
+
length: bullet[0].length,
|
|
21
|
+
data: {
|
|
22
|
+
type: "bullet",
|
|
23
|
+
bulletChar: char,
|
|
24
|
+
markerOffset: indent
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const ordered = ORDERED_MARKER_PATTERN.exec(rest);
|
|
29
|
+
const digits = ordered?.[1];
|
|
30
|
+
const delimiter = ordered?.[2];
|
|
31
|
+
if (ordered === null || digits === void 0 || delimiter === void 0 || !isOrderedDelimiter(delimiter)) return;
|
|
32
|
+
const start = Number.parseInt(digits, 10);
|
|
33
|
+
if (containerIsParagraph && start !== INTERRUPTING_ORDERED_START) return;
|
|
34
|
+
return {
|
|
35
|
+
length: ordered[0].length,
|
|
36
|
+
data: {
|
|
37
|
+
type: "ordered",
|
|
38
|
+
delimiter,
|
|
39
|
+
start,
|
|
40
|
+
markerOffset: indent
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function parseListMarker(line, containerIsParagraph) {
|
|
45
|
+
if (line.indented) return;
|
|
46
|
+
const rest = line.restFromNextNonspace();
|
|
47
|
+
const match = matchMarker(rest, line.indent, containerIsParagraph);
|
|
48
|
+
if (match === void 0) return;
|
|
49
|
+
const afterMarker = rest.charAt(match.length);
|
|
50
|
+
if (afterMarker !== "" && afterMarker !== " " && afterMarker !== " ") return;
|
|
51
|
+
if (containerIsParagraph && !NON_SPACE_PATTERN.test(rest.slice(match.length))) return;
|
|
52
|
+
line.advanceToNextNonspace();
|
|
53
|
+
line.advance(match.length);
|
|
54
|
+
const afterMarkerMark = line.mark();
|
|
55
|
+
const afterMarkerColumn = line.column;
|
|
56
|
+
do
|
|
57
|
+
line.advance(1);
|
|
58
|
+
while (line.column - afterMarkerColumn <= 4 && line.peek() === " ");
|
|
59
|
+
const followingSpaces = line.column - afterMarkerColumn;
|
|
60
|
+
const startsBlank = line.atEnd;
|
|
61
|
+
if (followingSpaces > 4 || followingSpaces < 1 || startsBlank) {
|
|
62
|
+
line.reset(afterMarkerMark);
|
|
63
|
+
if (line.peek() === " ") line.advance(1);
|
|
64
|
+
return {
|
|
65
|
+
...match.data,
|
|
66
|
+
padding: match.length + 1
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
...match.data,
|
|
71
|
+
padding: match.length + followingSpaces
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function listsMatch(a, b) {
|
|
75
|
+
return a.type === b.type && a.delimiter === b.delimiter && a.bulletChar === b.bulletChar;
|
|
76
|
+
}
|
|
77
|
+
function endsWithBlankLine(block) {
|
|
78
|
+
let current = block;
|
|
79
|
+
while (current !== void 0) {
|
|
80
|
+
if (current.lastLineBlank) return true;
|
|
81
|
+
if (!current.lastLineChecked && (current.kind === "list" || current.kind === "listItem")) {
|
|
82
|
+
current.lastLineChecked = true;
|
|
83
|
+
current = current.lastChild;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
current.lastLineChecked = true;
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
function finalizeListTightness(list) {
|
|
92
|
+
for (const [index, item] of list.children.entries()) {
|
|
93
|
+
const hasFollowingItem = index < list.children.length - 1;
|
|
94
|
+
if (hasFollowingItem && endsWithBlankLine(item)) {
|
|
95
|
+
list.tight = false;
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
for (const [childIndex, child] of item.children.entries()) {
|
|
99
|
+
const hasFollowingBlock = childIndex < item.children.length - 1;
|
|
100
|
+
if ((hasFollowingItem || hasFollowingBlock) && endsWithBlankLine(child)) {
|
|
101
|
+
list.tight = false;
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
exports.finalizeListTightness = finalizeListTightness;
|
|
109
|
+
exports.listsMatch = listsMatch;
|
|
110
|
+
exports.parseListMarker = parseListMarker;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LineCursor } from "./line.cjs";
|
|
2
|
+
import { BlockNode, ListMarkerData } from "./node.cjs";
|
|
3
|
+
//#region src/block/list.d.ts
|
|
4
|
+
declare function parseListMarker(line: LineCursor, containerIsParagraph: boolean): ListMarkerData | undefined;
|
|
5
|
+
declare function listsMatch(a: ListMarkerData, b: ListMarkerData): boolean;
|
|
6
|
+
declare function finalizeListTightness(list: BlockNode): void;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { finalizeListTightness, listsMatch, parseListMarker };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LineCursor } from "./line.js";
|
|
2
|
+
import { BlockNode, ListMarkerData } from "./node.js";
|
|
3
|
+
//#region src/block/list.d.ts
|
|
4
|
+
declare function parseListMarker(line: LineCursor, containerIsParagraph: boolean): ListMarkerData | undefined;
|
|
5
|
+
declare function listsMatch(a: ListMarkerData, b: ListMarkerData): boolean;
|
|
6
|
+
declare function finalizeListTightness(list: BlockNode): void;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { finalizeListTightness, listsMatch, parseListMarker };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import "./line.js";
|
|
2
|
+
//#region src/block/list.ts
|
|
3
|
+
const BULLET_MARKER_PATTERN = /^[*+-]/;
|
|
4
|
+
const ORDERED_MARKER_PATTERN = /^(\d{1,9})([.)])/;
|
|
5
|
+
const NON_SPACE_PATTERN = /[^ \t\f\v\r\n]/;
|
|
6
|
+
const INTERRUPTING_ORDERED_START = 1;
|
|
7
|
+
function isBulletMarker(char) {
|
|
8
|
+
return char === "-" || char === "*" || char === "+";
|
|
9
|
+
}
|
|
10
|
+
function isOrderedDelimiter(char) {
|
|
11
|
+
return char === "." || char === ")";
|
|
12
|
+
}
|
|
13
|
+
function matchMarker(rest, indent, containerIsParagraph) {
|
|
14
|
+
const bullet = BULLET_MARKER_PATTERN.exec(rest);
|
|
15
|
+
if (bullet !== null) {
|
|
16
|
+
const char = bullet[0];
|
|
17
|
+
if (!isBulletMarker(char)) return;
|
|
18
|
+
return {
|
|
19
|
+
length: bullet[0].length,
|
|
20
|
+
data: {
|
|
21
|
+
type: "bullet",
|
|
22
|
+
bulletChar: char,
|
|
23
|
+
markerOffset: indent
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const ordered = ORDERED_MARKER_PATTERN.exec(rest);
|
|
28
|
+
const digits = ordered?.[1];
|
|
29
|
+
const delimiter = ordered?.[2];
|
|
30
|
+
if (ordered === null || digits === void 0 || delimiter === void 0 || !isOrderedDelimiter(delimiter)) return;
|
|
31
|
+
const start = Number.parseInt(digits, 10);
|
|
32
|
+
if (containerIsParagraph && start !== INTERRUPTING_ORDERED_START) return;
|
|
33
|
+
return {
|
|
34
|
+
length: ordered[0].length,
|
|
35
|
+
data: {
|
|
36
|
+
type: "ordered",
|
|
37
|
+
delimiter,
|
|
38
|
+
start,
|
|
39
|
+
markerOffset: indent
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function parseListMarker(line, containerIsParagraph) {
|
|
44
|
+
if (line.indented) return;
|
|
45
|
+
const rest = line.restFromNextNonspace();
|
|
46
|
+
const match = matchMarker(rest, line.indent, containerIsParagraph);
|
|
47
|
+
if (match === void 0) return;
|
|
48
|
+
const afterMarker = rest.charAt(match.length);
|
|
49
|
+
if (afterMarker !== "" && afterMarker !== " " && afterMarker !== " ") return;
|
|
50
|
+
if (containerIsParagraph && !NON_SPACE_PATTERN.test(rest.slice(match.length))) return;
|
|
51
|
+
line.advanceToNextNonspace();
|
|
52
|
+
line.advance(match.length);
|
|
53
|
+
const afterMarkerMark = line.mark();
|
|
54
|
+
const afterMarkerColumn = line.column;
|
|
55
|
+
do
|
|
56
|
+
line.advance(1);
|
|
57
|
+
while (line.column - afterMarkerColumn <= 4 && line.peek() === " ");
|
|
58
|
+
const followingSpaces = line.column - afterMarkerColumn;
|
|
59
|
+
const startsBlank = line.atEnd;
|
|
60
|
+
if (followingSpaces > 4 || followingSpaces < 1 || startsBlank) {
|
|
61
|
+
line.reset(afterMarkerMark);
|
|
62
|
+
if (line.peek() === " ") line.advance(1);
|
|
63
|
+
return {
|
|
64
|
+
...match.data,
|
|
65
|
+
padding: match.length + 1
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
...match.data,
|
|
70
|
+
padding: match.length + followingSpaces
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function listsMatch(a, b) {
|
|
74
|
+
return a.type === b.type && a.delimiter === b.delimiter && a.bulletChar === b.bulletChar;
|
|
75
|
+
}
|
|
76
|
+
function endsWithBlankLine(block) {
|
|
77
|
+
let current = block;
|
|
78
|
+
while (current !== void 0) {
|
|
79
|
+
if (current.lastLineBlank) return true;
|
|
80
|
+
if (!current.lastLineChecked && (current.kind === "list" || current.kind === "listItem")) {
|
|
81
|
+
current.lastLineChecked = true;
|
|
82
|
+
current = current.lastChild;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
current.lastLineChecked = true;
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
function finalizeListTightness(list) {
|
|
91
|
+
for (const [index, item] of list.children.entries()) {
|
|
92
|
+
const hasFollowingItem = index < list.children.length - 1;
|
|
93
|
+
if (hasFollowingItem && endsWithBlankLine(item)) {
|
|
94
|
+
list.tight = false;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
for (const [childIndex, child] of item.children.entries()) {
|
|
98
|
+
const hasFollowingBlock = childIndex < item.children.length - 1;
|
|
99
|
+
if ((hasFollowingItem || hasFollowingBlock) && endsWithBlankLine(child)) {
|
|
100
|
+
list.tight = false;
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
export { finalizeListTightness, listsMatch, parseListMarker };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/block/node.ts
|
|
3
|
+
var BlockNode = class {
|
|
4
|
+
kind;
|
|
5
|
+
parent;
|
|
6
|
+
children = [];
|
|
7
|
+
open = true;
|
|
8
|
+
startLine = 0;
|
|
9
|
+
content = "";
|
|
10
|
+
lastLineBlank = false;
|
|
11
|
+
lastLineChecked = false;
|
|
12
|
+
level = 1;
|
|
13
|
+
setext = false;
|
|
14
|
+
fenced = false;
|
|
15
|
+
fenceChar = "`";
|
|
16
|
+
fenceLength = 0;
|
|
17
|
+
fenceOffset = 0;
|
|
18
|
+
infoString = "";
|
|
19
|
+
literal = "";
|
|
20
|
+
htmlBlockType = 1;
|
|
21
|
+
listData;
|
|
22
|
+
tight = true;
|
|
23
|
+
alignments = [];
|
|
24
|
+
headerLine = "";
|
|
25
|
+
constructor(kind, startLine) {
|
|
26
|
+
this.kind = kind;
|
|
27
|
+
this.startLine = startLine;
|
|
28
|
+
}
|
|
29
|
+
get lastChild() {
|
|
30
|
+
return this.children.at(-1);
|
|
31
|
+
}
|
|
32
|
+
appendChild(child) {
|
|
33
|
+
child.parent = this;
|
|
34
|
+
this.children.push(child);
|
|
35
|
+
}
|
|
36
|
+
replaceWith(replacement) {
|
|
37
|
+
const parent = this.parent;
|
|
38
|
+
if (parent === void 0) return;
|
|
39
|
+
const index = parent.children.indexOf(this);
|
|
40
|
+
if (index === -1) return;
|
|
41
|
+
parent.children[index] = replacement;
|
|
42
|
+
replacement.parent = parent;
|
|
43
|
+
this.parent = void 0;
|
|
44
|
+
}
|
|
45
|
+
unlink() {
|
|
46
|
+
const parent = this.parent;
|
|
47
|
+
if (parent === void 0) return;
|
|
48
|
+
const index = parent.children.indexOf(this);
|
|
49
|
+
if (index !== -1) parent.children.splice(index, 1);
|
|
50
|
+
this.parent = void 0;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
function canContain(parent, child) {
|
|
54
|
+
switch (parent) {
|
|
55
|
+
case "document":
|
|
56
|
+
case "blockquote":
|
|
57
|
+
case "listItem": return child !== "listItem";
|
|
58
|
+
case "list": return child === "listItem";
|
|
59
|
+
default: return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function acceptsLines(kind) {
|
|
63
|
+
return kind === "paragraph" || kind === "codeBlock" || kind === "htmlBlock" || kind === "table";
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
exports.BlockNode = BlockNode;
|
|
67
|
+
exports.acceptsLines = acceptsLines;
|
|
68
|
+
exports.canContain = canContain;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { S as MarkdownOrderedListDelimiter, i as MarkdownBulletMarker, k as MarkdownTableAlignment } from "../ast-BXYwy08e.cjs";
|
|
2
|
+
import { t as HtmlBlockType } from "../html-bkz2QTuq.cjs";
|
|
3
|
+
//#region src/block/node.d.ts
|
|
4
|
+
type BlockNodeKind = 'document' | 'paragraph' | 'heading' | 'blockquote' | 'list' | 'listItem' | 'codeBlock' | 'htmlBlock' | 'thematicBreak' | 'table';
|
|
5
|
+
type BlockHeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
6
|
+
interface ListMarkerData {
|
|
7
|
+
readonly type: 'bullet' | 'ordered';
|
|
8
|
+
readonly bulletChar?: MarkdownBulletMarker;
|
|
9
|
+
readonly delimiter?: MarkdownOrderedListDelimiter;
|
|
10
|
+
readonly start?: number;
|
|
11
|
+
readonly padding: number;
|
|
12
|
+
readonly markerOffset: number;
|
|
13
|
+
}
|
|
14
|
+
declare class BlockNode {
|
|
15
|
+
readonly kind: BlockNodeKind;
|
|
16
|
+
parent: BlockNode | undefined;
|
|
17
|
+
readonly children: BlockNode[];
|
|
18
|
+
open: boolean;
|
|
19
|
+
startLine: number;
|
|
20
|
+
content: string;
|
|
21
|
+
lastLineBlank: boolean;
|
|
22
|
+
lastLineChecked: boolean;
|
|
23
|
+
level: BlockHeadingLevel;
|
|
24
|
+
setext: boolean;
|
|
25
|
+
fenced: boolean;
|
|
26
|
+
fenceChar: '`' | '~';
|
|
27
|
+
fenceLength: number;
|
|
28
|
+
fenceOffset: number;
|
|
29
|
+
infoString: string;
|
|
30
|
+
literal: string;
|
|
31
|
+
htmlBlockType: HtmlBlockType;
|
|
32
|
+
listData: ListMarkerData | undefined;
|
|
33
|
+
tight: boolean;
|
|
34
|
+
alignments: MarkdownTableAlignment[];
|
|
35
|
+
headerLine: string;
|
|
36
|
+
constructor(kind: BlockNodeKind, startLine: number);
|
|
37
|
+
get lastChild(): BlockNode | undefined;
|
|
38
|
+
appendChild(child: BlockNode): void;
|
|
39
|
+
replaceWith(replacement: BlockNode): void;
|
|
40
|
+
unlink(): void;
|
|
41
|
+
}
|
|
42
|
+
declare function canContain(parent: BlockNodeKind, child: BlockNodeKind): boolean;
|
|
43
|
+
declare function acceptsLines(kind: BlockNodeKind): boolean;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { BlockHeadingLevel, BlockNode, BlockNodeKind, ListMarkerData, acceptsLines, canContain };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { S as MarkdownOrderedListDelimiter, i as MarkdownBulletMarker, k as MarkdownTableAlignment } from "../ast-BXYwy08e.js";
|
|
2
|
+
import { t as HtmlBlockType } from "../html-bkz2QTuq.js";
|
|
3
|
+
//#region src/block/node.d.ts
|
|
4
|
+
type BlockNodeKind = 'document' | 'paragraph' | 'heading' | 'blockquote' | 'list' | 'listItem' | 'codeBlock' | 'htmlBlock' | 'thematicBreak' | 'table';
|
|
5
|
+
type BlockHeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
6
|
+
interface ListMarkerData {
|
|
7
|
+
readonly type: 'bullet' | 'ordered';
|
|
8
|
+
readonly bulletChar?: MarkdownBulletMarker;
|
|
9
|
+
readonly delimiter?: MarkdownOrderedListDelimiter;
|
|
10
|
+
readonly start?: number;
|
|
11
|
+
readonly padding: number;
|
|
12
|
+
readonly markerOffset: number;
|
|
13
|
+
}
|
|
14
|
+
declare class BlockNode {
|
|
15
|
+
readonly kind: BlockNodeKind;
|
|
16
|
+
parent: BlockNode | undefined;
|
|
17
|
+
readonly children: BlockNode[];
|
|
18
|
+
open: boolean;
|
|
19
|
+
startLine: number;
|
|
20
|
+
content: string;
|
|
21
|
+
lastLineBlank: boolean;
|
|
22
|
+
lastLineChecked: boolean;
|
|
23
|
+
level: BlockHeadingLevel;
|
|
24
|
+
setext: boolean;
|
|
25
|
+
fenced: boolean;
|
|
26
|
+
fenceChar: '`' | '~';
|
|
27
|
+
fenceLength: number;
|
|
28
|
+
fenceOffset: number;
|
|
29
|
+
infoString: string;
|
|
30
|
+
literal: string;
|
|
31
|
+
htmlBlockType: HtmlBlockType;
|
|
32
|
+
listData: ListMarkerData | undefined;
|
|
33
|
+
tight: boolean;
|
|
34
|
+
alignments: MarkdownTableAlignment[];
|
|
35
|
+
headerLine: string;
|
|
36
|
+
constructor(kind: BlockNodeKind, startLine: number);
|
|
37
|
+
get lastChild(): BlockNode | undefined;
|
|
38
|
+
appendChild(child: BlockNode): void;
|
|
39
|
+
replaceWith(replacement: BlockNode): void;
|
|
40
|
+
unlink(): void;
|
|
41
|
+
}
|
|
42
|
+
declare function canContain(parent: BlockNodeKind, child: BlockNodeKind): boolean;
|
|
43
|
+
declare function acceptsLines(kind: BlockNodeKind): boolean;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { BlockHeadingLevel, BlockNode, BlockNodeKind, ListMarkerData, acceptsLines, canContain };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
//#region src/block/node.ts
|
|
2
|
+
var BlockNode = class {
|
|
3
|
+
kind;
|
|
4
|
+
parent;
|
|
5
|
+
children = [];
|
|
6
|
+
open = true;
|
|
7
|
+
startLine = 0;
|
|
8
|
+
content = "";
|
|
9
|
+
lastLineBlank = false;
|
|
10
|
+
lastLineChecked = false;
|
|
11
|
+
level = 1;
|
|
12
|
+
setext = false;
|
|
13
|
+
fenced = false;
|
|
14
|
+
fenceChar = "`";
|
|
15
|
+
fenceLength = 0;
|
|
16
|
+
fenceOffset = 0;
|
|
17
|
+
infoString = "";
|
|
18
|
+
literal = "";
|
|
19
|
+
htmlBlockType = 1;
|
|
20
|
+
listData;
|
|
21
|
+
tight = true;
|
|
22
|
+
alignments = [];
|
|
23
|
+
headerLine = "";
|
|
24
|
+
constructor(kind, startLine) {
|
|
25
|
+
this.kind = kind;
|
|
26
|
+
this.startLine = startLine;
|
|
27
|
+
}
|
|
28
|
+
get lastChild() {
|
|
29
|
+
return this.children.at(-1);
|
|
30
|
+
}
|
|
31
|
+
appendChild(child) {
|
|
32
|
+
child.parent = this;
|
|
33
|
+
this.children.push(child);
|
|
34
|
+
}
|
|
35
|
+
replaceWith(replacement) {
|
|
36
|
+
const parent = this.parent;
|
|
37
|
+
if (parent === void 0) return;
|
|
38
|
+
const index = parent.children.indexOf(this);
|
|
39
|
+
if (index === -1) return;
|
|
40
|
+
parent.children[index] = replacement;
|
|
41
|
+
replacement.parent = parent;
|
|
42
|
+
this.parent = void 0;
|
|
43
|
+
}
|
|
44
|
+
unlink() {
|
|
45
|
+
const parent = this.parent;
|
|
46
|
+
if (parent === void 0) return;
|
|
47
|
+
const index = parent.children.indexOf(this);
|
|
48
|
+
if (index !== -1) parent.children.splice(index, 1);
|
|
49
|
+
this.parent = void 0;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
function canContain(parent, child) {
|
|
53
|
+
switch (parent) {
|
|
54
|
+
case "document":
|
|
55
|
+
case "blockquote":
|
|
56
|
+
case "listItem": return child !== "listItem";
|
|
57
|
+
case "list": return child === "listItem";
|
|
58
|
+
default: return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function acceptsLines(kind) {
|
|
62
|
+
return kind === "paragraph" || kind === "codeBlock" || kind === "htmlBlock" || kind === "table";
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
export { BlockNode, acceptsLines, canContain };
|