@rebilder/render-md 0.1.1 → 0.3.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 +50 -13
- package/dist/index.cjs +128 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +103 -6
- package/dist/index.d.ts +103 -6
- package/dist/index.js +124 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,9 +6,9 @@ Source-of-truth → markdown/JSON-LD renderer for **any** page: commerce (PDP, p
|
|
|
6
6
|
|
|
7
7
|
**Pure format transformation.** Framework-agnostic, zero runtime dependencies, pure functions, fully deterministic: same input → same output, everywhere, every time. No LLM, no network, no clock, no locale (`Intl` is not used).
|
|
8
8
|
|
|
9
|
-
**
|
|
9
|
+
**Source-based rendering.** Every substantive value in the output — prices, availability, discounts, shipping and returns text, policy bodies, attributes, facts, hours, contact details, prose — is injected verbatim from the source object. This package never invents, estimates, or rewords a price, stock state, claim, or policy. The only text it adds is structural scaffolding, and that scaffolding is enumerated in full below. Non-integer money amounts throw rather than round: silently altering a price is never acceptable.
|
|
10
10
|
|
|
11
|
-
**Same substance across formats (
|
|
11
|
+
**Same substance across formats (consistent offer representations).** Markdown output is a format transformation of the same substance as the canonical HTML page. Rendering must never produce different prices, claims, or availability than the page a human sees; the renderer has no inputs (requester identity, headers, UA) that could even make that possible.
|
|
12
12
|
|
|
13
13
|
**Malformed input is dropped, never repaired.** A malformed date, a non-finite number, a wrapping time interval, a URL with a scheme we do not allow — each is omitted from the output. Repairing a value invents one the merchant never stated; dropping it only loses information, which the agent can still get from the canonical page.
|
|
14
14
|
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
// universal
|
|
25
25
|
renderDocumentMarkdown, // DocumentSource → any single page: facts, hours, contact, actions, prose
|
|
26
26
|
renderCollectionMarkdown, // CollectionSource → any listing page: link list or fact table
|
|
27
|
+
renderCollectionJsonLd, // CollectionSource → schema.org ItemList of positioned ListItems
|
|
27
28
|
formatMoney, // { amount: 8900, currency: 'USD' } → "$89.00" (minor units in, deterministic, zero-decimal aware: ¥4,900)
|
|
28
29
|
} from '@rebilder/render-md'
|
|
29
30
|
```
|
|
@@ -36,7 +37,37 @@ The fixed label maps (`BOOLEAN_LABELS`, `WEEKDAY_LABELS`, `PERIOD_SUFFIX`, `ACCE
|
|
|
36
37
|
|
|
37
38
|
## Rendering order (product)
|
|
38
39
|
|
|
39
|
-
Title (linked to canonical URL) → brand → price (`~~$120.00~~ $89.00` when a compare-at price exists in source) → availability → shipping → returns → variants table (id / title / options / price / availability) → description → attributes → images as markdown links. An agent reading top-down gets every buying fact in the first ~15 lines.
|
|
40
|
+
Title (linked to canonical URL) → brand → price (`~~$120.00~~ $89.00` when a compare-at price exists in source) → availability → shipping → returns → `- **Updated:**` → variants table (id / title / options / price / availability) → description → attributes → images as markdown links. An agent reading top-down gets every buying fact in the first ~15 lines.
|
|
41
|
+
|
|
42
|
+
`updated` sits at the end of the fact block rather than the start on purpose: it is metadata *about* the buying facts rather than one of them, and every line above `- **Availability:**` pushes a core fact further from the top of the document, which is a byte offset ARS D4 scores.
|
|
43
|
+
|
|
44
|
+
## Freshness and language
|
|
45
|
+
|
|
46
|
+
| Source type | `updated` | `language` |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| `ProductSource` | `dateModified` in JSON-LD, `- **Updated:**` in markdown | `inLanguage` in JSON-LD |
|
|
49
|
+
| `CollectionSource` | `dateModified` in JSON-LD | `inLanguage` in JSON-LD |
|
|
50
|
+
| `DocumentSource` | `- **Updated:**` in markdown | — |
|
|
51
|
+
|
|
52
|
+
`updated` is an ISO 8601 date or datetime; `language` is a BCP 47 tag (`en`, `pt-BR`, `zh-Hant`, `zh-Hant-TW`, `es-419`).
|
|
53
|
+
|
|
54
|
+
**`DocumentSource` has no `language` field on purpose.** There is no document JSON-LD renderer, so the only thing that consumes `language` would never see it, and a source field that silently renders nothing is a worse contract than an absent one. It arrives with `renderDocumentJsonLd`, which is unbuilt because choosing a schema.org `@type` per `DocumentKind` is an inference this package does not make — `DocumentKind` is an open union of merchant-supplied strings.
|
|
55
|
+
|
|
56
|
+
Both are **gates, never transforms.** A value that passes is emitted byte-for-byte as supplied — casing included, because BCP 47 is case-insensitive and re-casing a merchant's tag would make our JSON-LD disagree with their own `<html lang>`. A value that fails is dropped from *every* representation at once, so a fact can never be good enough for the markdown and not the JSON-LD.
|
|
57
|
+
|
|
58
|
+
The date check is a real-calendar check, not a `Date.parse` call: `Date.parse` rolls a day-of-month overflow silently forward (`2026-02-31` → March 3, `2026-02-29` → March 1 in a non-leap year), which is tolerable in a markdown line and not tolerable as `dateModified` in a product feed.
|
|
59
|
+
|
|
60
|
+
`renderProductJsonLd` feeds `/acp/v0/feed` and the MCP product tool as well as the canonical page, so anything it emits is published as an authoritative fact about the catalog.
|
|
61
|
+
|
|
62
|
+
## Collections as structured data
|
|
63
|
+
|
|
64
|
+
`renderCollectionJsonLd` renders a `CollectionSource` as a schema.org `ItemList` of positioned `ListItem`s. Three refusals are part of the contract:
|
|
65
|
+
|
|
66
|
+
- **`name` is omitted when the source has no title.** The markdown renderer falls back to the fixed `Contents` heading because a markdown document needs a heading; JSON-LD does not, and emitting the fallback would assert a name the merchant never wrote.
|
|
67
|
+
- **Item URLs pass the same scheme allowlist as the markdown path.** A rejected URL drops the link, not the item — the item still renders with its name, because dropping it would misreport the length of the listing.
|
|
68
|
+
- **`numberOfItems` counts what was emitted**, not `items.length`. Past the 500-row cap, a list announcing 900 while carrying 500 would send a paging agent after items that are not in the document.
|
|
69
|
+
|
|
70
|
+
Item facts are deliberately not projected into the list: `ListItem` has no honest slot for an arbitrary labelled fact, and inventing property names for merchant labels is the kind of inference this package does not do. The facts are in the markdown table.
|
|
40
71
|
|
|
41
72
|
## The universal surface
|
|
42
73
|
|
|
@@ -76,7 +107,7 @@ Two ceilings, not one. `maxBytes` (default **5120**) governs the truncatable tai
|
|
|
76
107
|
|
|
77
108
|
**Hours.** All seven weekdays always render. A weekday absent from `weekly` is `Not stated`; a weekday present with `intervals: []` is `Closed`. Those are different facts and collapsing them would assert a closure the merchant never stated. An interval where `closes <= opens` is malformed — overnight spans are expressed as two intervals on two days — and one malformed interval drops the whole hours fact, because a table missing exactly the day that was broken reads as authoritative and is not. Nothing here computes "open now": that needs a clock and a timezone database, and a wrong answer to "are they open" is worse than no answer.
|
|
78
109
|
|
|
79
|
-
**Access gate.** `sections` is emitted **only** when `access === 'free'`. `registered`, `metered`, and `subscriber` emit summary + facts + contact + actions + a fixed access notice, and never touch `sections`. This is mechanical, not a prose rule:
|
|
110
|
+
**Access gate.** `sections` is emitted **only** when `access === 'free'`. `registered`, `metered`, and `subscriber` emit summary + facts + contact + actions + a fixed access notice, and never touch `sections`. This is mechanical, not a prose rule: the renderer omits those bodies on the tested restricted-access paths.
|
|
80
111
|
|
|
81
112
|
**Dedup.** If `DocumentSource.updated` is set and valid, a fact labelled `Updated` is dropped. Two "Updated" lines disagreeing is worse than one that might be stale.
|
|
82
113
|
|
|
@@ -109,19 +140,15 @@ The complete list of renderer-authored text. Nothing else is ever added to the o
|
|
|
109
140
|
|
|
110
141
|
`ContactSource.url` is rendered as a bare bullet with no label, because there is no whitelisted word for "the contact URL" and inventing one would put renderer prose in the output. `DocumentKind` and `ActionKind` are advisory routing/telemetry labels and are **never** rendered.
|
|
111
142
|
|
|
112
|
-
##
|
|
143
|
+
## Extending the source model
|
|
113
144
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
> A vertical earns its own source type and renderer only when **(a)** the generic `Fact` union loses machine-parseability for its core facts, **and (b)** a downstream protocol surface needs the structure, **and (c)** it is top-5 by observed merchant demand. Otherwise it ships as a **profile** — vocabulary, which is data.
|
|
117
|
-
|
|
118
|
-
Nothing clears the bar today. The closest call is `article` (normalised author/publisher for attribution); revisit that first if citation data justifies it.
|
|
145
|
+
Use a profile when the existing fact types express the content clearly. Add a source type or renderer when it improves machine-readable structure, protocol support or a customer workflow. Preserve compatibility and validate the new output; no minimum demand ranking is required.
|
|
119
146
|
|
|
120
147
|
## Security and privacy notes
|
|
121
148
|
|
|
122
|
-
**A snapshot is not a source of truth.** `DocumentSource.provenance` is set by hosted extraction only. When present, the gateway refuses to serve the document past `ttlSeconds` and falls through to HTML, and a scheduled recrawl auto-unpublishes on content drift. Without that, a merchant changes their hours and agents keep receiving the approved bundle — different substance to agents and humans at the same URL, which is a
|
|
149
|
+
**A snapshot is not a source of truth.** `DocumentSource.provenance` is set by hosted extraction only. When present, the gateway refuses to serve the document past `ttlSeconds` and falls through to HTML, and a scheduled recrawl auto-unpublishes on content drift. Without that, a merchant changes their hours and agents keep receiving the approved bundle — different substance to agents and humans at the same URL, which is a consistent offer representations breach manufactured by our own pipeline. This package renders `provenance` documents like any other; **enforcement is the gateway's job**, and extraction integrations need to validate that behavior.
|
|
123
150
|
|
|
124
|
-
**Prompt injection.** `DocumentSectionSource.body` is untrusted third-party prose delivered inside our structured envelope. A merchant page — or anything a merchant's CMS lets a third party publish — can contain text addressed to the agent reading it. We do not sanitise it, because rewriting merchant prose is exactly what this package must never do; we render it verbatim and it stays the consuming agent's responsibility to treat page content as data, not instructions.
|
|
151
|
+
**Prompt injection.** `DocumentSectionSource.body` is untrusted third-party prose delivered inside our structured envelope. A merchant page — or anything a merchant's CMS lets a third party publish — can contain text addressed to the agent reading it. We do not sanitise it, because rewriting merchant prose is exactly what this package must never do; we render it verbatim and it stays the consuming agent's responsibility to treat page content as data, not instructions. Consumers should preserve that trust boundary.
|
|
125
152
|
|
|
126
153
|
**PII.** `ContactSource`, combined with `kind: 'profile'` or `'job'`, makes it trivial to serve named individuals' contact details in bulk and in a machine-readable form. The merchant is the data controller. `render-md` must not be used to expose contact data that is not already public on the canonical page — mirroring ARCHITECTURE § Security.
|
|
127
154
|
|
|
@@ -129,8 +156,18 @@ Nothing clears the bar today. The closest call is `article` (normalised author/p
|
|
|
129
156
|
|
|
130
157
|
`pnpm --filter @rebilder/render-md test`.
|
|
131
158
|
|
|
132
|
-
- `commerce-frozen.test.ts` pins the three commerce renderers byte-exactly with **inline string literals**, not snapshots: `vitest -u` can silently regenerate a snapshot, it cannot regenerate a string literal. A change to that file is a deliberate output change, never a mechanical update. The same applies to `tests/__snapshots__/` —
|
|
159
|
+
- `commerce-frozen.test.ts` pins the three commerce renderers byte-exactly with **inline string literals**, not snapshots: `vitest -u` can silently regenerate a snapshot, it cannot regenerate a string literal. A change to that file is a deliberate output change, never a mechanical update. The same applies to `tests/__snapshots__/` — review any output change against the renderer contract before updating expected values.
|
|
133
160
|
- `documents-integrity.test.ts` is **structural, not a corpus scan**, and this is the important part: **a bare-number scan is not a validator.** A `number` fact renders through `String(value)`, so a fact of `3` renders `3`, and from that moment any `3` anywhere in the output passes a scan — including a fabricated one. The test instead (a) pins every fact to the exact line `- **<label>:** <expected>`, with `expected` computed independently from the same fixed label maps, and (b) asserts that the output, minus the scaffolding whitelist, is a token-for-token **subsequence** of the concatenated source strings. Subsequence, not subset: a token in the wrong place fails too. The whitelist is restated as literals in that file rather than imported, so new renderer-authored text cannot whitelist itself.
|
|
134
161
|
- `documents-access.test.ts` proves the access gate holds at every budget, against sentinel bodies that exist for no other purpose.
|
|
135
162
|
- `documents-budget.test.ts` asserts the truncation *ordering* over a sweep of budgets rather than at hand-picked byte counts.
|
|
136
163
|
- `integrity.test.ts` keeps the commerce price-token scan, which works there because a price has a recognisable shape.
|
|
164
|
+
|
|
165
|
+
### Versioned compatibility profiles
|
|
166
|
+
|
|
167
|
+
`applyCompatibilityProfile` accepts `baseline`, `source-envelope`, or
|
|
168
|
+
`section-index` at version 1. The latter two add source orientation or existing
|
|
169
|
+
heading navigation while preserving all baseline markdown bytes. Additions are
|
|
170
|
+
bounded to 1,024 bytes and fall back to baseline when the caller's byte budget
|
|
171
|
+
would be exceeded. The returned `profile` identifies what was actually rendered.
|
|
172
|
+
These are conservative evaluation candidates, with no claim of empirical model
|
|
173
|
+
improvement. See [the update contract](../../docs/design/rebilder-compatibility-updates.md).
|
package/dist/index.cjs
CHANGED
|
@@ -58,6 +58,22 @@ function formatMoney(m) {
|
|
|
58
58
|
return symbol !== void 0 ? `${sign}${symbol}${grouped}${frac}` : `${sign}${code} ${grouped}${frac}`;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
+
// src/internal/validate.ts
|
|
62
|
+
var ISO_DATE = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d{1,9})?)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
63
|
+
function isRealCalendarDate(value) {
|
|
64
|
+
const [year, month, day] = value.slice(0, 10).split("-").map(Number);
|
|
65
|
+
const probe = /* @__PURE__ */ new Date(0);
|
|
66
|
+
probe.setUTCFullYear(year, month - 1, day);
|
|
67
|
+
return probe.getUTCFullYear() === year && probe.getUTCMonth() === month - 1 && probe.getUTCDate() === day;
|
|
68
|
+
}
|
|
69
|
+
function isIsoDate(value) {
|
|
70
|
+
return ISO_DATE.test(value) && !Number.isNaN(Date.parse(value)) && isRealCalendarDate(value);
|
|
71
|
+
}
|
|
72
|
+
var BCP_47 = /^[A-Za-z]{2,3}(-[A-Za-z]{4})?(-(?:[A-Za-z]{2}|\d{3}))?$/;
|
|
73
|
+
function isLanguageTag(value) {
|
|
74
|
+
return BCP_47.test(value);
|
|
75
|
+
}
|
|
76
|
+
|
|
61
77
|
// src/jsonld.ts
|
|
62
78
|
var SCHEMA_AVAILABILITY = {
|
|
63
79
|
in_stock: "https://schema.org/InStock",
|
|
@@ -87,7 +103,9 @@ function renderProductJsonLd(p) {
|
|
|
87
103
|
if (p.brand !== void 0) out.brand = { "@type": "Brand", name: p.brand };
|
|
88
104
|
if (p.description !== void 0 && p.description.length > 0) out.description = p.description;
|
|
89
105
|
if (p.images !== void 0 && p.images.length > 0) out.image = p.images.map((img) => img.url);
|
|
106
|
+
if (p.language !== void 0 && isLanguageTag(p.language)) out.inLanguage = p.language;
|
|
90
107
|
out.offers = p.variants !== void 0 && p.variants.length > 0 ? p.variants.map((v) => offer(v.price, v.availability, { sku: v.sku, name: v.title })) : offer(p.price, p.availability, { url: p.url });
|
|
108
|
+
if (p.updated !== void 0 && isIsoDate(p.updated)) out.dateModified = p.updated;
|
|
91
109
|
return out;
|
|
92
110
|
}
|
|
93
111
|
|
|
@@ -110,6 +128,30 @@ function inline(text) {
|
|
|
110
128
|
function cell(text) {
|
|
111
129
|
return inline(text).replace(/\|/g, "\\|");
|
|
112
130
|
}
|
|
131
|
+
var ALLOWED_LINK_SCHEMES = ["https:", "http:", "mailto:", "tel:"];
|
|
132
|
+
function isSafeUrl(url) {
|
|
133
|
+
try {
|
|
134
|
+
return ALLOWED_LINK_SCHEMES.includes(new URL(url).protocol);
|
|
135
|
+
} catch {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function linkText(text) {
|
|
140
|
+
return inline(text).replace(/[[\]]/g, (c) => `\\${c}`);
|
|
141
|
+
}
|
|
142
|
+
function safeUrl(url) {
|
|
143
|
+
return url.replace(
|
|
144
|
+
/[()<>\s]/g,
|
|
145
|
+
(c) => `%${c.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
function cellLinkText(text) {
|
|
149
|
+
return linkText(text).replace(/\|/g, "\\|");
|
|
150
|
+
}
|
|
151
|
+
function safeLink(label, url, labelEscaper = linkText) {
|
|
152
|
+
const text = labelEscaper(label);
|
|
153
|
+
return isSafeUrl(url) ? `[${text}](${safeUrl(url)})` : text;
|
|
154
|
+
}
|
|
113
155
|
function tailText(t) {
|
|
114
156
|
return `${t.headingLine}
|
|
115
157
|
|
|
@@ -177,7 +219,7 @@ function renderProductMarkdown(p, opts) {
|
|
|
177
219
|
const maxBytes = opts?.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
178
220
|
const level = clampHeadingLevel(opts?.headingLevel ?? 1);
|
|
179
221
|
const sub = clampHeadingLevel(level + 1);
|
|
180
|
-
const facts = [heading(level,
|
|
222
|
+
const facts = [heading(level, safeLink(p.title, p.url)), ""];
|
|
181
223
|
if (p.brand !== void 0) facts.push(`- **Brand:** ${inline(p.brand)}`);
|
|
182
224
|
const price = formatMoney(p.price);
|
|
183
225
|
facts.push(
|
|
@@ -201,10 +243,13 @@ function renderProductMarkdown(p, opts) {
|
|
|
201
243
|
if (p.returns.windowDays !== void 0) {
|
|
202
244
|
facts.push(` - Return window: ${p.returns.windowDays} days`);
|
|
203
245
|
}
|
|
204
|
-
if (p.returns.url !== void 0) {
|
|
246
|
+
if (p.returns.url !== void 0 && isSafeUrl(p.returns.url)) {
|
|
205
247
|
facts.push(` - Policy: ${p.returns.url}`);
|
|
206
248
|
}
|
|
207
249
|
}
|
|
250
|
+
if (p.updated !== void 0 && isIsoDate(p.updated)) {
|
|
251
|
+
facts.push(`- **Updated:** ${inline(p.updated)}`);
|
|
252
|
+
}
|
|
208
253
|
const requiredBlocks = [facts.join("\n")];
|
|
209
254
|
if (p.variants !== void 0 && p.variants.length > 0) {
|
|
210
255
|
requiredBlocks.push(variantsTable(p.variants, sub));
|
|
@@ -221,8 +266,8 @@ function renderProductMarkdown(p, opts) {
|
|
|
221
266
|
}
|
|
222
267
|
if (p.images !== void 0 && p.images.length > 0) {
|
|
223
268
|
const items = p.images.map((img) => {
|
|
224
|
-
const label = img.alt !== void 0 && img.alt.length > 0 ?
|
|
225
|
-
return `-
|
|
269
|
+
const label = img.alt !== void 0 && img.alt.length > 0 ? img.alt : img.url;
|
|
270
|
+
return `- ${safeLink(label, img.url)}`;
|
|
226
271
|
});
|
|
227
272
|
tail.push({ headingLine: heading(sub, "Images"), items });
|
|
228
273
|
}
|
|
@@ -231,7 +276,7 @@ function renderProductMarkdown(p, opts) {
|
|
|
231
276
|
function renderPolicyMarkdown(policies, opts) {
|
|
232
277
|
const maxBytes = opts?.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
233
278
|
const level = clampHeadingLevel(opts?.headingLevel ?? 1);
|
|
234
|
-
const titleLineFor = (pol) => heading(level,
|
|
279
|
+
const titleLineFor = (pol) => heading(level, safeLink(pol.title, pol.url));
|
|
235
280
|
const blocks = policies.map((pol) => `${titleLineFor(pol)}
|
|
236
281
|
|
|
237
282
|
${pol.body}`);
|
|
@@ -272,7 +317,7 @@ function renderCatalogMarkdown(items, opts) {
|
|
|
272
317
|
"| --- | --- | --- |"
|
|
273
318
|
].join("\n");
|
|
274
319
|
const rows = items.map(
|
|
275
|
-
(item) => `|
|
|
320
|
+
(item) => `| ${safeLink(item.title, item.url, cellLinkText)} | ${formatMoney(item.price)} | ${AVAILABILITY_LABELS[item.availability]} |`
|
|
276
321
|
);
|
|
277
322
|
const full = [head, ...rows].join("\n");
|
|
278
323
|
if (byteLength(full) <= maxBytes) return full;
|
|
@@ -370,10 +415,6 @@ function markdownLink(label, url) {
|
|
|
370
415
|
function cellLink(label, url) {
|
|
371
416
|
return markdownLink(label, url).replace(/\|/g, "\\|");
|
|
372
417
|
}
|
|
373
|
-
var ISO_DATE = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d{1,9})?)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
374
|
-
function isIsoDate(value) {
|
|
375
|
-
return ISO_DATE.test(value) && !Number.isNaN(Date.parse(value));
|
|
376
|
-
}
|
|
377
418
|
function isIsoDay(value) {
|
|
378
419
|
return /^\d{4}-\d{2}-\d{2}$/.test(value) && !Number.isNaN(Date.parse(value));
|
|
379
420
|
}
|
|
@@ -717,21 +758,98 @@ ${TRUNCATION_NOTE}`;
|
|
|
717
758
|
return truncated ? `${out}${noteSuffix}` : out;
|
|
718
759
|
}
|
|
719
760
|
|
|
761
|
+
// src/documents/jsonld.ts
|
|
762
|
+
function listItem(item, position) {
|
|
763
|
+
const out = { "@type": "ListItem", position };
|
|
764
|
+
if (isAllowedUrl(item.url)) out.url = item.url;
|
|
765
|
+
out.name = item.title;
|
|
766
|
+
return out;
|
|
767
|
+
}
|
|
768
|
+
function renderCollectionJsonLd(collection) {
|
|
769
|
+
const out = {
|
|
770
|
+
"@context": "https://schema.org",
|
|
771
|
+
"@type": "ItemList"
|
|
772
|
+
};
|
|
773
|
+
if (isAllowedUrl(collection.url)) out.url = collection.url;
|
|
774
|
+
if (collection.title !== void 0) out.name = collection.title;
|
|
775
|
+
if (collection.language !== void 0 && isLanguageTag(collection.language)) {
|
|
776
|
+
out.inLanguage = collection.language;
|
|
777
|
+
}
|
|
778
|
+
const elements = collection.items.slice(0, MAX_COLLECTION_ROWS).map((item, index) => listItem(item, index + 1));
|
|
779
|
+
out.numberOfItems = elements.length;
|
|
780
|
+
out.itemListElement = elements;
|
|
781
|
+
if (collection.updated !== void 0 && isIsoDate(collection.updated)) {
|
|
782
|
+
out.dateModified = collection.updated;
|
|
783
|
+
}
|
|
784
|
+
return out;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// src/compatibility.ts
|
|
788
|
+
var BASELINE_PROFILE = Object.freeze({
|
|
789
|
+
id: "baseline",
|
|
790
|
+
version: 1
|
|
791
|
+
});
|
|
792
|
+
var COMPATIBILITY_RUNTIME_VERSION = 1;
|
|
793
|
+
function validateCompatibilityProfile(value) {
|
|
794
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
|
|
795
|
+
const profile = value;
|
|
796
|
+
if (Object.keys(profile).some((key) => key !== "id" && key !== "version")) return null;
|
|
797
|
+
if (profile.version !== 1 || typeof profile.id !== "string" || !["baseline", "source-envelope", "section-index"].includes(profile.id))
|
|
798
|
+
return null;
|
|
799
|
+
return { id: profile.id, version: 1 };
|
|
800
|
+
}
|
|
801
|
+
function applyCompatibilityProfile(markdown, selected, options) {
|
|
802
|
+
const profile = validateCompatibilityProfile(selected) ?? BASELINE_PROFILE;
|
|
803
|
+
const baseline = { markdown, profile: { ...BASELINE_PROFILE } };
|
|
804
|
+
if (profile.id === "baseline") return baseline;
|
|
805
|
+
let prefix = "";
|
|
806
|
+
if (profile.id === "source-envelope") {
|
|
807
|
+
let canonical;
|
|
808
|
+
try {
|
|
809
|
+
canonical = new URL(options.canonicalUrl);
|
|
810
|
+
} catch {
|
|
811
|
+
return baseline;
|
|
812
|
+
}
|
|
813
|
+
if (!["https:", "http:"].includes(canonical.protocol) || canonical.username || canonical.password)
|
|
814
|
+
return baseline;
|
|
815
|
+
prefix = `Source: ${JSON.stringify(canonical.href)}
|
|
816
|
+
|
|
817
|
+
`;
|
|
818
|
+
} else {
|
|
819
|
+
const headings = markdown.split("\n").filter((line) => /^#{1,6} /.test(line)).slice(0, 12);
|
|
820
|
+
if (headings.length < 2) return baseline;
|
|
821
|
+
prefix = `Sections on this page:
|
|
822
|
+
${headings.map((line) => `- ${line.replace(/^#{1,6} /, "")}`).join("\n")}
|
|
823
|
+
|
|
824
|
+
`;
|
|
825
|
+
}
|
|
826
|
+
const output = prefix + markdown;
|
|
827
|
+
const bytes = new TextEncoder().encode(output).byteLength;
|
|
828
|
+
if (new TextEncoder().encode(prefix).byteLength > 1024 || bytes > (options.maxBytes ?? 5120))
|
|
829
|
+
return baseline;
|
|
830
|
+
return { markdown: output, profile };
|
|
831
|
+
}
|
|
832
|
+
|
|
720
833
|
exports.ACCESS_LABELS = ACCESS_LABELS;
|
|
721
834
|
exports.ALLOWED_URL_SCHEMES = ALLOWED_URL_SCHEMES;
|
|
835
|
+
exports.BASELINE_PROFILE = BASELINE_PROFILE;
|
|
722
836
|
exports.BOOLEAN_LABELS = BOOLEAN_LABELS;
|
|
723
837
|
exports.CLOSED_LABEL = CLOSED_LABEL;
|
|
838
|
+
exports.COMPATIBILITY_RUNTIME_VERSION = COMPATIBILITY_RUNTIME_VERSION;
|
|
724
839
|
exports.NOT_STATED_LABEL = NOT_STATED_LABEL;
|
|
725
840
|
exports.PERIOD_SUFFIX = PERIOD_SUFFIX;
|
|
726
841
|
exports.SEE_PAGE_LABEL = SEE_PAGE_LABEL;
|
|
727
842
|
exports.WEEKDAY_LABELS = WEEKDAY_LABELS;
|
|
728
843
|
exports.WEEKDAY_ORDER = WEEKDAY_ORDER;
|
|
844
|
+
exports.applyCompatibilityProfile = applyCompatibilityProfile;
|
|
729
845
|
exports.formatMoney = formatMoney;
|
|
730
846
|
exports.renderCatalogMarkdown = renderCatalogMarkdown;
|
|
847
|
+
exports.renderCollectionJsonLd = renderCollectionJsonLd;
|
|
731
848
|
exports.renderCollectionMarkdown = renderCollectionMarkdown;
|
|
732
849
|
exports.renderDocumentMarkdown = renderDocumentMarkdown;
|
|
733
850
|
exports.renderPolicyMarkdown = renderPolicyMarkdown;
|
|
734
851
|
exports.renderProductJsonLd = renderProductJsonLd;
|
|
735
852
|
exports.renderProductMarkdown = renderProductMarkdown;
|
|
853
|
+
exports.validateCompatibilityProfile = validateCompatibilityProfile;
|
|
736
854
|
//# sourceMappingURL=index.cjs.map
|
|
737
855
|
//# sourceMappingURL=index.cjs.map
|