markdown-codec 0.0.0 → 1.0.1
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 +492 -0
- package/dist/codec.d.ts +492 -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,80 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/scan/scan.ts
|
|
3
|
+
const MARKDOWN_TAB_STOP_WIDTH = 4;
|
|
4
|
+
var MarkdownScanCursor = class {
|
|
5
|
+
source;
|
|
6
|
+
rawOffset = 0;
|
|
7
|
+
lineNumber = 1;
|
|
8
|
+
columnNumber = 0;
|
|
9
|
+
pendingTabColumns = 0;
|
|
10
|
+
constructor(source) {
|
|
11
|
+
this.source = source;
|
|
12
|
+
}
|
|
13
|
+
get position() {
|
|
14
|
+
return {
|
|
15
|
+
offset: this.rawOffset,
|
|
16
|
+
line: this.lineNumber,
|
|
17
|
+
column: this.columnNumber
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
atEnd() {
|
|
21
|
+
return this.pendingTabColumns === 0 && this.rawOffset >= this.source.length;
|
|
22
|
+
}
|
|
23
|
+
peek() {
|
|
24
|
+
if (this.pendingTabColumns > 0) return " ";
|
|
25
|
+
if (this.rawOffset >= this.source.length) return;
|
|
26
|
+
const char = this.source[this.rawOffset];
|
|
27
|
+
if (char === " ") return " ";
|
|
28
|
+
if (char === "\r") return "\n";
|
|
29
|
+
return char;
|
|
30
|
+
}
|
|
31
|
+
peekRaw(count) {
|
|
32
|
+
return this.source.slice(this.rawOffset, this.rawOffset + count);
|
|
33
|
+
}
|
|
34
|
+
next() {
|
|
35
|
+
if (this.pendingTabColumns > 0) {
|
|
36
|
+
this.pendingTabColumns -= 1;
|
|
37
|
+
this.columnNumber += 1;
|
|
38
|
+
if (this.pendingTabColumns === 0) this.rawOffset += 1;
|
|
39
|
+
return " ";
|
|
40
|
+
}
|
|
41
|
+
if (this.rawOffset >= this.source.length) return;
|
|
42
|
+
const char = this.source[this.rawOffset];
|
|
43
|
+
if (char === " ") {
|
|
44
|
+
const width = 4 - this.columnNumber % 4;
|
|
45
|
+
this.columnNumber += 1;
|
|
46
|
+
if (width > 1) this.pendingTabColumns = width - 1;
|
|
47
|
+
else this.rawOffset += 1;
|
|
48
|
+
return " ";
|
|
49
|
+
}
|
|
50
|
+
if (char === "\r") {
|
|
51
|
+
this.rawOffset += this.source[this.rawOffset + 1] === "\n" ? 2 : 1;
|
|
52
|
+
this.lineNumber += 1;
|
|
53
|
+
this.columnNumber = 0;
|
|
54
|
+
return "\n";
|
|
55
|
+
}
|
|
56
|
+
this.rawOffset += 1;
|
|
57
|
+
if (char === "\n") {
|
|
58
|
+
this.lineNumber += 1;
|
|
59
|
+
this.columnNumber = 0;
|
|
60
|
+
} else this.columnNumber += 1;
|
|
61
|
+
return char;
|
|
62
|
+
}
|
|
63
|
+
mark() {
|
|
64
|
+
return {
|
|
65
|
+
rawOffset: this.rawOffset,
|
|
66
|
+
lineNumber: this.lineNumber,
|
|
67
|
+
columnNumber: this.columnNumber,
|
|
68
|
+
pendingTabColumns: this.pendingTabColumns
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
reset(mark) {
|
|
72
|
+
this.rawOffset = mark.rawOffset;
|
|
73
|
+
this.lineNumber = mark.lineNumber;
|
|
74
|
+
this.columnNumber = mark.columnNumber;
|
|
75
|
+
this.pendingTabColumns = mark.pendingTabColumns;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
//#endregion
|
|
79
|
+
exports.MARKDOWN_TAB_STOP_WIDTH = MARKDOWN_TAB_STOP_WIDTH;
|
|
80
|
+
exports.MarkdownScanCursor = MarkdownScanCursor;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
//#region src/scan/scan.ts
|
|
2
|
+
const MARKDOWN_TAB_STOP_WIDTH = 4;
|
|
3
|
+
var MarkdownScanCursor = class {
|
|
4
|
+
source;
|
|
5
|
+
rawOffset = 0;
|
|
6
|
+
lineNumber = 1;
|
|
7
|
+
columnNumber = 0;
|
|
8
|
+
pendingTabColumns = 0;
|
|
9
|
+
constructor(source) {
|
|
10
|
+
this.source = source;
|
|
11
|
+
}
|
|
12
|
+
get position() {
|
|
13
|
+
return {
|
|
14
|
+
offset: this.rawOffset,
|
|
15
|
+
line: this.lineNumber,
|
|
16
|
+
column: this.columnNumber
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
atEnd() {
|
|
20
|
+
return this.pendingTabColumns === 0 && this.rawOffset >= this.source.length;
|
|
21
|
+
}
|
|
22
|
+
peek() {
|
|
23
|
+
if (this.pendingTabColumns > 0) return " ";
|
|
24
|
+
if (this.rawOffset >= this.source.length) return;
|
|
25
|
+
const char = this.source[this.rawOffset];
|
|
26
|
+
if (char === " ") return " ";
|
|
27
|
+
if (char === "\r") return "\n";
|
|
28
|
+
return char;
|
|
29
|
+
}
|
|
30
|
+
peekRaw(count) {
|
|
31
|
+
return this.source.slice(this.rawOffset, this.rawOffset + count);
|
|
32
|
+
}
|
|
33
|
+
next() {
|
|
34
|
+
if (this.pendingTabColumns > 0) {
|
|
35
|
+
this.pendingTabColumns -= 1;
|
|
36
|
+
this.columnNumber += 1;
|
|
37
|
+
if (this.pendingTabColumns === 0) this.rawOffset += 1;
|
|
38
|
+
return " ";
|
|
39
|
+
}
|
|
40
|
+
if (this.rawOffset >= this.source.length) return;
|
|
41
|
+
const char = this.source[this.rawOffset];
|
|
42
|
+
if (char === " ") {
|
|
43
|
+
const width = 4 - this.columnNumber % 4;
|
|
44
|
+
this.columnNumber += 1;
|
|
45
|
+
if (width > 1) this.pendingTabColumns = width - 1;
|
|
46
|
+
else this.rawOffset += 1;
|
|
47
|
+
return " ";
|
|
48
|
+
}
|
|
49
|
+
if (char === "\r") {
|
|
50
|
+
this.rawOffset += this.source[this.rawOffset + 1] === "\n" ? 2 : 1;
|
|
51
|
+
this.lineNumber += 1;
|
|
52
|
+
this.columnNumber = 0;
|
|
53
|
+
return "\n";
|
|
54
|
+
}
|
|
55
|
+
this.rawOffset += 1;
|
|
56
|
+
if (char === "\n") {
|
|
57
|
+
this.lineNumber += 1;
|
|
58
|
+
this.columnNumber = 0;
|
|
59
|
+
} else this.columnNumber += 1;
|
|
60
|
+
return char;
|
|
61
|
+
}
|
|
62
|
+
mark() {
|
|
63
|
+
return {
|
|
64
|
+
rawOffset: this.rawOffset,
|
|
65
|
+
lineNumber: this.lineNumber,
|
|
66
|
+
columnNumber: this.columnNumber,
|
|
67
|
+
pendingTabColumns: this.pendingTabColumns
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
reset(mark) {
|
|
71
|
+
this.rawOffset = mark.rawOffset;
|
|
72
|
+
this.lineNumber = mark.lineNumber;
|
|
73
|
+
this.columnNumber = mark.columnNumber;
|
|
74
|
+
this.pendingTabColumns = mark.pendingTabColumns;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
//#endregion
|
|
78
|
+
export { MARKDOWN_TAB_STOP_WIDTH, MarkdownScanCursor };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/scan/scan.d.ts
|
|
2
|
+
declare const MARKDOWN_TAB_STOP_WIDTH = 4;
|
|
3
|
+
interface ScanPosition {
|
|
4
|
+
readonly offset: number;
|
|
5
|
+
readonly line: number;
|
|
6
|
+
readonly column: number;
|
|
7
|
+
}
|
|
8
|
+
interface MarkdownScanMark {
|
|
9
|
+
readonly rawOffset: number;
|
|
10
|
+
readonly lineNumber: number;
|
|
11
|
+
readonly columnNumber: number;
|
|
12
|
+
readonly pendingTabColumns: number;
|
|
13
|
+
}
|
|
14
|
+
declare class MarkdownScanCursor {
|
|
15
|
+
private readonly source;
|
|
16
|
+
private rawOffset;
|
|
17
|
+
private lineNumber;
|
|
18
|
+
private columnNumber;
|
|
19
|
+
private pendingTabColumns;
|
|
20
|
+
constructor(source: string);
|
|
21
|
+
get position(): ScanPosition;
|
|
22
|
+
atEnd(): boolean;
|
|
23
|
+
peek(): string | undefined;
|
|
24
|
+
peekRaw(count: number): string;
|
|
25
|
+
next(): string | undefined;
|
|
26
|
+
mark(): MarkdownScanMark;
|
|
27
|
+
reset(mark: MarkdownScanMark): void;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { ScanPosition as i, MarkdownScanCursor as n, MarkdownScanMark as r, MARKDOWN_TAB_STOP_WIDTH as t };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/scan/scan.d.ts
|
|
2
|
+
declare const MARKDOWN_TAB_STOP_WIDTH = 4;
|
|
3
|
+
interface ScanPosition {
|
|
4
|
+
readonly offset: number;
|
|
5
|
+
readonly line: number;
|
|
6
|
+
readonly column: number;
|
|
7
|
+
}
|
|
8
|
+
interface MarkdownScanMark {
|
|
9
|
+
readonly rawOffset: number;
|
|
10
|
+
readonly lineNumber: number;
|
|
11
|
+
readonly columnNumber: number;
|
|
12
|
+
readonly pendingTabColumns: number;
|
|
13
|
+
}
|
|
14
|
+
declare class MarkdownScanCursor {
|
|
15
|
+
private readonly source;
|
|
16
|
+
private rawOffset;
|
|
17
|
+
private lineNumber;
|
|
18
|
+
private columnNumber;
|
|
19
|
+
private pendingTabColumns;
|
|
20
|
+
constructor(source: string);
|
|
21
|
+
get position(): ScanPosition;
|
|
22
|
+
atEnd(): boolean;
|
|
23
|
+
peek(): string | undefined;
|
|
24
|
+
peekRaw(count: number): string;
|
|
25
|
+
next(): string | undefined;
|
|
26
|
+
mark(): MarkdownScanMark;
|
|
27
|
+
reset(mark: MarkdownScanMark): void;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { ScanPosition as i, MarkdownScanCursor as n, MarkdownScanMark as r, MARKDOWN_TAB_STOP_WIDTH as t };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/shared/list-id.ts
|
|
3
|
+
const NUMID_PATTERN = /^md(\d+):(bullet|ordered)(?:@(\d+))?(\+task)?(\+loose)?$/;
|
|
4
|
+
const DEFAULT_ORDERED_START = 1;
|
|
5
|
+
function createNumIdMintState() {
|
|
6
|
+
return { next: 1 };
|
|
7
|
+
}
|
|
8
|
+
function mintListNumId(state, options) {
|
|
9
|
+
const id = state.next;
|
|
10
|
+
state.next += 1;
|
|
11
|
+
const startSuffix = options.type === "ordered" && options.start !== void 0 && options.start !== DEFAULT_ORDERED_START ? `@${String(options.start)}` : "";
|
|
12
|
+
const taskSuffix = options.task ? "+task" : "";
|
|
13
|
+
const looseSuffix = options.loose ? "+loose" : "";
|
|
14
|
+
return `md${String(id)}:${options.type}${startSuffix}${taskSuffix}${looseSuffix}`;
|
|
15
|
+
}
|
|
16
|
+
function parseListNumId(numId) {
|
|
17
|
+
const match = NUMID_PATTERN.exec(numId);
|
|
18
|
+
if (match === null) return;
|
|
19
|
+
const type = match[2];
|
|
20
|
+
if (type === void 0 || type !== "bullet" && type !== "ordered") return;
|
|
21
|
+
const startText = match[3];
|
|
22
|
+
return {
|
|
23
|
+
type,
|
|
24
|
+
start: type === "ordered" && startText !== void 0 ? Number.parseInt(startText, 10) : void 0,
|
|
25
|
+
task: match[4] !== void 0,
|
|
26
|
+
loose: match[5] !== void 0
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function mintedListType(numId) {
|
|
30
|
+
return parseListNumId(numId)?.type;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
exports.createNumIdMintState = createNumIdMintState;
|
|
34
|
+
exports.mintListNumId = mintListNumId;
|
|
35
|
+
exports.mintedListType = mintedListType;
|
|
36
|
+
exports.parseListNumId = parseListNumId;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/shared/list-id.d.ts
|
|
2
|
+
interface ListNumIdInfo {
|
|
3
|
+
readonly type: 'bullet' | 'ordered';
|
|
4
|
+
readonly start?: number;
|
|
5
|
+
readonly task: boolean;
|
|
6
|
+
readonly loose: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface ListNumIdMintOptions {
|
|
9
|
+
readonly type: 'bullet' | 'ordered';
|
|
10
|
+
readonly start?: number;
|
|
11
|
+
readonly task: boolean;
|
|
12
|
+
readonly loose: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface NumIdMintState {
|
|
15
|
+
next: number;
|
|
16
|
+
}
|
|
17
|
+
declare function createNumIdMintState(): NumIdMintState;
|
|
18
|
+
declare function mintListNumId(state: NumIdMintState, options: ListNumIdMintOptions): string;
|
|
19
|
+
declare function parseListNumId(numId: string): ListNumIdInfo | undefined;
|
|
20
|
+
declare function mintedListType(numId: string): 'bullet' | 'ordered' | undefined;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { ListNumIdInfo, ListNumIdMintOptions, NumIdMintState, createNumIdMintState, mintListNumId, mintedListType, parseListNumId };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region src/shared/list-id.d.ts
|
|
2
|
+
interface ListNumIdInfo {
|
|
3
|
+
readonly type: 'bullet' | 'ordered';
|
|
4
|
+
readonly start?: number;
|
|
5
|
+
readonly task: boolean;
|
|
6
|
+
readonly loose: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface ListNumIdMintOptions {
|
|
9
|
+
readonly type: 'bullet' | 'ordered';
|
|
10
|
+
readonly start?: number;
|
|
11
|
+
readonly task: boolean;
|
|
12
|
+
readonly loose: boolean;
|
|
13
|
+
}
|
|
14
|
+
interface NumIdMintState {
|
|
15
|
+
next: number;
|
|
16
|
+
}
|
|
17
|
+
declare function createNumIdMintState(): NumIdMintState;
|
|
18
|
+
declare function mintListNumId(state: NumIdMintState, options: ListNumIdMintOptions): string;
|
|
19
|
+
declare function parseListNumId(numId: string): ListNumIdInfo | undefined;
|
|
20
|
+
declare function mintedListType(numId: string): 'bullet' | 'ordered' | undefined;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { ListNumIdInfo, ListNumIdMintOptions, NumIdMintState, createNumIdMintState, mintListNumId, mintedListType, parseListNumId };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/shared/list-id.ts
|
|
2
|
+
const NUMID_PATTERN = /^md(\d+):(bullet|ordered)(?:@(\d+))?(\+task)?(\+loose)?$/;
|
|
3
|
+
const DEFAULT_ORDERED_START = 1;
|
|
4
|
+
function createNumIdMintState() {
|
|
5
|
+
return { next: 1 };
|
|
6
|
+
}
|
|
7
|
+
function mintListNumId(state, options) {
|
|
8
|
+
const id = state.next;
|
|
9
|
+
state.next += 1;
|
|
10
|
+
const startSuffix = options.type === "ordered" && options.start !== void 0 && options.start !== DEFAULT_ORDERED_START ? `@${String(options.start)}` : "";
|
|
11
|
+
const taskSuffix = options.task ? "+task" : "";
|
|
12
|
+
const looseSuffix = options.loose ? "+loose" : "";
|
|
13
|
+
return `md${String(id)}:${options.type}${startSuffix}${taskSuffix}${looseSuffix}`;
|
|
14
|
+
}
|
|
15
|
+
function parseListNumId(numId) {
|
|
16
|
+
const match = NUMID_PATTERN.exec(numId);
|
|
17
|
+
if (match === null) return;
|
|
18
|
+
const type = match[2];
|
|
19
|
+
if (type === void 0 || type !== "bullet" && type !== "ordered") return;
|
|
20
|
+
const startText = match[3];
|
|
21
|
+
return {
|
|
22
|
+
type,
|
|
23
|
+
start: type === "ordered" && startText !== void 0 ? Number.parseInt(startText, 10) : void 0,
|
|
24
|
+
task: match[4] !== void 0,
|
|
25
|
+
loose: match[5] !== void 0
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function mintedListType(numId) {
|
|
29
|
+
return parseListNumId(numId)?.type;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { createNumIdMintState, mintListNumId, mintedListType, parseListNumId };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/shared/style-constants.ts
|
|
3
|
+
const HEADING_STYLE_PREFIX = "Heading";
|
|
4
|
+
function headingStyleId(level) {
|
|
5
|
+
return `${HEADING_STYLE_PREFIX}${String(level)}`;
|
|
6
|
+
}
|
|
7
|
+
const MAX_HEADING_STYLE_LEVEL = 6;
|
|
8
|
+
const HEADING_STYLE_ID_PATTERN = /^Heading([0-9]+)$/;
|
|
9
|
+
function parseHeadingStyleId(styleId) {
|
|
10
|
+
const levelText = HEADING_STYLE_ID_PATTERN.exec(styleId)?.[1];
|
|
11
|
+
if (levelText === void 0) return;
|
|
12
|
+
const level = Number.parseInt(levelText, 10);
|
|
13
|
+
return Number.isInteger(level) && level > 0 ? level : void 0;
|
|
14
|
+
}
|
|
15
|
+
const QUOTE_STYLE_ID = "Quote";
|
|
16
|
+
const CODE_BLOCK_STYLE_ID = "CodeBlock";
|
|
17
|
+
const HORIZONTAL_RULE_STYLE_ID = "HorizontalRule";
|
|
18
|
+
const HTML_PREFORMATTED_STYLE_ID = "HTMLPreformatted";
|
|
19
|
+
const MONOSPACE_FONT_FAMILY = "Courier New";
|
|
20
|
+
const QUOTE_INDENT_PT = 36;
|
|
21
|
+
const TASK_CHECKBOX_UNCHECKED = "☐";
|
|
22
|
+
const TASK_CHECKBOX_CHECKED = "☒";
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.CODE_BLOCK_STYLE_ID = CODE_BLOCK_STYLE_ID;
|
|
25
|
+
exports.HORIZONTAL_RULE_STYLE_ID = HORIZONTAL_RULE_STYLE_ID;
|
|
26
|
+
exports.HTML_PREFORMATTED_STYLE_ID = HTML_PREFORMATTED_STYLE_ID;
|
|
27
|
+
exports.MAX_HEADING_STYLE_LEVEL = MAX_HEADING_STYLE_LEVEL;
|
|
28
|
+
exports.MONOSPACE_FONT_FAMILY = MONOSPACE_FONT_FAMILY;
|
|
29
|
+
exports.QUOTE_INDENT_PT = QUOTE_INDENT_PT;
|
|
30
|
+
exports.QUOTE_STYLE_ID = QUOTE_STYLE_ID;
|
|
31
|
+
exports.TASK_CHECKBOX_CHECKED = TASK_CHECKBOX_CHECKED;
|
|
32
|
+
exports.TASK_CHECKBOX_UNCHECKED = TASK_CHECKBOX_UNCHECKED;
|
|
33
|
+
exports.headingStyleId = headingStyleId;
|
|
34
|
+
exports.parseHeadingStyleId = parseHeadingStyleId;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/shared/style-constants.d.ts
|
|
2
|
+
declare function headingStyleId(level: number): string;
|
|
3
|
+
declare const MAX_HEADING_STYLE_LEVEL = 6;
|
|
4
|
+
declare function parseHeadingStyleId(styleId: string): number | undefined;
|
|
5
|
+
declare const QUOTE_STYLE_ID = "Quote";
|
|
6
|
+
declare const CODE_BLOCK_STYLE_ID = "CodeBlock";
|
|
7
|
+
declare const HORIZONTAL_RULE_STYLE_ID = "HorizontalRule";
|
|
8
|
+
declare const HTML_PREFORMATTED_STYLE_ID = "HTMLPreformatted";
|
|
9
|
+
declare const MONOSPACE_FONT_FAMILY = "Courier New";
|
|
10
|
+
declare const QUOTE_INDENT_PT = 36;
|
|
11
|
+
declare const TASK_CHECKBOX_UNCHECKED = "☐";
|
|
12
|
+
declare const TASK_CHECKBOX_CHECKED = "☒";
|
|
13
|
+
//#endregion
|
|
14
|
+
export { CODE_BLOCK_STYLE_ID, HORIZONTAL_RULE_STYLE_ID, HTML_PREFORMATTED_STYLE_ID, MAX_HEADING_STYLE_LEVEL, MONOSPACE_FONT_FAMILY, QUOTE_INDENT_PT, QUOTE_STYLE_ID, TASK_CHECKBOX_CHECKED, TASK_CHECKBOX_UNCHECKED, headingStyleId, parseHeadingStyleId };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/shared/style-constants.d.ts
|
|
2
|
+
declare function headingStyleId(level: number): string;
|
|
3
|
+
declare const MAX_HEADING_STYLE_LEVEL = 6;
|
|
4
|
+
declare function parseHeadingStyleId(styleId: string): number | undefined;
|
|
5
|
+
declare const QUOTE_STYLE_ID = "Quote";
|
|
6
|
+
declare const CODE_BLOCK_STYLE_ID = "CodeBlock";
|
|
7
|
+
declare const HORIZONTAL_RULE_STYLE_ID = "HorizontalRule";
|
|
8
|
+
declare const HTML_PREFORMATTED_STYLE_ID = "HTMLPreformatted";
|
|
9
|
+
declare const MONOSPACE_FONT_FAMILY = "Courier New";
|
|
10
|
+
declare const QUOTE_INDENT_PT = 36;
|
|
11
|
+
declare const TASK_CHECKBOX_UNCHECKED = "☐";
|
|
12
|
+
declare const TASK_CHECKBOX_CHECKED = "☒";
|
|
13
|
+
//#endregion
|
|
14
|
+
export { CODE_BLOCK_STYLE_ID, HORIZONTAL_RULE_STYLE_ID, HTML_PREFORMATTED_STYLE_ID, MAX_HEADING_STYLE_LEVEL, MONOSPACE_FONT_FAMILY, QUOTE_INDENT_PT, QUOTE_STYLE_ID, TASK_CHECKBOX_CHECKED, TASK_CHECKBOX_UNCHECKED, headingStyleId, parseHeadingStyleId };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/shared/style-constants.ts
|
|
2
|
+
const HEADING_STYLE_PREFIX = "Heading";
|
|
3
|
+
function headingStyleId(level) {
|
|
4
|
+
return `${HEADING_STYLE_PREFIX}${String(level)}`;
|
|
5
|
+
}
|
|
6
|
+
const MAX_HEADING_STYLE_LEVEL = 6;
|
|
7
|
+
const HEADING_STYLE_ID_PATTERN = /^Heading([0-9]+)$/;
|
|
8
|
+
function parseHeadingStyleId(styleId) {
|
|
9
|
+
const levelText = HEADING_STYLE_ID_PATTERN.exec(styleId)?.[1];
|
|
10
|
+
if (levelText === void 0) return;
|
|
11
|
+
const level = Number.parseInt(levelText, 10);
|
|
12
|
+
return Number.isInteger(level) && level > 0 ? level : void 0;
|
|
13
|
+
}
|
|
14
|
+
const QUOTE_STYLE_ID = "Quote";
|
|
15
|
+
const CODE_BLOCK_STYLE_ID = "CodeBlock";
|
|
16
|
+
const HORIZONTAL_RULE_STYLE_ID = "HorizontalRule";
|
|
17
|
+
const HTML_PREFORMATTED_STYLE_ID = "HTMLPreformatted";
|
|
18
|
+
const MONOSPACE_FONT_FAMILY = "Courier New";
|
|
19
|
+
const QUOTE_INDENT_PT = 36;
|
|
20
|
+
const TASK_CHECKBOX_UNCHECKED = "☐";
|
|
21
|
+
const TASK_CHECKBOX_CHECKED = "☒";
|
|
22
|
+
//#endregion
|
|
23
|
+
export { CODE_BLOCK_STYLE_ID, HORIZONTAL_RULE_STYLE_ID, HTML_PREFORMATTED_STYLE_ID, MAX_HEADING_STYLE_LEVEL, MONOSPACE_FONT_FAMILY, QUOTE_INDENT_PT, QUOTE_STYLE_ID, TASK_CHECKBOX_CHECKED, TASK_CHECKBOX_UNCHECKED, headingStyleId, parseHeadingStyleId };
|
package/dist/write.cjs
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_emit_emit = require("./emit/emit.cjs");
|
|
3
|
+
//#region src/write.ts
|
|
4
|
+
function writeMarkdown(document, options = {}) {
|
|
5
|
+
options.signal?.throwIfAborted();
|
|
6
|
+
return require_emit_emit.emitMarkdown(document, options);
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
exports.writeMarkdown = writeMarkdown;
|
package/dist/write.d.cts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { WriteMarkdownOptions } from "./options/options.cjs";
|
|
2
|
+
import { ContentDocument } from "document-schema.js";
|
|
3
|
+
//#region src/write.d.ts
|
|
4
|
+
declare function writeMarkdown(document: ContentDocument, options?: WriteMarkdownOptions): string;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { writeMarkdown };
|
package/dist/write.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { WriteMarkdownOptions } from "./options/options.js";
|
|
2
|
+
import { ContentDocument } from "document-schema.js";
|
|
3
|
+
//#region src/write.d.ts
|
|
4
|
+
declare function writeMarkdown(document: ContentDocument, options?: WriteMarkdownOptions): string;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { writeMarkdown };
|
package/dist/write.js
ADDED
package/package.json
CHANGED
|
@@ -1,5 +1,95 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markdown-codec",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Hand-written CommonMark+GFM <-> ContentDocument codec, built on document-schema.js",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/ExaDev/markdown-codec.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/ExaDev/markdown-codec#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/ExaDev/markdown-codec/issues"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": {
|
|
17
|
+
"import": "./dist/index.d.ts",
|
|
18
|
+
"require": "./dist/index.d.cts"
|
|
19
|
+
},
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"require": "./dist/index.cjs"
|
|
22
|
+
},
|
|
23
|
+
"./*": {
|
|
24
|
+
"types": {
|
|
25
|
+
"import": "./dist/*.d.ts",
|
|
26
|
+
"require": "./dist/*.d.cts"
|
|
27
|
+
},
|
|
28
|
+
"import": "./dist/*.js",
|
|
29
|
+
"require": "./dist/*.cjs"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"main": "./dist/index.cjs",
|
|
33
|
+
"module": "./dist/index.js",
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"files": [
|
|
36
|
+
"dist"
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public",
|
|
40
|
+
"provenance": true,
|
|
41
|
+
"registry": "https://registry.npmjs.org/"
|
|
42
|
+
},
|
|
43
|
+
"sideEffects": false,
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=20"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsdown",
|
|
49
|
+
"prepublishOnly": "pnpm run lint && pnpm run typecheck && tsdown && publint && attw --pack",
|
|
50
|
+
"lint": "eslint . --max-warnings 0",
|
|
51
|
+
"typecheck": "tsc --noEmit",
|
|
52
|
+
"test": "vitest run --project unit",
|
|
53
|
+
"test:watch": "vitest --project unit",
|
|
54
|
+
"test:coverage": "vitest run --project unit --coverage",
|
|
55
|
+
"test:corpus": "vitest run --project corpus",
|
|
56
|
+
"test:smoke": "tsdown && vitest run --project smoke",
|
|
57
|
+
"prepare": "husky",
|
|
58
|
+
"release": "semantic-release"
|
|
59
|
+
},
|
|
60
|
+
"keywords": [
|
|
61
|
+
"markdown",
|
|
62
|
+
"commonmark",
|
|
63
|
+
"gfm",
|
|
64
|
+
"codec",
|
|
65
|
+
"round-trip",
|
|
66
|
+
"zod",
|
|
67
|
+
"ast"
|
|
68
|
+
],
|
|
69
|
+
"license": "MIT",
|
|
70
|
+
"packageManager": "pnpm@11.6.0",
|
|
71
|
+
"dependencies": {
|
|
72
|
+
"document-schema.js": "^2.2.0",
|
|
73
|
+
"zod": "^4.4.3"
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@arethetypeswrong/cli": "^0.18.5",
|
|
77
|
+
"@commitlint/cli": "^21.2.1",
|
|
78
|
+
"@commitlint/config-conventional": "^21.2.0",
|
|
79
|
+
"@eslint/js": "^10.0.1",
|
|
80
|
+
"@semantic-release/changelog": "^7.0.0",
|
|
81
|
+
"@semantic-release/git": "^11.0.1",
|
|
82
|
+
"@types/node": "^26.1.1",
|
|
83
|
+
"@vitest/coverage-v8": "^4.1.10",
|
|
84
|
+
"eslint": "^10.8.0",
|
|
85
|
+
"globals": "^17.8.0",
|
|
86
|
+
"husky": "^9.1.7",
|
|
87
|
+
"lint-staged": "^17.2.0",
|
|
88
|
+
"publint": "^0.3.21",
|
|
89
|
+
"semantic-release": "^25.0.8",
|
|
90
|
+
"tsdown": "^0.22.13",
|
|
91
|
+
"typescript": "^6.0.3",
|
|
92
|
+
"typescript-eslint": "^8.65.0",
|
|
93
|
+
"vitest": "^4.1.10"
|
|
94
|
+
}
|
|
5
95
|
}
|