markdown-codec 4.0.14 → 4.1.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/README.md +13 -12
- package/dist/block/block.d.cts +3 -3
- package/dist/block/block.d.ts +3 -3
- package/dist/block/definitions.d.cts +2 -2
- package/dist/block/definitions.d.ts +2 -2
- package/dist/codec.d.cts +20 -0
- package/dist/codec.d.ts +20 -0
- package/dist/diagnostics/diagnostics.cjs +12 -4
- package/dist/diagnostics/diagnostics.d.cts +2 -2
- package/dist/diagnostics/diagnostics.d.ts +2 -2
- package/dist/diagnostics/diagnostics.js +12 -5
- package/dist/{diagnostics-BWK1iGy7.d.cts → diagnostics-CUMLtGHJ.d.cts} +7 -5
- package/dist/{diagnostics-BWK1iGy7.d.ts → diagnostics-CUMLtGHJ.d.ts} +7 -5
- package/dist/emit/emit.cjs +93 -27
- package/dist/emit/emit.js +96 -30
- package/dist/emit/inline.cjs +22 -14
- package/dist/emit/inline.d.cts +7 -5
- package/dist/emit/inline.d.ts +7 -5
- package/dist/emit/inline.js +21 -15
- package/dist/emit/table.cjs +1 -1
- package/dist/emit/table.d.cts +1 -1
- package/dist/emit/table.d.ts +1 -1
- package/dist/emit/table.js +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/inline/inline.d.cts +1 -1
- package/dist/inline/inline.d.ts +1 -1
- package/dist/inline/link.d.cts +17 -1
- package/dist/inline/link.d.ts +17 -1
- package/dist/{inline-CXVQWQnW.d.cts → inline-CoS1JzxI.d.cts} +1 -1
- package/dist/{inline-B_V7bs5j.d.ts → inline-OGXVE6hB.d.ts} +1 -1
- package/dist/lower/front-matter.cjs +7 -4
- package/dist/lower/front-matter.d.cts +2 -1
- package/dist/lower/front-matter.d.ts +2 -1
- package/dist/lower/front-matter.js +7 -4
- package/dist/lower/inline.cjs +73 -29
- package/dist/lower/inline.d.cts +7 -10
- package/dist/lower/inline.d.ts +7 -10
- package/dist/lower/inline.js +74 -29
- package/dist/lower/lower.cjs +140 -71
- package/dist/lower/lower.d.cts +8 -1
- package/dist/lower/lower.d.ts +8 -1
- package/dist/lower/lower.js +142 -74
- package/dist/lower/table.cjs +3 -2
- package/dist/lower/table.js +3 -2
- package/dist/options/options.d.cts +1 -1
- package/dist/options/options.d.ts +1 -1
- package/dist/read.cjs +45 -9
- package/dist/read.d.cts +1 -1
- package/dist/read.d.ts +1 -1
- package/dist/read.js +46 -10
- package/dist/shared/list-id.cjs +6 -0
- package/dist/shared/list-id.d.cts +2 -1
- package/dist/shared/list-id.d.ts +2 -1
- package/dist/shared/list-id.js +6 -1
- package/dist/write.cjs +31 -4
- package/dist/write.js +31 -4
- package/package.json +2 -2
- package/dist/link-Dv4kxVjk.d.cts +0 -18
- package/dist/link-Dv4kxVjk.d.ts +0 -18
package/dist/write.js
CHANGED
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
import { MarkdownDiagnosticCodes, MarkdownPackageFlattenError, MarkdownUnsupportedDocumentKindError, NOOP_MARKDOWN_DIAGNOSTIC_SINK } from "./diagnostics/diagnostics.js";
|
|
2
|
+
import { emitFrontMatter } from "./emit/front-matter.js";
|
|
3
|
+
import { escapeLinkDestination, renderLinkTitle } from "./emit/inline.js";
|
|
2
4
|
import { emitMarkdown } from "./emit/emit.js";
|
|
3
5
|
import { flattenPackage } from "document-schema.js";
|
|
4
6
|
//#region src/write.ts
|
|
5
|
-
function
|
|
7
|
+
function renderLinkDefinition(label, entry) {
|
|
8
|
+
const destination = entry.destination;
|
|
9
|
+
const title = entry.title;
|
|
10
|
+
if (typeof destination !== "string") return;
|
|
11
|
+
if (title !== void 0 && typeof title !== "string") return;
|
|
12
|
+
return `[${label}]: ${escapeLinkDestination(destination)}${title === void 0 ? "" : ` "${renderLinkTitle(title)}"`}`;
|
|
13
|
+
}
|
|
14
|
+
function renderLinkDefinitions(definitions) {
|
|
15
|
+
const lines = [];
|
|
16
|
+
for (const [label, entry] of Object.entries(definitions)) {
|
|
17
|
+
const line = renderLinkDefinition(label, entry);
|
|
18
|
+
if (line !== void 0) lines.push(line);
|
|
19
|
+
}
|
|
20
|
+
return lines.length > 0 ? lines.join("\n") : void 0;
|
|
21
|
+
}
|
|
22
|
+
function reportDroppedPackageTables(documentPackage, definitionsRendered, sink) {
|
|
23
|
+
const definitions = documentPackage.definitions;
|
|
6
24
|
const tables = [
|
|
7
|
-
["definitions",
|
|
25
|
+
["definitions", definitions !== void 0 && !definitionsRendered && Object.keys(definitions).length > 0],
|
|
8
26
|
["layers", documentPackage.layers !== void 0 && Object.keys(documentPackage.layers).length > 0],
|
|
9
27
|
["attachments", documentPackage.attachments !== void 0 && Object.keys(documentPackage.attachments).length > 0],
|
|
10
28
|
["destinations", documentPackage.destinations !== void 0 && Object.keys(documentPackage.destinations).length > 0],
|
|
@@ -22,14 +40,23 @@ function reportDroppedPackageTables(documentPackage, sink) {
|
|
|
22
40
|
function writeMarkdown(documentPackage, options = {}) {
|
|
23
41
|
options.signal?.throwIfAborted();
|
|
24
42
|
if (documentPackage.kind !== "wordprocessing") throw new MarkdownUnsupportedDocumentKindError(documentPackage.kind);
|
|
25
|
-
|
|
43
|
+
const sink = options.sink ?? NOOP_MARKDOWN_DIAGNOSTIC_SINK;
|
|
44
|
+
const definitionsBlock = documentPackage.definitions === void 0 ? void 0 : renderLinkDefinitions(documentPackage.definitions);
|
|
45
|
+
reportDroppedPackageTables(documentPackage, definitionsBlock !== void 0, sink);
|
|
26
46
|
let flattened;
|
|
27
47
|
try {
|
|
28
48
|
flattened = flattenPackage(documentPackage);
|
|
29
49
|
} catch (error) {
|
|
30
50
|
throw new MarkdownPackageFlattenError(error);
|
|
31
51
|
}
|
|
32
|
-
|
|
52
|
+
const body = writeMarkdownContent(flattened, {
|
|
53
|
+
...options,
|
|
54
|
+
frontMatter: false
|
|
55
|
+
});
|
|
56
|
+
const frontMatterResidue = documentPackage.source?.frontmatter;
|
|
57
|
+
const frontMatter = options.frontMatter === true ? frontMatterResidue?.format === "markdown" ? frontMatterResidue.xml : emitFrontMatter(flattened.metadata) : void 0;
|
|
58
|
+
const withFrontMatter = frontMatter === void 0 ? body : `${frontMatter}\n\n${body}`;
|
|
59
|
+
return definitionsBlock === void 0 ? withFrontMatter : withFrontMatter.length > 0 ? `${withFrontMatter}\n\n${definitionsBlock}` : definitionsBlock;
|
|
33
60
|
}
|
|
34
61
|
function writeMarkdownContent(document, options = {}) {
|
|
35
62
|
options.signal?.throwIfAborted();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markdown-codec",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "Hand-written CommonMark+GFM <-> DocumentPackage codec, built on document-schema.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"license": "MIT",
|
|
82
82
|
"packageManager": "pnpm@11.6.0",
|
|
83
83
|
"dependencies": {
|
|
84
|
-
"document-schema.js": "^4.
|
|
84
|
+
"document-schema.js": "^4.8.0",
|
|
85
85
|
"zod": "^4.4.3"
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|
package/dist/link-Dv4kxVjk.d.cts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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 };
|
package/dist/link-Dv4kxVjk.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
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 };
|