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,57 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/inline/node.ts
|
|
3
|
+
var InlineNode = class {
|
|
4
|
+
kind;
|
|
5
|
+
literal = "";
|
|
6
|
+
destination = "";
|
|
7
|
+
title;
|
|
8
|
+
email = false;
|
|
9
|
+
marker = "*";
|
|
10
|
+
raw = "";
|
|
11
|
+
parent;
|
|
12
|
+
firstChild;
|
|
13
|
+
lastChild;
|
|
14
|
+
previous;
|
|
15
|
+
next;
|
|
16
|
+
constructor(kind) {
|
|
17
|
+
this.kind = kind;
|
|
18
|
+
}
|
|
19
|
+
appendChild(child) {
|
|
20
|
+
child.unlink();
|
|
21
|
+
child.parent = this;
|
|
22
|
+
if (this.lastChild === void 0) {
|
|
23
|
+
this.firstChild = child;
|
|
24
|
+
this.lastChild = child;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
child.previous = this.lastChild;
|
|
28
|
+
this.lastChild.next = child;
|
|
29
|
+
this.lastChild = child;
|
|
30
|
+
}
|
|
31
|
+
insertAfter(sibling) {
|
|
32
|
+
sibling.unlink();
|
|
33
|
+
sibling.next = this.next;
|
|
34
|
+
if (sibling.next !== void 0) sibling.next.previous = sibling;
|
|
35
|
+
sibling.previous = this;
|
|
36
|
+
this.next = sibling;
|
|
37
|
+
sibling.parent = this.parent;
|
|
38
|
+
if (sibling.next === void 0 && sibling.parent !== void 0) sibling.parent.lastChild = sibling;
|
|
39
|
+
}
|
|
40
|
+
unlink() {
|
|
41
|
+
if (this.previous !== void 0) this.previous.next = this.next;
|
|
42
|
+
else if (this.parent !== void 0) this.parent.firstChild = this.next;
|
|
43
|
+
if (this.next !== void 0) this.next.previous = this.previous;
|
|
44
|
+
else if (this.parent !== void 0) this.parent.lastChild = this.previous;
|
|
45
|
+
this.parent = void 0;
|
|
46
|
+
this.next = void 0;
|
|
47
|
+
this.previous = void 0;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
function createTextNode(literal) {
|
|
51
|
+
const node = new InlineNode("text");
|
|
52
|
+
node.literal = literal;
|
|
53
|
+
return node;
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
exports.InlineNode = InlineNode;
|
|
57
|
+
exports.createTextNode = createTextNode;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/inline/node.d.ts
|
|
2
|
+
type InlineNodeKind = 'text' | 'emphasis' | 'strong' | 'strikethrough' | 'codeSpan' | 'link' | 'image' | 'autolink' | 'hardBreak' | 'softBreak' | 'rawHtml' | 'entity' | 'container';
|
|
3
|
+
declare class InlineNode {
|
|
4
|
+
readonly kind: InlineNodeKind;
|
|
5
|
+
literal: string;
|
|
6
|
+
destination: string;
|
|
7
|
+
title: string | undefined;
|
|
8
|
+
email: boolean;
|
|
9
|
+
marker: '_' | '*';
|
|
10
|
+
raw: string;
|
|
11
|
+
parent: InlineNode | undefined;
|
|
12
|
+
firstChild: InlineNode | undefined;
|
|
13
|
+
lastChild: InlineNode | undefined;
|
|
14
|
+
previous: InlineNode | undefined;
|
|
15
|
+
next: InlineNode | undefined;
|
|
16
|
+
constructor(kind: InlineNodeKind);
|
|
17
|
+
appendChild(child: InlineNode): void;
|
|
18
|
+
insertAfter(sibling: InlineNode): void;
|
|
19
|
+
unlink(): void;
|
|
20
|
+
}
|
|
21
|
+
declare function createTextNode(literal: string): InlineNode;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { InlineNode, InlineNodeKind, createTextNode };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/inline/node.d.ts
|
|
2
|
+
type InlineNodeKind = 'text' | 'emphasis' | 'strong' | 'strikethrough' | 'codeSpan' | 'link' | 'image' | 'autolink' | 'hardBreak' | 'softBreak' | 'rawHtml' | 'entity' | 'container';
|
|
3
|
+
declare class InlineNode {
|
|
4
|
+
readonly kind: InlineNodeKind;
|
|
5
|
+
literal: string;
|
|
6
|
+
destination: string;
|
|
7
|
+
title: string | undefined;
|
|
8
|
+
email: boolean;
|
|
9
|
+
marker: '_' | '*';
|
|
10
|
+
raw: string;
|
|
11
|
+
parent: InlineNode | undefined;
|
|
12
|
+
firstChild: InlineNode | undefined;
|
|
13
|
+
lastChild: InlineNode | undefined;
|
|
14
|
+
previous: InlineNode | undefined;
|
|
15
|
+
next: InlineNode | undefined;
|
|
16
|
+
constructor(kind: InlineNodeKind);
|
|
17
|
+
appendChild(child: InlineNode): void;
|
|
18
|
+
insertAfter(sibling: InlineNode): void;
|
|
19
|
+
unlink(): void;
|
|
20
|
+
}
|
|
21
|
+
declare function createTextNode(literal: string): InlineNode;
|
|
22
|
+
//#endregion
|
|
23
|
+
export { InlineNode, InlineNodeKind, createTextNode };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
//#region src/inline/node.ts
|
|
2
|
+
var InlineNode = class {
|
|
3
|
+
kind;
|
|
4
|
+
literal = "";
|
|
5
|
+
destination = "";
|
|
6
|
+
title;
|
|
7
|
+
email = false;
|
|
8
|
+
marker = "*";
|
|
9
|
+
raw = "";
|
|
10
|
+
parent;
|
|
11
|
+
firstChild;
|
|
12
|
+
lastChild;
|
|
13
|
+
previous;
|
|
14
|
+
next;
|
|
15
|
+
constructor(kind) {
|
|
16
|
+
this.kind = kind;
|
|
17
|
+
}
|
|
18
|
+
appendChild(child) {
|
|
19
|
+
child.unlink();
|
|
20
|
+
child.parent = this;
|
|
21
|
+
if (this.lastChild === void 0) {
|
|
22
|
+
this.firstChild = child;
|
|
23
|
+
this.lastChild = child;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
child.previous = this.lastChild;
|
|
27
|
+
this.lastChild.next = child;
|
|
28
|
+
this.lastChild = child;
|
|
29
|
+
}
|
|
30
|
+
insertAfter(sibling) {
|
|
31
|
+
sibling.unlink();
|
|
32
|
+
sibling.next = this.next;
|
|
33
|
+
if (sibling.next !== void 0) sibling.next.previous = sibling;
|
|
34
|
+
sibling.previous = this;
|
|
35
|
+
this.next = sibling;
|
|
36
|
+
sibling.parent = this.parent;
|
|
37
|
+
if (sibling.next === void 0 && sibling.parent !== void 0) sibling.parent.lastChild = sibling;
|
|
38
|
+
}
|
|
39
|
+
unlink() {
|
|
40
|
+
if (this.previous !== void 0) this.previous.next = this.next;
|
|
41
|
+
else if (this.parent !== void 0) this.parent.firstChild = this.next;
|
|
42
|
+
if (this.next !== void 0) this.next.previous = this.previous;
|
|
43
|
+
else if (this.parent !== void 0) this.parent.lastChild = this.previous;
|
|
44
|
+
this.parent = void 0;
|
|
45
|
+
this.next = void 0;
|
|
46
|
+
this.previous = void 0;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
function createTextNode(literal) {
|
|
50
|
+
const node = new InlineNode("text");
|
|
51
|
+
node.literal = literal;
|
|
52
|
+
return node;
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { InlineNode, createTextNode };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { g as MarkdownInlineNode } from "./ast-BXYwy08e.js";
|
|
2
|
+
import { n as LinkReferenceMap } from "./link-Dv4kxVjk.js";
|
|
3
|
+
//#region src/inline/inline.d.ts
|
|
4
|
+
interface InlineParseOptions {
|
|
5
|
+
readonly gfmAutolinks?: boolean;
|
|
6
|
+
readonly gfmStrikethrough?: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare function parseInlines(content: string, references: LinkReferenceMap, options?: InlineParseOptions): MarkdownInlineNode[];
|
|
9
|
+
//#endregion
|
|
10
|
+
export { parseInlines as n, InlineParseOptions as t };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { g as MarkdownInlineNode } from "./ast-BXYwy08e.cjs";
|
|
2
|
+
import { n as LinkReferenceMap } from "./link-Dv4kxVjk.cjs";
|
|
3
|
+
//#region src/inline/inline.d.ts
|
|
4
|
+
interface InlineParseOptions {
|
|
5
|
+
readonly gfmAutolinks?: boolean;
|
|
6
|
+
readonly gfmStrikethrough?: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare function parseInlines(content: string, references: LinkReferenceMap, options?: InlineParseOptions): MarkdownInlineNode[];
|
|
9
|
+
//#endregion
|
|
10
|
+
export { parseInlines as n, InlineParseOptions as t };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/inline/link.d.ts
|
|
2
|
+
interface LinkReferenceDefinition {
|
|
3
|
+
readonly destination: string;
|
|
4
|
+
readonly title?: string;
|
|
5
|
+
}
|
|
6
|
+
type LinkReferenceMap = ReadonlyMap<string, LinkReferenceDefinition>;
|
|
7
|
+
declare function normalizeLinkLabel(labelWithBrackets: string): string;
|
|
8
|
+
declare function matchLinkLabel(text: string, start: number): number;
|
|
9
|
+
interface ParsedSpan {
|
|
10
|
+
readonly value: string;
|
|
11
|
+
readonly end: number;
|
|
12
|
+
}
|
|
13
|
+
declare function parseLinkDestination(text: string, start: number): ParsedSpan | undefined;
|
|
14
|
+
declare function parseLinkTitle(text: string, start: number): ParsedSpan | undefined;
|
|
15
|
+
declare function skipInlineWhitespace(text: string, start: number): number;
|
|
16
|
+
declare function isBlankRemainderOfLine(text: string, start: number): boolean;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { matchLinkLabel as a, parseLinkTitle as c, isBlankRemainderOfLine as i, skipInlineWhitespace as l, LinkReferenceMap as n, normalizeLinkLabel as o, ParsedSpan as r, parseLinkDestination as s, LinkReferenceDefinition as t };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/inline/link.d.ts
|
|
2
|
+
interface LinkReferenceDefinition {
|
|
3
|
+
readonly destination: string;
|
|
4
|
+
readonly title?: string;
|
|
5
|
+
}
|
|
6
|
+
type LinkReferenceMap = ReadonlyMap<string, LinkReferenceDefinition>;
|
|
7
|
+
declare function normalizeLinkLabel(labelWithBrackets: string): string;
|
|
8
|
+
declare function matchLinkLabel(text: string, start: number): number;
|
|
9
|
+
interface ParsedSpan {
|
|
10
|
+
readonly value: string;
|
|
11
|
+
readonly end: number;
|
|
12
|
+
}
|
|
13
|
+
declare function parseLinkDestination(text: string, start: number): ParsedSpan | undefined;
|
|
14
|
+
declare function parseLinkTitle(text: string, start: number): ParsedSpan | undefined;
|
|
15
|
+
declare function skipInlineWhitespace(text: string, start: number): number;
|
|
16
|
+
declare function isBlankRemainderOfLine(text: string, start: number): boolean;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { matchLinkLabel as a, parseLinkTitle as c, isBlankRemainderOfLine as i, skipInlineWhitespace as l, LinkReferenceMap as n, normalizeLinkLabel as o, ParsedSpan as r, parseLinkDestination as s, LinkReferenceDefinition as t };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_diagnostics_diagnostics = require("../diagnostics/diagnostics.cjs");
|
|
3
|
+
//#region src/lower/front-matter.ts
|
|
4
|
+
const LEADING_DELIMITER_PATTERN = /^---[ \t]*$/;
|
|
5
|
+
const CLOSING_DELIMITER_PATTERN = /^(?:---|\.\.\.)[ \t]*$/;
|
|
6
|
+
const KEY_VALUE_LINE_PATTERN = /^([A-Za-z_][A-Za-z0-9_-]*):[ \t]*(.*)$/;
|
|
7
|
+
const LINE_ENDING_PATTERN = /\r\n|\n|\r/;
|
|
8
|
+
function parseScalar(raw) {
|
|
9
|
+
const trimmed = raw.trim();
|
|
10
|
+
const isDoubleQuoted = trimmed.length >= 2 && trimmed.startsWith("\"") && trimmed.endsWith("\"");
|
|
11
|
+
const isSingleQuoted = trimmed.length >= 2 && trimmed.startsWith("'") && trimmed.endsWith("'");
|
|
12
|
+
return isDoubleQuoted || isSingleQuoted ? trimmed.slice(1, -1) : trimmed;
|
|
13
|
+
}
|
|
14
|
+
function parseKeywordList(raw) {
|
|
15
|
+
const trimmed = raw.trim();
|
|
16
|
+
return (trimmed.startsWith("[") && trimmed.endsWith("]") ? trimmed.slice(1, -1) : trimmed).split(",").map((item) => parseScalar(item)).filter((item) => item.length > 0);
|
|
17
|
+
}
|
|
18
|
+
function extractFrontMatter(source, sink = require_diagnostics_diagnostics.NOOP_MARKDOWN_DIAGNOSTIC_SINK) {
|
|
19
|
+
const lines = source.split(LINE_ENDING_PATTERN);
|
|
20
|
+
const firstLine = lines[0];
|
|
21
|
+
if (firstLine === void 0 || !LEADING_DELIMITER_PATTERN.test(firstLine)) return {
|
|
22
|
+
metadata: {},
|
|
23
|
+
rest: source
|
|
24
|
+
};
|
|
25
|
+
let closingIndex = -1;
|
|
26
|
+
for (let index = 1; index < lines.length; index += 1) if (CLOSING_DELIMITER_PATTERN.test(lines[index] ?? "")) {
|
|
27
|
+
closingIndex = index;
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
if (closingIndex === -1) return {
|
|
31
|
+
metadata: {},
|
|
32
|
+
rest: source
|
|
33
|
+
};
|
|
34
|
+
const metadata = {};
|
|
35
|
+
for (let index = 1; index < closingIndex; index += 1) {
|
|
36
|
+
const line = lines[index] ?? "";
|
|
37
|
+
if (line.trim().length === 0) continue;
|
|
38
|
+
const match = KEY_VALUE_LINE_PATTERN.exec(line);
|
|
39
|
+
const key = match?.[1];
|
|
40
|
+
const value = match?.[2];
|
|
41
|
+
if (key === void 0 || value === void 0) continue;
|
|
42
|
+
switch (key) {
|
|
43
|
+
case "title":
|
|
44
|
+
metadata.title = parseScalar(value);
|
|
45
|
+
break;
|
|
46
|
+
case "author":
|
|
47
|
+
metadata.author = parseScalar(value);
|
|
48
|
+
break;
|
|
49
|
+
case "subject":
|
|
50
|
+
metadata.subject = parseScalar(value);
|
|
51
|
+
break;
|
|
52
|
+
case "creator":
|
|
53
|
+
metadata.creator = parseScalar(value);
|
|
54
|
+
break;
|
|
55
|
+
case "date":
|
|
56
|
+
metadata.createdIso = parseScalar(value);
|
|
57
|
+
break;
|
|
58
|
+
case "keywords":
|
|
59
|
+
metadata.keywords = [...parseKeywordList(value)];
|
|
60
|
+
break;
|
|
61
|
+
default: sink({
|
|
62
|
+
code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.FRONT_MATTER_KEY_UNMAPPED,
|
|
63
|
+
severity: "info",
|
|
64
|
+
message: `front matter key "${key}" has no LayoutMetadata equivalent and was dropped`,
|
|
65
|
+
line: index + 1
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
metadata,
|
|
71
|
+
rest: lines.slice(closingIndex + 1).join("\n")
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
exports.extractFrontMatter = extractFrontMatter;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { i as MarkdownDiagnosticSink } from "../diagnostics-DmuWc7d8.cjs";
|
|
2
|
+
import { LayoutMetadata } from "document-schema.js";
|
|
3
|
+
//#region src/lower/front-matter.d.ts
|
|
4
|
+
interface FrontMatterResult {
|
|
5
|
+
readonly metadata: LayoutMetadata;
|
|
6
|
+
readonly rest: string;
|
|
7
|
+
}
|
|
8
|
+
declare function extractFrontMatter(source: string, sink?: MarkdownDiagnosticSink): FrontMatterResult;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { FrontMatterResult, extractFrontMatter };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { i as MarkdownDiagnosticSink } from "../diagnostics-DmuWc7d8.js";
|
|
2
|
+
import { LayoutMetadata } from "document-schema.js";
|
|
3
|
+
//#region src/lower/front-matter.d.ts
|
|
4
|
+
interface FrontMatterResult {
|
|
5
|
+
readonly metadata: LayoutMetadata;
|
|
6
|
+
readonly rest: string;
|
|
7
|
+
}
|
|
8
|
+
declare function extractFrontMatter(source: string, sink?: MarkdownDiagnosticSink): FrontMatterResult;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { FrontMatterResult, extractFrontMatter };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { MarkdownDiagnosticCodes, NOOP_MARKDOWN_DIAGNOSTIC_SINK } from "../diagnostics/diagnostics.js";
|
|
2
|
+
//#region src/lower/front-matter.ts
|
|
3
|
+
const LEADING_DELIMITER_PATTERN = /^---[ \t]*$/;
|
|
4
|
+
const CLOSING_DELIMITER_PATTERN = /^(?:---|\.\.\.)[ \t]*$/;
|
|
5
|
+
const KEY_VALUE_LINE_PATTERN = /^([A-Za-z_][A-Za-z0-9_-]*):[ \t]*(.*)$/;
|
|
6
|
+
const LINE_ENDING_PATTERN = /\r\n|\n|\r/;
|
|
7
|
+
function parseScalar(raw) {
|
|
8
|
+
const trimmed = raw.trim();
|
|
9
|
+
const isDoubleQuoted = trimmed.length >= 2 && trimmed.startsWith("\"") && trimmed.endsWith("\"");
|
|
10
|
+
const isSingleQuoted = trimmed.length >= 2 && trimmed.startsWith("'") && trimmed.endsWith("'");
|
|
11
|
+
return isDoubleQuoted || isSingleQuoted ? trimmed.slice(1, -1) : trimmed;
|
|
12
|
+
}
|
|
13
|
+
function parseKeywordList(raw) {
|
|
14
|
+
const trimmed = raw.trim();
|
|
15
|
+
return (trimmed.startsWith("[") && trimmed.endsWith("]") ? trimmed.slice(1, -1) : trimmed).split(",").map((item) => parseScalar(item)).filter((item) => item.length > 0);
|
|
16
|
+
}
|
|
17
|
+
function extractFrontMatter(source, sink = NOOP_MARKDOWN_DIAGNOSTIC_SINK) {
|
|
18
|
+
const lines = source.split(LINE_ENDING_PATTERN);
|
|
19
|
+
const firstLine = lines[0];
|
|
20
|
+
if (firstLine === void 0 || !LEADING_DELIMITER_PATTERN.test(firstLine)) return {
|
|
21
|
+
metadata: {},
|
|
22
|
+
rest: source
|
|
23
|
+
};
|
|
24
|
+
let closingIndex = -1;
|
|
25
|
+
for (let index = 1; index < lines.length; index += 1) if (CLOSING_DELIMITER_PATTERN.test(lines[index] ?? "")) {
|
|
26
|
+
closingIndex = index;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
if (closingIndex === -1) return {
|
|
30
|
+
metadata: {},
|
|
31
|
+
rest: source
|
|
32
|
+
};
|
|
33
|
+
const metadata = {};
|
|
34
|
+
for (let index = 1; index < closingIndex; index += 1) {
|
|
35
|
+
const line = lines[index] ?? "";
|
|
36
|
+
if (line.trim().length === 0) continue;
|
|
37
|
+
const match = KEY_VALUE_LINE_PATTERN.exec(line);
|
|
38
|
+
const key = match?.[1];
|
|
39
|
+
const value = match?.[2];
|
|
40
|
+
if (key === void 0 || value === void 0) continue;
|
|
41
|
+
switch (key) {
|
|
42
|
+
case "title":
|
|
43
|
+
metadata.title = parseScalar(value);
|
|
44
|
+
break;
|
|
45
|
+
case "author":
|
|
46
|
+
metadata.author = parseScalar(value);
|
|
47
|
+
break;
|
|
48
|
+
case "subject":
|
|
49
|
+
metadata.subject = parseScalar(value);
|
|
50
|
+
break;
|
|
51
|
+
case "creator":
|
|
52
|
+
metadata.creator = parseScalar(value);
|
|
53
|
+
break;
|
|
54
|
+
case "date":
|
|
55
|
+
metadata.createdIso = parseScalar(value);
|
|
56
|
+
break;
|
|
57
|
+
case "keywords":
|
|
58
|
+
metadata.keywords = [...parseKeywordList(value)];
|
|
59
|
+
break;
|
|
60
|
+
default: sink({
|
|
61
|
+
code: MarkdownDiagnosticCodes.FRONT_MATTER_KEY_UNMAPPED,
|
|
62
|
+
severity: "info",
|
|
63
|
+
message: `front matter key "${key}" has no LayoutMetadata equivalent and was dropped`,
|
|
64
|
+
line: index + 1
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
metadata,
|
|
70
|
+
rest: lines.slice(closingIndex + 1).join("\n")
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { extractFrontMatter };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_image_image = require("../image/image.cjs");
|
|
3
|
+
//#region src/lower/image.ts
|
|
4
|
+
const POINTS_PER_PIXEL = 72 / 96;
|
|
5
|
+
const DATA_URI_PATTERN = /^data:image\/(?:png|jpe?g);base64,(.+)$/is;
|
|
6
|
+
function decodeDataUriImage(destination) {
|
|
7
|
+
const base64 = DATA_URI_PATTERN.exec(destination)?.[1];
|
|
8
|
+
if (base64 === void 0) return;
|
|
9
|
+
try {
|
|
10
|
+
return require_image_image.base64ToBytes(base64);
|
|
11
|
+
} catch {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function resolveMarkdownImage(destination, context, resolver) {
|
|
16
|
+
const bytes = decodeDataUriImage(destination) ?? resolver?.(destination, context)?.bytes;
|
|
17
|
+
if (bytes === void 0) return;
|
|
18
|
+
const format = require_image_image.detectImageFormat(bytes);
|
|
19
|
+
const dimensions = require_image_image.readImageDimensions(bytes);
|
|
20
|
+
if (format === void 0 || dimensions === void 0) return;
|
|
21
|
+
return {
|
|
22
|
+
format,
|
|
23
|
+
base64: require_image_image.bytesToBase64(bytes),
|
|
24
|
+
widthPt: dimensions.widthPx * POINTS_PER_PIXEL,
|
|
25
|
+
heightPt: dimensions.heightPx * POINTS_PER_PIXEL
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.resolveMarkdownImage = resolveMarkdownImage;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as resolveMarkdownImage, i as ResolvedMarkdownImage, n as MarkdownImageResolver, r as MarkdownResolvedImageBytes, t as MarkdownImageResolveContext } from "../image-C4KYmz_L.cjs";
|
|
2
|
+
export { MarkdownImageResolveContext, MarkdownImageResolver, MarkdownResolvedImageBytes, ResolvedMarkdownImage, resolveMarkdownImage };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as resolveMarkdownImage, i as ResolvedMarkdownImage, n as MarkdownImageResolver, r as MarkdownResolvedImageBytes, t as MarkdownImageResolveContext } from "../image-Cm3hT5PS.js";
|
|
2
|
+
export { MarkdownImageResolveContext, MarkdownImageResolver, MarkdownResolvedImageBytes, ResolvedMarkdownImage, resolveMarkdownImage };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { base64ToBytes, bytesToBase64, detectImageFormat, readImageDimensions } from "../image/image.js";
|
|
2
|
+
//#region src/lower/image.ts
|
|
3
|
+
const POINTS_PER_PIXEL = 72 / 96;
|
|
4
|
+
const DATA_URI_PATTERN = /^data:image\/(?:png|jpe?g);base64,(.+)$/is;
|
|
5
|
+
function decodeDataUriImage(destination) {
|
|
6
|
+
const base64 = DATA_URI_PATTERN.exec(destination)?.[1];
|
|
7
|
+
if (base64 === void 0) return;
|
|
8
|
+
try {
|
|
9
|
+
return base64ToBytes(base64);
|
|
10
|
+
} catch {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function resolveMarkdownImage(destination, context, resolver) {
|
|
15
|
+
const bytes = decodeDataUriImage(destination) ?? resolver?.(destination, context)?.bytes;
|
|
16
|
+
if (bytes === void 0) return;
|
|
17
|
+
const format = detectImageFormat(bytes);
|
|
18
|
+
const dimensions = readImageDimensions(bytes);
|
|
19
|
+
if (format === void 0 || dimensions === void 0) return;
|
|
20
|
+
return {
|
|
21
|
+
format,
|
|
22
|
+
base64: bytesToBase64(bytes),
|
|
23
|
+
widthPt: dimensions.widthPx * POINTS_PER_PIXEL,
|
|
24
|
+
heightPt: dimensions.heightPx * POINTS_PER_PIXEL
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { resolveMarkdownImage };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_diagnostics_diagnostics = require("../diagnostics/diagnostics.cjs");
|
|
3
|
+
const require_shared_style_constants = require("../shared/style-constants.cjs");
|
|
4
|
+
//#region src/lower/inline.ts
|
|
5
|
+
function buildRun(text, style, fontFamily) {
|
|
6
|
+
return {
|
|
7
|
+
text,
|
|
8
|
+
...style.bold === true ? { bold: true } : {},
|
|
9
|
+
...style.italic === true ? { italic: true } : {},
|
|
10
|
+
...style.strike === true ? { strike: true } : {},
|
|
11
|
+
...style.hyperlink !== void 0 ? { hyperlink: style.hyperlink } : {},
|
|
12
|
+
...fontFamily !== void 0 ? { fontFamily } : {}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function lowerNestedEmphasisLike(kind, node, style, context) {
|
|
16
|
+
if (style[kind] === true) context.sink({
|
|
17
|
+
code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.NESTED_EMPHASIS_FLATTENED,
|
|
18
|
+
severity: "info",
|
|
19
|
+
message: `a ${kind === "italic" ? "emphasis" : kind === "bold" ? "strong emphasis" : "strikethrough"} span is nested inside another span of the same kind; ContentRun has no nesting depth of its own, so both collapse to one flat run`
|
|
20
|
+
});
|
|
21
|
+
const childStyle = {
|
|
22
|
+
...style,
|
|
23
|
+
[kind]: true
|
|
24
|
+
};
|
|
25
|
+
return node.children.flatMap((child) => lowerInlineNode(child, childStyle, context));
|
|
26
|
+
}
|
|
27
|
+
function lowerInlineNode(node, style, context) {
|
|
28
|
+
switch (node.type) {
|
|
29
|
+
case "text": return node.value.length === 0 ? [] : [buildRun(node.value, style)];
|
|
30
|
+
case "entity": return node.value.length === 0 ? [] : [buildRun(node.value, style)];
|
|
31
|
+
case "softBreak": return [buildRun(" ", style)];
|
|
32
|
+
case "hardBreak": return [buildRun("\n", style)];
|
|
33
|
+
case "codeSpan": return [buildRun(node.literal, style, require_shared_style_constants.MONOSPACE_FONT_FAMILY)];
|
|
34
|
+
case "rawHtml":
|
|
35
|
+
if (context.rawHtml === "drop") {
|
|
36
|
+
context.sink({
|
|
37
|
+
code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.RAW_HTML_DROPPED,
|
|
38
|
+
severity: "info",
|
|
39
|
+
message: "inline raw HTML was dropped per the rawHtml: \"drop\" option"
|
|
40
|
+
});
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
context.sink({
|
|
44
|
+
code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.RAW_HTML_PRESERVED_AS_TEXT,
|
|
45
|
+
severity: "info",
|
|
46
|
+
message: "inline raw HTML was preserved as literal text; it will not be rendered as HTML by any consumer of the resulting ContentDocument"
|
|
47
|
+
});
|
|
48
|
+
return node.literal.length === 0 ? [] : [buildRun(node.literal, style)];
|
|
49
|
+
case "autolink": {
|
|
50
|
+
const destination = node.email ? `mailto:${node.destination}` : node.destination;
|
|
51
|
+
return [buildRun(node.destination, {
|
|
52
|
+
...style,
|
|
53
|
+
hyperlink: destination
|
|
54
|
+
})];
|
|
55
|
+
}
|
|
56
|
+
case "link": {
|
|
57
|
+
if (node.title !== void 0) context.sink({
|
|
58
|
+
code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.LINK_TITLE_DROPPED,
|
|
59
|
+
severity: "info",
|
|
60
|
+
message: `link title "${node.title}" has no ContentRun equivalent and was dropped`
|
|
61
|
+
});
|
|
62
|
+
const childStyle = {
|
|
63
|
+
...style,
|
|
64
|
+
hyperlink: node.destination
|
|
65
|
+
};
|
|
66
|
+
const runs = node.children.flatMap((child) => lowerInlineNode(child, childStyle, context));
|
|
67
|
+
return runs.length > 0 ? runs : [buildRun("", childStyle)];
|
|
68
|
+
}
|
|
69
|
+
case "image":
|
|
70
|
+
if (node.title !== void 0) context.sink({
|
|
71
|
+
code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.LINK_TITLE_DROPPED,
|
|
72
|
+
severity: "info",
|
|
73
|
+
message: `image title "${node.title}" has no ContentRun equivalent and was dropped`
|
|
74
|
+
});
|
|
75
|
+
return [buildRun(node.alt, {
|
|
76
|
+
...style,
|
|
77
|
+
hyperlink: node.destination
|
|
78
|
+
})];
|
|
79
|
+
case "emphasis": return lowerNestedEmphasisLike("italic", node, style, context);
|
|
80
|
+
case "strong": return lowerNestedEmphasisLike("bold", node, style, context);
|
|
81
|
+
case "strikethrough": return lowerNestedEmphasisLike("strike", node, style, context);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function lowerInlineNodes(nodes, context) {
|
|
85
|
+
return nodes.flatMap((node) => lowerInlineNode(node, {}, context));
|
|
86
|
+
}
|
|
87
|
+
function lowerCodeBlockRun(literal) {
|
|
88
|
+
return {
|
|
89
|
+
text: literal,
|
|
90
|
+
fontFamily: require_shared_style_constants.MONOSPACE_FONT_FAMILY
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
exports.lowerCodeBlockRun = lowerCodeBlockRun;
|
|
95
|
+
exports.lowerInlineNode = lowerInlineNode;
|
|
96
|
+
exports.lowerInlineNodes = lowerInlineNodes;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { g as MarkdownInlineNode } from "../ast-BXYwy08e.cjs";
|
|
2
|
+
import { i as MarkdownDiagnosticSink } from "../diagnostics-DmuWc7d8.cjs";
|
|
3
|
+
import { ContentRun } from "document-schema.js";
|
|
4
|
+
//#region src/lower/inline.d.ts
|
|
5
|
+
interface InlineLowerContext {
|
|
6
|
+
readonly sink: MarkdownDiagnosticSink;
|
|
7
|
+
readonly rawHtml: 'preserve' | 'drop';
|
|
8
|
+
}
|
|
9
|
+
interface RunStyle {
|
|
10
|
+
readonly bold?: boolean;
|
|
11
|
+
readonly italic?: boolean;
|
|
12
|
+
readonly strike?: boolean;
|
|
13
|
+
readonly hyperlink?: string;
|
|
14
|
+
}
|
|
15
|
+
declare function lowerInlineNode(node: MarkdownInlineNode, style: RunStyle, context: InlineLowerContext): ContentRun[];
|
|
16
|
+
declare function lowerInlineNodes(nodes: readonly MarkdownInlineNode[], context: InlineLowerContext): ContentRun[];
|
|
17
|
+
declare function lowerCodeBlockRun(literal: string): ContentRun;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { InlineLowerContext, lowerCodeBlockRun, lowerInlineNode, lowerInlineNodes };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { g as MarkdownInlineNode } from "../ast-BXYwy08e.js";
|
|
2
|
+
import { i as MarkdownDiagnosticSink } from "../diagnostics-DmuWc7d8.js";
|
|
3
|
+
import { ContentRun } from "document-schema.js";
|
|
4
|
+
//#region src/lower/inline.d.ts
|
|
5
|
+
interface InlineLowerContext {
|
|
6
|
+
readonly sink: MarkdownDiagnosticSink;
|
|
7
|
+
readonly rawHtml: 'preserve' | 'drop';
|
|
8
|
+
}
|
|
9
|
+
interface RunStyle {
|
|
10
|
+
readonly bold?: boolean;
|
|
11
|
+
readonly italic?: boolean;
|
|
12
|
+
readonly strike?: boolean;
|
|
13
|
+
readonly hyperlink?: string;
|
|
14
|
+
}
|
|
15
|
+
declare function lowerInlineNode(node: MarkdownInlineNode, style: RunStyle, context: InlineLowerContext): ContentRun[];
|
|
16
|
+
declare function lowerInlineNodes(nodes: readonly MarkdownInlineNode[], context: InlineLowerContext): ContentRun[];
|
|
17
|
+
declare function lowerCodeBlockRun(literal: string): ContentRun;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { InlineLowerContext, lowerCodeBlockRun, lowerInlineNode, lowerInlineNodes };
|