markdown-codec 5.0.3 → 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 CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  [![GitHub](https://img.shields.io/badge/GitHub-181717?logo=github&logoColor=white)](https://github.com/ExaDev/documents.js/tree/main/packages/markdown-codec) [![npm](https://img.shields.io/badge/npm-CB3837?logo=npm&logoColor=white)](https://www.npmjs.com/package/markdown-codec) [![npm version](https://img.shields.io/npm/v/markdown-codec)](https://www.npmjs.com/package/markdown-codec) [![CI](https://img.shields.io/github/actions/workflow/status/ExaDev/documents.js/ci.yml?branch=main)](https://github.com/ExaDev/documents.js/actions)
4
4
 
5
- > Hand-written CommonMark+GFM ⇄ `DocumentPackage` codec, built on [document-schema.js](../document-schema.js/README.md).
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 `DocumentPackage`; `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).
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 `DocumentPackage` — 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.
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 `flattenPackage`. 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 `DocumentPackage`'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.
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: `DocumentPackage` and `ContentDocument`
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 `DocumentPackage` a serialised artefact carries — sections, headings, lists, and construct boundaries as real nested groups, plus a styles table minted over repeated property tuples. `assemblePackage` goes flat → tree (`decompose` then `factorStyles`), `flattenPackage` goes tree → flat. Only one direction is a genuine round trip: `flattenPackage(assemblePackage(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). `assemblePackage(flattenPackage(documentPackage))` does not, in general, reproduce `documentPackage` — a package carrying `definitions`/`layers`/`attachments`/`destinations`/`pages` loses all of them on the way through `flattenPackage`, which carries forward only `metadata` and `symbolTable` (see [Gotchas](#gotchas-and-quirks)).
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` | `DocumentPackage` |
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 `assemblePackage` over `readMarkdownContent`, `writeMarkdown` is `flattenPackage` 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.
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`/`flattenPackage` 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.
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 `DocumentPackage`, and `readMarkdownContent`/`writeMarkdownContent`/`markdownContentCodec` over `ContentDocument`. The tree-form functions are thin compositions of `document-schema.js`'s `assemblePackage`/`flattenPackage` onto the flat ones; no conversion logic of their own lives here.
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 `DocumentPackage`'s own `definitions`/`layers`/`attachments`/`destinations`/`pages` table has no flat-`ContentDocument` home (`flattenPackage`'s own envelope carries forward only `metadata` and `symbolTable`); fires once per non-empty table present.
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 `DocumentPackage` `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: `DocumentPackage` 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`/`flattenPackage` 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`.
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`, `DocumentPackage`) and the `assemblePackage`/`flattenPackage` transform between them.
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.DocumentPackageSchema, {
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.d.cts CHANGED
@@ -86,9 +86,9 @@ declare const markdownCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uin
86
86
  symbol: z.ZodString;
87
87
  name: z.ZodOptional<z.ZodString>;
88
88
  dimension: z.ZodRecord<z.ZodEnum<{
89
+ time: "time";
89
90
  length: "length";
90
91
  mass: "mass";
91
- time: "time";
92
92
  electricCurrent: "electricCurrent";
93
93
  thermodynamicTemperature: "thermodynamicTemperature";
94
94
  amountOfSubstance: "amountOfSubstance";
@@ -212,9 +212,9 @@ declare const markdownCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uin
212
212
  symbol: z.ZodString;
213
213
  name: z.ZodOptional<z.ZodString>;
214
214
  dimension: z.ZodRecord<z.ZodEnum<{
215
+ time: "time";
215
216
  length: "length";
216
217
  mass: "mass";
217
- time: "time";
218
218
  electricCurrent: "electricCurrent";
219
219
  thermodynamicTemperature: "thermodynamicTemperature";
220
220
  amountOfSubstance: "amountOfSubstance";
@@ -338,9 +338,9 @@ declare const markdownCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uin
338
338
  symbol: z.ZodString;
339
339
  name: z.ZodOptional<z.ZodString>;
340
340
  dimension: z.ZodRecord<z.ZodEnum<{
341
+ time: "time";
341
342
  length: "length";
342
343
  mass: "mass";
343
- time: "time";
344
344
  electricCurrent: "electricCurrent";
345
345
  thermodynamicTemperature: "thermodynamicTemperature";
346
346
  amountOfSubstance: "amountOfSubstance";
@@ -464,9 +464,9 @@ declare const markdownCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uin
464
464
  symbol: z.ZodString;
465
465
  name: z.ZodOptional<z.ZodString>;
466
466
  dimension: z.ZodRecord<z.ZodEnum<{
467
+ time: "time";
467
468
  length: "length";
468
469
  mass: "mass";
469
- time: "time";
470
470
  electricCurrent: "electricCurrent";
471
471
  thermodynamicTemperature: "thermodynamicTemperature";
472
472
  amountOfSubstance: "amountOfSubstance";
@@ -619,9 +619,9 @@ declare const markdownCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uin
619
619
  symbol: z.ZodString;
620
620
  name: z.ZodOptional<z.ZodString>;
621
621
  dimension: z.ZodRecord<z.ZodEnum<{
622
+ time: "time";
622
623
  length: "length";
623
624
  mass: "mass";
624
- time: "time";
625
625
  electricCurrent: "electricCurrent";
626
626
  thermodynamicTemperature: "thermodynamicTemperature";
627
627
  amountOfSubstance: "amountOfSubstance";
@@ -712,9 +712,9 @@ declare const markdownContentCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffe
712
712
  symbol: z.ZodString;
713
713
  name: z.ZodOptional<z.ZodString>;
714
714
  dimension: z.ZodRecord<z.ZodEnum<{
715
+ time: "time";
715
716
  length: "length";
716
717
  mass: "mass";
717
- time: "time";
718
718
  electricCurrent: "electricCurrent";
719
719
  thermodynamicTemperature: "thermodynamicTemperature";
720
720
  amountOfSubstance: "amountOfSubstance";
@@ -835,9 +835,9 @@ declare const markdownContentCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffe
835
835
  symbol: z.ZodString;
836
836
  name: z.ZodOptional<z.ZodString>;
837
837
  dimension: z.ZodRecord<z.ZodEnum<{
838
+ time: "time";
838
839
  length: "length";
839
840
  mass: "mass";
840
- time: "time";
841
841
  electricCurrent: "electricCurrent";
842
842
  thermodynamicTemperature: "thermodynamicTemperature";
843
843
  amountOfSubstance: "amountOfSubstance";
@@ -1193,9 +1193,9 @@ declare const markdownContentCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffe
1193
1193
  symbol: z.ZodString;
1194
1194
  name: z.ZodOptional<z.ZodString>;
1195
1195
  dimension: z.ZodRecord<z.ZodEnum<{
1196
+ time: "time";
1196
1197
  length: "length";
1197
1198
  mass: "mass";
1198
- time: "time";
1199
1199
  electricCurrent: "electricCurrent";
1200
1200
  thermodynamicTemperature: "thermodynamicTemperature";
1201
1201
  amountOfSubstance: "amountOfSubstance";
@@ -1560,9 +1560,9 @@ declare const markdownContentCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffe
1560
1560
  symbol: z.ZodString;
1561
1561
  name: z.ZodOptional<z.ZodString>;
1562
1562
  dimension: z.ZodRecord<z.ZodEnum<{
1563
+ time: "time";
1563
1564
  length: "length";
1564
1565
  mass: "mass";
1565
- time: "time";
1566
1566
  electricCurrent: "electricCurrent";
1567
1567
  thermodynamicTemperature: "thermodynamicTemperature";
1568
1568
  amountOfSubstance: "amountOfSubstance";
@@ -1646,9 +1646,9 @@ declare const markdownContentCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffe
1646
1646
  symbol: z.ZodString;
1647
1647
  name: z.ZodOptional<z.ZodString>;
1648
1648
  dimension: z.ZodRecord<z.ZodEnum<{
1649
+ time: "time";
1649
1650
  length: "length";
1650
1651
  mass: "mass";
1651
- time: "time";
1652
1652
  electricCurrent: "electricCurrent";
1653
1653
  thermodynamicTemperature: "thermodynamicTemperature";
1654
1654
  amountOfSubstance: "amountOfSubstance";
package/dist/codec.d.ts CHANGED
@@ -86,9 +86,9 @@ declare const markdownCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uin
86
86
  symbol: z.ZodString;
87
87
  name: z.ZodOptional<z.ZodString>;
88
88
  dimension: z.ZodRecord<z.ZodEnum<{
89
+ time: "time";
89
90
  length: "length";
90
91
  mass: "mass";
91
- time: "time";
92
92
  electricCurrent: "electricCurrent";
93
93
  thermodynamicTemperature: "thermodynamicTemperature";
94
94
  amountOfSubstance: "amountOfSubstance";
@@ -212,9 +212,9 @@ declare const markdownCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uin
212
212
  symbol: z.ZodString;
213
213
  name: z.ZodOptional<z.ZodString>;
214
214
  dimension: z.ZodRecord<z.ZodEnum<{
215
+ time: "time";
215
216
  length: "length";
216
217
  mass: "mass";
217
- time: "time";
218
218
  electricCurrent: "electricCurrent";
219
219
  thermodynamicTemperature: "thermodynamicTemperature";
220
220
  amountOfSubstance: "amountOfSubstance";
@@ -338,9 +338,9 @@ declare const markdownCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uin
338
338
  symbol: z.ZodString;
339
339
  name: z.ZodOptional<z.ZodString>;
340
340
  dimension: z.ZodRecord<z.ZodEnum<{
341
+ time: "time";
341
342
  length: "length";
342
343
  mass: "mass";
343
- time: "time";
344
344
  electricCurrent: "electricCurrent";
345
345
  thermodynamicTemperature: "thermodynamicTemperature";
346
346
  amountOfSubstance: "amountOfSubstance";
@@ -464,9 +464,9 @@ declare const markdownCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uin
464
464
  symbol: z.ZodString;
465
465
  name: z.ZodOptional<z.ZodString>;
466
466
  dimension: z.ZodRecord<z.ZodEnum<{
467
+ time: "time";
467
468
  length: "length";
468
469
  mass: "mass";
469
- time: "time";
470
470
  electricCurrent: "electricCurrent";
471
471
  thermodynamicTemperature: "thermodynamicTemperature";
472
472
  amountOfSubstance: "amountOfSubstance";
@@ -619,9 +619,9 @@ declare const markdownCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffer>, Uin
619
619
  symbol: z.ZodString;
620
620
  name: z.ZodOptional<z.ZodString>;
621
621
  dimension: z.ZodRecord<z.ZodEnum<{
622
+ time: "time";
622
623
  length: "length";
623
624
  mass: "mass";
624
- time: "time";
625
625
  electricCurrent: "electricCurrent";
626
626
  thermodynamicTemperature: "thermodynamicTemperature";
627
627
  amountOfSubstance: "amountOfSubstance";
@@ -712,9 +712,9 @@ declare const markdownContentCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffe
712
712
  symbol: z.ZodString;
713
713
  name: z.ZodOptional<z.ZodString>;
714
714
  dimension: z.ZodRecord<z.ZodEnum<{
715
+ time: "time";
715
716
  length: "length";
716
717
  mass: "mass";
717
- time: "time";
718
718
  electricCurrent: "electricCurrent";
719
719
  thermodynamicTemperature: "thermodynamicTemperature";
720
720
  amountOfSubstance: "amountOfSubstance";
@@ -835,9 +835,9 @@ declare const markdownContentCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffe
835
835
  symbol: z.ZodString;
836
836
  name: z.ZodOptional<z.ZodString>;
837
837
  dimension: z.ZodRecord<z.ZodEnum<{
838
+ time: "time";
838
839
  length: "length";
839
840
  mass: "mass";
840
- time: "time";
841
841
  electricCurrent: "electricCurrent";
842
842
  thermodynamicTemperature: "thermodynamicTemperature";
843
843
  amountOfSubstance: "amountOfSubstance";
@@ -1193,9 +1193,9 @@ declare const markdownContentCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffe
1193
1193
  symbol: z.ZodString;
1194
1194
  name: z.ZodOptional<z.ZodString>;
1195
1195
  dimension: z.ZodRecord<z.ZodEnum<{
1196
+ time: "time";
1196
1197
  length: "length";
1197
1198
  mass: "mass";
1198
- time: "time";
1199
1199
  electricCurrent: "electricCurrent";
1200
1200
  thermodynamicTemperature: "thermodynamicTemperature";
1201
1201
  amountOfSubstance: "amountOfSubstance";
@@ -1560,9 +1560,9 @@ declare const markdownContentCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffe
1560
1560
  symbol: z.ZodString;
1561
1561
  name: z.ZodOptional<z.ZodString>;
1562
1562
  dimension: z.ZodRecord<z.ZodEnum<{
1563
+ time: "time";
1563
1564
  length: "length";
1564
1565
  mass: "mass";
1565
- time: "time";
1566
1566
  electricCurrent: "electricCurrent";
1567
1567
  thermodynamicTemperature: "thermodynamicTemperature";
1568
1568
  amountOfSubstance: "amountOfSubstance";
@@ -1646,9 +1646,9 @@ declare const markdownContentCodec: z.ZodCodec<z.ZodCustom<Uint8Array<ArrayBuffe
1646
1646
  symbol: z.ZodString;
1647
1647
  name: z.ZodOptional<z.ZodString>;
1648
1648
  dimension: z.ZodRecord<z.ZodEnum<{
1649
+ time: "time";
1649
1650
  length: "length";
1650
1651
  mass: "mass";
1651
- time: "time";
1652
1652
  electricCurrent: "electricCurrent";
1653
1653
  thermodynamicTemperature: "thermodynamicTemperature";
1654
1654
  amountOfSubstance: "amountOfSubstance";
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, DocumentPackageSchema } from "document-schema.js";
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, DocumentPackageSchema, {
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.assemblePackage)(detail.document);
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, DocumentPackage } from "document-schema.js";
3
+ import { ContentDocument, DocumentTree } from "document-schema.js";
4
4
  //#region src/read.d.ts
5
5
  interface ReadMarkdownResult {
6
- readonly documentPackage: 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, DocumentPackage } from "document-schema.js";
3
+ import { ContentDocument, DocumentTree } from "document-schema.js";
4
4
  //#region src/read.d.ts
5
5
  interface ReadMarkdownResult {
6
- readonly documentPackage: 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 { assemblePackage } from "document-schema.js";
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 = assemblePackage(detail.document);
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; flattenPackage's envelope carries forward only metadata and symbolTable, so "${name}" is dropped rather than rendered`
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.flattenPackage)(documentPackage);
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, DocumentPackage } from "document-schema.js";
2
+ import { ContentDocument, DocumentTree } from "document-schema.js";
3
3
  //#region src/write.d.ts
4
- declare function writeMarkdown(documentPackage: DocumentPackage, options?: WriteMarkdownOptions): string;
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, DocumentPackage } from "document-schema.js";
2
+ import { ContentDocument, DocumentTree } from "document-schema.js";
3
3
  //#region src/write.d.ts
4
- declare function writeMarkdown(documentPackage: DocumentPackage, options?: WriteMarkdownOptions): string;
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 { flattenPackage } from "document-schema.js";
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; flattenPackage's envelope carries forward only metadata and symbolTable, so "${name}" is dropped rather than rendered`
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 = flattenPackage(documentPackage);
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": "5.0.3",
4
- "description": "Hand-written CommonMark+GFM <-> DocumentPackage codec, built on document-schema.js",
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": "^4.10.0",
84
+ "document-schema.js": "^5.0.0",
85
85
  "zod": "^4.4.3"
86
86
  },
87
87
  "devDependencies": {