markdown-codec 5.0.2 → 6.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/README.md +14 -14
- package/dist/codec.cjs +1 -1
- package/dist/codec.js +2 -2
- package/dist/read.cjs +1 -1
- package/dist/read.d.cts +2 -2
- package/dist/read.d.ts +2 -2
- package/dist/read.js +2 -2
- package/dist/write.cjs +2 -2
- package/dist/write.d.cts +2 -2
- package/dist/write.d.ts +2 -2
- package/dist/write.js +3 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/ExaDev/documents.js/tree/main/packages/markdown-codec) [](https://www.npmjs.com/package/markdown-codec) [](https://www.npmjs.com/package/markdown-codec) [](https://github.com/ExaDev/documents.js/actions)
|
|
4
4
|
|
|
5
|
-
> Hand-written CommonMark+GFM ⇄ `
|
|
5
|
+
> Hand-written CommonMark+GFM ⇄ `DocumentTree` codec, built on [document-schema.js](../document-schema.js/README.md).
|
|
6
6
|
|
|
7
|
-
The same "hand-write the format instead of wrapping a third-party library" bet as [`pdf-codec`](../pdf-codec/README.md), aimed at CommonMark and GFM. No `micromark`/`remark`/`marked`/`markdown-it`/`commonmark`/`mdast`/`unified`/`turndown`/`showdown` dependency (enforced by eslint `no-restricted-imports`). Runtime dependencies: `document-schema.js` (the shared pivot) and `zod`. `readMarkdown`/`writeMarkdown` read and write that pivot's tree-form `
|
|
7
|
+
The same "hand-write the format instead of wrapping a third-party library" bet as [`pdf-codec`](../pdf-codec/README.md), aimed at CommonMark and GFM. No `micromark`/`remark`/`marked`/`markdown-it`/`commonmark`/`mdast`/`unified`/`turndown`/`showdown` dependency (enforced by eslint `no-restricted-imports`). Runtime dependencies: `document-schema.js` (the shared pivot) and `zod`. `readMarkdown`/`writeMarkdown` read and write that pivot's tree-form `DocumentTree`; `readMarkdownContent`/`writeMarkdownContent` read and write the flat `ContentDocument` underneath it — the same model [`documents.js`](https://github.com/ExaDev/documents.js) builds docx/pptx/odt/odp conversions around. See [Two encodings](#two-encodings-documentpackage-and-contentdocument).
|
|
8
8
|
|
|
9
9
|
```mermaid
|
|
10
10
|
graph TD
|
|
@@ -91,9 +91,9 @@ const markdown = writeMarkdown(documentPackage, {
|
|
|
91
91
|
});
|
|
92
92
|
```
|
|
93
93
|
|
|
94
|
-
`documentPackage` is a `
|
|
94
|
+
`documentPackage` is a `DocumentTree` — document-schema.js's tree form, with a minted styles table (see [Two encodings](#two-encodings-documentpackage-and-contentdocument)). The field is named `documentPackage` rather than `package` because `package` is a reserved word in strict mode, so `const { package } = readMarkdown(src)` would not parse.
|
|
95
95
|
|
|
96
|
-
Both accept an optional `signal` (`AbortSignal`) and `sink` (`MarkdownDiagnosticSink`, called once per recoverable issue or construct-mapping gap — see [Gotchas](#gotchas-and-quirks)). `writeMarkdown` throws `MarkdownUnsupportedDocumentKindError` for a package whose `kind` is not `'wordprocessing'`, checked before flattening so every non-`'wordprocessing'` package reaches it the same way regardless of what else about that package would have failed document-schema.js's own `
|
|
96
|
+
Both accept an optional `signal` (`AbortSignal`) and `sink` (`MarkdownDiagnosticSink`, called once per recoverable issue or construct-mapping gap — see [Gotchas](#gotchas-and-quirks)). `writeMarkdown` throws `MarkdownUnsupportedDocumentKindError` for a package whose `kind` is not `'wordprocessing'`, checked before flattening so every non-`'wordprocessing'` package reaches it the same way regardless of what else about that package would have failed document-schema.js's own `flattenTree`. A `'wordprocessing'` package can still fail to flatten — a group carrying a style reference the package's own `styles` table has no entry for — and that failure surfaces as `MarkdownPackageFlattenError`, not a bare `Error` from the dependency. A `DocumentTree`'s own `layers`/`attachments`/`destinations`/`pages` tables have no flat-`ContentDocument` home to land in; `writeMarkdown` reports one `PACKAGE_TABLE_DROPPED` diagnostic per non-empty table it finds rather than dropping them without a trace. The `definitions` table is the one exemption: this package's own link-tenant entries (what `readMarkdown` splices there from the source's reference definitions) render back out as `[label]: destination "title"` lines, so only a table holding foreign tenants reports.
|
|
97
97
|
|
|
98
98
|
The same round trip as a schema-validated [`z.codec()`](https://zod.dev) pair, mirroring `pdf-codec`'s `pdfCodec`:
|
|
99
99
|
|
|
@@ -107,20 +107,20 @@ const bytes2 = z.encode(markdownCodec, documentPackage);
|
|
|
107
107
|
|
|
108
108
|
`MarkdownBytesSchema` checks for well-formed UTF-8. The no-options form only; `readMarkdown`/`writeMarkdown` remain the entry points for an `AbortSignal` or diagnostic sink. Every construct-mapping gap reports through the sink as a stable code (e.g. `md/nested-emphasis-flattened`) — see `MarkdownDiagnosticCodes` and [Gotchas](#gotchas-and-quirks).
|
|
109
109
|
|
|
110
|
-
## Two encodings: `
|
|
110
|
+
## Two encodings: `DocumentTree` and `ContentDocument`
|
|
111
111
|
|
|
112
|
-
document-schema.js states one document in two shapes, and owns the transform between them: the flat `ContentDocument` every codec's lowering pipeline actually builds, and the tree-form `
|
|
112
|
+
document-schema.js states one document in two shapes, and owns the transform between them: the flat `ContentDocument` every codec's lowering pipeline actually builds, and the tree-form `DocumentTree` a serialised artefact carries — sections, headings, lists, and construct boundaries as real nested groups, plus a styles table minted over repeated property tuples. `assembleTree` goes flat → tree (`decompose` then `factorStyles`), `flattenTree` goes tree → flat. Only one direction is a genuine round trip: `flattenTree(assembleTree(document))` reproduces `document` exactly, for any `ContentDocument` this package's own read side produces (checked against the full CommonMark and GFM conformance corpora, not just a hand-picked fixture — see `src/conformance.test.ts`/`src/gfm-conformance.test.ts`'s own "tree pair matches the flat pair" suite). `assembleTree(flattenTree(documentPackage))` does not, in general, reproduce `documentPackage` — a package carrying `definitions`/`layers`/`attachments`/`destinations`/`pages` loses all of them on the way through `flattenTree`, which carries forward only `metadata` and `symbolTable` (see [Gotchas](#gotchas-and-quirks)).
|
|
113
113
|
|
|
114
114
|
This package exposes a read/write pair and a codec at each level. The unsuffixed names are the tree-form ones and are what to reach for by default — a codec is a construction site, so the tree is what a caller gets unless they ask for otherwise. The `Content`-suffixed names are the flat pair one level down, mirroring the `readXlsx`/`readXlsxContent` naming already in [`ooxml.js`](../ooxml.js/README.md):
|
|
115
115
|
|
|
116
116
|
| Level | Read | Write | Codec | Value type |
|
|
117
117
|
| --- | --- | --- | --- | --- |
|
|
118
|
-
| Tree (default) | `readMarkdown` | `writeMarkdown` | `markdownCodec` | `
|
|
118
|
+
| Tree (default) | `readMarkdown` | `writeMarkdown` | `markdownCodec` | `DocumentTree` |
|
|
119
119
|
| Flat | `readMarkdownContent` | `writeMarkdownContent` | `markdownContentCodec` | `ContentDocument` |
|
|
120
120
|
|
|
121
|
-
The tree pair is the flat pair with the transform composed on — `readMarkdown` is `
|
|
121
|
+
The tree pair is the flat pair with the transform composed on — `readMarkdown` is `assembleTree` over `readMarkdownContent`, `writeMarkdown` is `flattenTree` before `writeMarkdownContent` — plus the two tree-only carries the flat form has no root for: the source's reference definitions splice into `documentPackage.definitions` (link tenant, keyed by normalised label) and the verbatim front-matter block into `documentPackage.source.frontmatter`, both rendered back out by `writeMarkdown` (`[label]: dest "title"` lines after the body; the original front matter verbatim in place of the regenerated block). Sources carrying neither render identically to the flat pair, pinned in `src/package.test.ts`; a source carrying either renders its extra block, which is the point of reaching for the tree. Options, diagnostics, and error behaviour are identical at both levels.
|
|
122
122
|
|
|
123
|
-
Reach for the flat pair when composing a package boundary by hand (`decompose`/`
|
|
123
|
+
Reach for the flat pair when composing a package boundary by hand (`decompose`/`flattenTree` directly, or `factorStyles` with your own minting policy), when feeding a `ContentDocument`-consuming builder such as `documents.js`'s conversion pipeline, or when a layout stage needs to stamp frames onto content before it is decomposed. Everything else wants the tree.
|
|
124
124
|
|
|
125
125
|
```ts
|
|
126
126
|
import { readMarkdownContent, writeMarkdownContent } from 'markdown-codec';
|
|
@@ -144,7 +144,7 @@ Modelled on `pdf-codec`'s own layering, aimed at CommonMark+GFM instead of PDF:
|
|
|
144
144
|
- **`src/shared/`** — string-shape conventions `src/lower`/`src/emit` agree on (`style-constants.ts`, `list-id.ts`'s opaque `numId`). Re-exported so `documents.js`'s `MarkdownEditor` reuses the identical grammar.
|
|
145
145
|
- **`src/lower/`** — AST → `ContentDocument` lowering (thin adapter, not a second parser); top-of-file table maps each construct to its diagnostic gap.
|
|
146
146
|
- **`src/emit/`** — `ContentDocument` → markdown text emission, the structural inverse of `src/lower`.
|
|
147
|
-
- **`src/read.ts`** / **`src/write.ts`** / **`src/codec.ts`** — the public entry points at both levels: `readMarkdown`/`writeMarkdown`/`markdownCodec` over `
|
|
147
|
+
- **`src/read.ts`** / **`src/write.ts`** / **`src/codec.ts`** — the public entry points at both levels: `readMarkdown`/`writeMarkdown`/`markdownCodec` over `DocumentTree`, and `readMarkdownContent`/`writeMarkdownContent`/`markdownContentCodec` over `ContentDocument`. The tree-form functions are thin compositions of `document-schema.js`'s `assembleTree`/`flattenTree` onto the flat ones; no conversion logic of their own lives here.
|
|
148
148
|
|
|
149
149
|
## Vendored assets
|
|
150
150
|
|
|
@@ -202,7 +202,7 @@ Every construct `src/lower`/`src/emit` cannot represent losslessly is a document
|
|
|
202
202
|
- **`md/duplicate-footnote-definition`** — two definitions share a label; every reference resolves to the first, both are kept as written.
|
|
203
203
|
- **`md/footnote-body-heading-flattened`** — a heading inside a definition body is carried as literal ATX text, since a construct extent may not open or close a heading scope.
|
|
204
204
|
- **`md/construct-unrepresented`** — a construct kind markdown has no syntax for renders transparently: its extent still appears, the construct itself does not.
|
|
205
|
-
- **`md/package-table-dropped`** — `writeMarkdown` only, ahead of flattening: a `
|
|
205
|
+
- **`md/package-table-dropped`** — `writeMarkdown` only, ahead of flattening: a `DocumentTree`'s own `definitions`/`layers`/`attachments`/`destinations`/`pages` table has no flat-`ContentDocument` home (`flattenTree`'s own envelope carries forward only `metadata` and `symbolTable`); fires once per non-empty table present.
|
|
206
206
|
|
|
207
207
|
## Footnotes
|
|
208
208
|
|
|
@@ -210,8 +210,8 @@ GitHub's footnote extension (`[^label]` markers, `[^label]: body` definitions) i
|
|
|
210
210
|
|
|
211
211
|
The two halves of a footnote map onto the **same `anchor` construct at two different scopes**, and that split is structural rather than a choice:
|
|
212
212
|
|
|
213
|
-
- **A definition becomes an `anchor` construct.** Lowering emits document-schema.js's construct boundary markers — a `constructStart` carrying `{ kind: 'anchor', anchorType: 'footnote', name }`, the definition's own lowered body blocks, and a `constructEnd` — which is what `readMarkdownContent` returns in its block flow, and what `decompose` promotes to a construct group of its own in the `
|
|
214
|
-
- **A reference site becomes a point run-level `anchor` extent.** A reference sits between two runs inside a paragraph, so no block-level boundary marker can bracket it without splitting the paragraph in two — but a run-level construct extent (`RunConstructExtent` on `ContentParagraph.constructs`, document-schema.js 4.5.0) names exactly that shape. Lowering emits an ordinary text run keeping the reference's own `[^label]` spelling (the materialised rendering, so a consumer that ignores constructs still shows `[^1]`) plus a point extent — `{ kind: 'anchor', anchorType: 'footnote', name }` at `startRun === endRun` naming that run, the same wiring ooxml.js's docx reader mints for a `w:footnoteReference` — carried through `decompose`/`
|
|
213
|
+
- **A definition becomes an `anchor` construct.** Lowering emits document-schema.js's construct boundary markers — a `constructStart` carrying `{ kind: 'anchor', anchorType: 'footnote', name }`, the definition's own lowered body blocks, and a `constructEnd` — which is what `readMarkdownContent` returns in its block flow, and what `decompose` promotes to a construct group of its own in the `DocumentTree` `readMarkdown` returns (the descriptor rides the group's `node`, the body blocks its `children`). The body rides the construct's extent rather than `AnchorDescriptor.definition`, which names a key in a package-level definitions table: `DocumentTree` does carry that table as a root (unlike the flat `ContentDocument`), but a table entry there is a flat descriptor record, not a container for block content, so a body that is genuinely several paragraphs, a code block, or a list still has nowhere to live as a table value either way — the construct's own bracketed extent is the one shape in this schema built to hold real block content. A bodyless `[^1]:` lowers to the point anchor the same descriptor describes: a pair with nothing between it.
|
|
214
|
+
- **A reference site becomes a point run-level `anchor` extent.** A reference sits between two runs inside a paragraph, so no block-level boundary marker can bracket it without splitting the paragraph in two — but a run-level construct extent (`RunConstructExtent` on `ContentParagraph.constructs`, document-schema.js 4.5.0) names exactly that shape. Lowering emits an ordinary text run keeping the reference's own `[^label]` spelling (the materialised rendering, so a consumer that ignores constructs still shows `[^1]`) plus a point extent — `{ kind: 'anchor', anchorType: 'footnote', name }` at `startRun === endRun` naming that run, the same wiring ooxml.js's docx reader mints for a `w:footnoteReference` — carried through `decompose`/`flattenTree` verbatim, exactly the way a table cell's own markers are. The writer spells `[^label]` back out from the covering extent rather than from anything about the run's text (which is what still distinguishes a genuine reference from a deliberately-escaped literal `\[^1\]`), gated by the same label grammar as the definition marker: a foreign name that grammar cannot spell degrades to the run's own escaped text plus `md/construct-unrepresented`.
|
|
215
215
|
|
|
216
216
|
Definitions are recognised only at the document's own top level. Inside a block quote or a list item, the pair's extent would sit inside a scope the enclosing container had already opened, which the marker contract forbids a producer from emitting — so the text stays an ordinary paragraph there. A heading inside a definition body is flattened to literal ATX text for the same reason.
|
|
217
217
|
|
|
@@ -245,7 +245,7 @@ Conventional Commits, enforced workspace-wide by commitlint through a root `comm
|
|
|
245
245
|
|
|
246
246
|
## References
|
|
247
247
|
|
|
248
|
-
- [document-schema.js](../document-schema.js/README.md) — owns both shared encodings (`ContentDocument`, `
|
|
248
|
+
- [document-schema.js](../document-schema.js/README.md) — owns both shared encodings (`ContentDocument`, `DocumentTree`) and the `assembleTree`/`flattenTree` transform between them.
|
|
249
249
|
- [pdf-codec](../pdf-codec/README.md) — the sibling whose scaffold, tooling, and "hand-write the format" philosophy this project mirrors.
|
|
250
250
|
- [documents.js](https://github.com/ExaDev/documents.js) — bridges markdown to docx/odt/PDF via this package's `ContentDocument` (the flat pair; its own conversion pipeline assembles the package itself). Markdown has no presentation/spreadsheet/drawing variant, so pptx/odp/ods/odg are structurally out of reach.
|
|
251
251
|
- [CommonMark Spec](https://spec.commonmark.org/) — the base specification targeted.
|
package/dist/codec.cjs
CHANGED
|
@@ -13,7 +13,7 @@ function isWellFormedUtf8Text(bytes) {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
const MarkdownBytesSchema = zod.z.instanceof(Uint8Array).refine(isWellFormedUtf8Text, { message: "not well-formed UTF-8 text" });
|
|
16
|
-
const markdownCodec = zod.z.codec(MarkdownBytesSchema, document_schema_js.
|
|
16
|
+
const markdownCodec = zod.z.codec(MarkdownBytesSchema, document_schema_js.DocumentTreeSchema, {
|
|
17
17
|
decode: (bytes) => require_read.readMarkdown(new TextDecoder().decode(bytes)).documentPackage,
|
|
18
18
|
encode: (documentPackage) => new TextEncoder().encode(require_write.writeMarkdown(documentPackage))
|
|
19
19
|
});
|
package/dist/codec.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readMarkdown, readMarkdownContent } from "./read.js";
|
|
2
2
|
import { writeMarkdown, writeMarkdownContent } from "./write.js";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { ContentDocumentSchema,
|
|
4
|
+
import { ContentDocumentSchema, DocumentTreeSchema } from "document-schema.js";
|
|
5
5
|
//#region src/codec.ts
|
|
6
6
|
function isWellFormedUtf8Text(bytes) {
|
|
7
7
|
try {
|
|
@@ -12,7 +12,7 @@ function isWellFormedUtf8Text(bytes) {
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
const MarkdownBytesSchema = z.instanceof(Uint8Array).refine(isWellFormedUtf8Text, { message: "not well-formed UTF-8 text" });
|
|
15
|
-
const markdownCodec = z.codec(MarkdownBytesSchema,
|
|
15
|
+
const markdownCodec = z.codec(MarkdownBytesSchema, DocumentTreeSchema, {
|
|
16
16
|
decode: (bytes) => readMarkdown(new TextDecoder().decode(bytes)).documentPackage,
|
|
17
17
|
encode: (documentPackage) => new TextEncoder().encode(writeMarkdown(documentPackage))
|
|
18
18
|
});
|
package/dist/read.cjs
CHANGED
|
@@ -32,7 +32,7 @@ function linkDefinitionEntries(references) {
|
|
|
32
32
|
}
|
|
33
33
|
function readMarkdown(text, options = {}) {
|
|
34
34
|
const detail = readMarkdownDetail(text, options);
|
|
35
|
-
const assembled = (0, document_schema_js.
|
|
35
|
+
const assembled = (0, document_schema_js.assembleTree)(detail.document);
|
|
36
36
|
const definitions = linkDefinitionEntries(detail.references);
|
|
37
37
|
const frontMatterResidue = detail.frontMatterSource === void 0 ? void 0 : {
|
|
38
38
|
format: "markdown",
|
package/dist/read.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as MarkdownDiagnostic } from "./diagnostics-CkcSYZf1.cjs";
|
|
2
2
|
import { ReadMarkdownOptions } from "./options/options.cjs";
|
|
3
|
-
import { ContentDocument,
|
|
3
|
+
import { ContentDocument, DocumentTree } from "document-schema.js";
|
|
4
4
|
//#region src/read.d.ts
|
|
5
5
|
interface ReadMarkdownResult {
|
|
6
|
-
readonly documentPackage:
|
|
6
|
+
readonly documentPackage: DocumentTree;
|
|
7
7
|
readonly diagnostics: readonly MarkdownDiagnostic[];
|
|
8
8
|
}
|
|
9
9
|
interface ReadMarkdownContentResult {
|
package/dist/read.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as MarkdownDiagnostic } from "./diagnostics-CkcSYZf1.js";
|
|
2
2
|
import { ReadMarkdownOptions } from "./options/options.js";
|
|
3
|
-
import { ContentDocument,
|
|
3
|
+
import { ContentDocument, DocumentTree } from "document-schema.js";
|
|
4
4
|
//#region src/read.d.ts
|
|
5
5
|
interface ReadMarkdownResult {
|
|
6
|
-
readonly documentPackage:
|
|
6
|
+
readonly documentPackage: DocumentTree;
|
|
7
7
|
readonly diagnostics: readonly MarkdownDiagnostic[];
|
|
8
8
|
}
|
|
9
9
|
interface ReadMarkdownContentResult {
|
package/dist/read.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { lowerMarkdownDetailed } from "./lower/lower.js";
|
|
2
|
-
import {
|
|
2
|
+
import { assembleTree } from "document-schema.js";
|
|
3
3
|
//#region src/read.ts
|
|
4
4
|
function readMarkdownDetail(text, options) {
|
|
5
5
|
options.signal?.throwIfAborted();
|
|
@@ -31,7 +31,7 @@ function linkDefinitionEntries(references) {
|
|
|
31
31
|
}
|
|
32
32
|
function readMarkdown(text, options = {}) {
|
|
33
33
|
const detail = readMarkdownDetail(text, options);
|
|
34
|
-
const assembled =
|
|
34
|
+
const assembled = assembleTree(detail.document);
|
|
35
35
|
const definitions = linkDefinitionEntries(detail.references);
|
|
36
36
|
const frontMatterResidue = detail.frontMatterSource === void 0 ? void 0 : {
|
|
37
37
|
format: "markdown",
|
package/dist/write.cjs
CHANGED
|
@@ -34,7 +34,7 @@ function reportDroppedPackageTables(documentPackage, definitionsRendered, sink)
|
|
|
34
34
|
sink({
|
|
35
35
|
code: require_diagnostics_diagnostics.MarkdownDiagnosticCodes.PACKAGE_TABLE_DROPPED,
|
|
36
36
|
severity: "info",
|
|
37
|
-
message: `the package's own "${name}" table has no markdown representation;
|
|
37
|
+
message: `the package's own "${name}" table has no markdown representation; flattenTree's envelope carries forward only metadata and symbolTable, so "${name}" is dropped rather than rendered`
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -46,7 +46,7 @@ function writeMarkdown(documentPackage, options = {}) {
|
|
|
46
46
|
reportDroppedPackageTables(documentPackage, definitionsBlock !== void 0, sink);
|
|
47
47
|
let flattened;
|
|
48
48
|
try {
|
|
49
|
-
flattened = (0, document_schema_js.
|
|
49
|
+
flattened = (0, document_schema_js.flattenTree)(documentPackage);
|
|
50
50
|
} catch (error) {
|
|
51
51
|
throw new require_diagnostics_diagnostics.MarkdownPackageFlattenError(error);
|
|
52
52
|
}
|
package/dist/write.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { WriteMarkdownOptions } from "./options/options.cjs";
|
|
2
|
-
import { ContentDocument,
|
|
2
|
+
import { ContentDocument, DocumentTree } from "document-schema.js";
|
|
3
3
|
//#region src/write.d.ts
|
|
4
|
-
declare function writeMarkdown(documentPackage:
|
|
4
|
+
declare function writeMarkdown(documentPackage: DocumentTree, options?: WriteMarkdownOptions): string;
|
|
5
5
|
declare function writeMarkdownContent(document: ContentDocument, options?: WriteMarkdownOptions): string;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { writeMarkdown, writeMarkdownContent };
|
package/dist/write.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { WriteMarkdownOptions } from "./options/options.js";
|
|
2
|
-
import { ContentDocument,
|
|
2
|
+
import { ContentDocument, DocumentTree } from "document-schema.js";
|
|
3
3
|
//#region src/write.d.ts
|
|
4
|
-
declare function writeMarkdown(documentPackage:
|
|
4
|
+
declare function writeMarkdown(documentPackage: DocumentTree, options?: WriteMarkdownOptions): string;
|
|
5
5
|
declare function writeMarkdownContent(document: ContentDocument, options?: WriteMarkdownOptions): string;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { writeMarkdown, writeMarkdownContent };
|
package/dist/write.js
CHANGED
|
@@ -2,7 +2,7 @@ import { MarkdownDiagnosticCodes, MarkdownPackageFlattenError, MarkdownUnsupport
|
|
|
2
2
|
import { emitFrontMatter } from "./emit/front-matter.js";
|
|
3
3
|
import { escapeLinkDestination, renderLinkTitle } from "./emit/inline.js";
|
|
4
4
|
import { emitMarkdown } from "./emit/emit.js";
|
|
5
|
-
import {
|
|
5
|
+
import { flattenTree } from "document-schema.js";
|
|
6
6
|
//#region src/write.ts
|
|
7
7
|
function renderLinkDefinition(label, entry) {
|
|
8
8
|
const destination = entry.destination;
|
|
@@ -33,7 +33,7 @@ function reportDroppedPackageTables(documentPackage, definitionsRendered, sink)
|
|
|
33
33
|
sink({
|
|
34
34
|
code: MarkdownDiagnosticCodes.PACKAGE_TABLE_DROPPED,
|
|
35
35
|
severity: "info",
|
|
36
|
-
message: `the package's own "${name}" table has no markdown representation;
|
|
36
|
+
message: `the package's own "${name}" table has no markdown representation; flattenTree's envelope carries forward only metadata and symbolTable, so "${name}" is dropped rather than rendered`
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -45,7 +45,7 @@ function writeMarkdown(documentPackage, options = {}) {
|
|
|
45
45
|
reportDroppedPackageTables(documentPackage, definitionsBlock !== void 0, sink);
|
|
46
46
|
let flattened;
|
|
47
47
|
try {
|
|
48
|
-
flattened =
|
|
48
|
+
flattened = flattenTree(documentPackage);
|
|
49
49
|
} catch (error) {
|
|
50
50
|
throw new MarkdownPackageFlattenError(error);
|
|
51
51
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markdown-codec",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Hand-written CommonMark+GFM <->
|
|
3
|
+
"version": "6.0.0",
|
|
4
|
+
"description": "Hand-written CommonMark+GFM <-> DocumentTree codec, built on document-schema.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"license": "MIT",
|
|
82
82
|
"packageManager": "pnpm@11.6.0",
|
|
83
83
|
"dependencies": {
|
|
84
|
-
"document-schema.js": "^
|
|
84
|
+
"document-schema.js": "^5.0.0",
|
|
85
85
|
"zod": "^4.4.3"
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|