@serene-pub/docs 0.0.0-stage → 0.6.0-pr-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +17 -0
- package/README.md +286 -2
- package/dist/compile.d.ts +3 -0
- package/dist/compile.js +329 -0
- package/dist/dialect.d.ts +139 -0
- package/dist/dialect.js +465 -0
- package/dist/escape.d.ts +14 -0
- package/dist/escape.js +21 -0
- package/dist/graph.d.ts +31 -0
- package/dist/graph.js +132 -0
- package/dist/highlight.d.ts +7 -0
- package/dist/highlight.js +40 -0
- package/dist/images.d.ts +22 -0
- package/dist/images.js +137 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +23 -0
- package/dist/manifest.d.ts +44 -0
- package/dist/manifest.js +72 -0
- package/dist/sources.d.ts +15 -0
- package/dist/sources.js +52 -0
- package/dist/specGraph.d.ts +34 -0
- package/dist/specGraph.js +0 -0
- package/dist/types.d.ts +208 -0
- package/dist/types.js +19 -0
- package/package.json +67 -5
package/dist/compile.js
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `compileDocs` — markdown from several places in, one reading order out.
|
|
3
|
+
*
|
|
4
|
+
* The compile is a two-pass job and has to be: a link's anchor cannot be
|
|
5
|
+
* checked until every page has been rendered and every heading id is known.
|
|
6
|
+
* So nothing is written until everything has been rendered and proved. A
|
|
7
|
+
* compile that fails leaves the previous output alone rather than a half-empty
|
|
8
|
+
* directory that a server would happily serve.
|
|
9
|
+
*
|
|
10
|
+
* Every broken link, missing image and unresolvable anchor is collected and
|
|
11
|
+
* reported TOGETHER. Failing on the first one turns a docs pass into a dozen
|
|
12
|
+
* rebuilds.
|
|
13
|
+
*
|
|
14
|
+
* The write itself is write-then-prune, never empty-then-write. `out` used to
|
|
15
|
+
* be `rm -rf`'d and recreated, which is only invisible if nothing is reading
|
|
16
|
+
* the tree — and something is: the app's dev server watches `out`, and a reader
|
|
17
|
+
* landing between the `rm` and the writes saw a manifest naming pages that were
|
|
18
|
+
* not on disk ("that documentation page is not in this build"). Two compiles
|
|
19
|
+
* overlapping made it worse than a flicker, one `rmdir`-ing what the other was
|
|
20
|
+
* still writing into: `ENOTEMPTY`. So `out`, `out/pages` and `assetsOut` are
|
|
21
|
+
* never removed, every file is overwritten in place, whatever this compile did
|
|
22
|
+
* not write is pruned afterwards, and `manifest.json` and `search.json` land
|
|
23
|
+
* last — after every page and asset they name is already readable.
|
|
24
|
+
*/
|
|
25
|
+
import { mkdir, readdir, readFile, rm, rmdir, stat, writeFile } from 'node:fs/promises';
|
|
26
|
+
import { dirname, join, resolve, sep } from 'node:path';
|
|
27
|
+
import { AssetConverter } from './images.js';
|
|
28
|
+
import { createDocsHighlighter } from './highlight.js';
|
|
29
|
+
import { renderDocsGraph } from './graph.js';
|
|
30
|
+
import { navOrder } from './manifest.js';
|
|
31
|
+
import { docTitle, renderMarkdown } from './dialect.js';
|
|
32
|
+
import { DEFAULT_ASSET_BUDGET_BYTES, DEFAULT_DOC_LANGUAGES, DEFAULT_LINK_BASE, DEFAULT_MAX_WIDTH, DEFAULT_QUALITY, } from './types.js';
|
|
33
|
+
/** An href the compiler has no business converting: offsite, or already rooted. */
|
|
34
|
+
const OFFSITE_IMAGE = /^(?:[a-z][a-z0-9+.-]*:|\/\/|\/|data:)/i;
|
|
35
|
+
export async function compileDocs(opts) {
|
|
36
|
+
const linkBase = (opts.linkBase ?? DEFAULT_LINK_BASE).replace(/\/+$/, '');
|
|
37
|
+
const budgetBytes = opts.assetBudgetBytes ?? DEFAULT_ASSET_BUDGET_BYTES;
|
|
38
|
+
const maxWidth = opts.image?.maxWidth ?? DEFAULT_MAX_WIDTH;
|
|
39
|
+
const quality = opts.image?.quality ?? DEFAULT_QUALITY;
|
|
40
|
+
const offenders = [];
|
|
41
|
+
const warnings = [];
|
|
42
|
+
// ── 1. Gather every page, and settle the reading order per source. ──
|
|
43
|
+
const seenSourceIds = new Set();
|
|
44
|
+
const bySource = [];
|
|
45
|
+
for (const source of opts.sources) {
|
|
46
|
+
if (seenSourceIds.has(source.id))
|
|
47
|
+
throw new Error(`Two docs sources share the id \`${source.id}\`.`);
|
|
48
|
+
seenSourceIds.add(source.id);
|
|
49
|
+
bySource.push({ source, pages: await collectPages(source) });
|
|
50
|
+
}
|
|
51
|
+
const ordered = [];
|
|
52
|
+
const navGroups = [];
|
|
53
|
+
const pagesBySlug = new Map();
|
|
54
|
+
for (const { source, pages } of bySource) {
|
|
55
|
+
const settled = navOrder(source, pages);
|
|
56
|
+
warnings.push(...settled.warnings);
|
|
57
|
+
for (const page of settled.ordered) {
|
|
58
|
+
const clash = pagesBySlug.get(page.slug);
|
|
59
|
+
if (clash) {
|
|
60
|
+
offenders.push(`two pages compile to the slug \`${page.slug}\`: ` +
|
|
61
|
+
`\`${clash.source.id}:${clash.path}\` and \`${source.id}:${page.path}\`.`);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
pagesBySlug.set(page.slug, page);
|
|
65
|
+
ordered.push(page);
|
|
66
|
+
}
|
|
67
|
+
// One nav group per settled group — several for a grouped `order`.
|
|
68
|
+
// A page whose slug clashed was never rendered, so it stays out of
|
|
69
|
+
// the nav as it stays out of `ordered`.
|
|
70
|
+
for (const group of settled.groups) {
|
|
71
|
+
navGroups.push({
|
|
72
|
+
group: group.group,
|
|
73
|
+
source: source.id,
|
|
74
|
+
pages: group.pages
|
|
75
|
+
.filter((page) => pagesBySlug.get(page.slug) === page)
|
|
76
|
+
.map((page) => page.slug),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// ── 2. Render everything, converting images as they are met. ──
|
|
81
|
+
const converter = new AssetConverter({ maxWidth, quality });
|
|
82
|
+
const assets = new Map();
|
|
83
|
+
const highlighter = await createDocsHighlighter(opts.languages ?? DEFAULT_DOC_LANGUAGES);
|
|
84
|
+
const rendered = [];
|
|
85
|
+
try {
|
|
86
|
+
for (const page of ordered) {
|
|
87
|
+
const result = await renderMarkdown(page.markdown, {
|
|
88
|
+
path: page.path,
|
|
89
|
+
prefix: page.source.prefix,
|
|
90
|
+
linkBase,
|
|
91
|
+
banner: page.source.banner,
|
|
92
|
+
assetsBase: opts.assetsBase,
|
|
93
|
+
highlight: (code, lang) => highlighter.render(code, lang),
|
|
94
|
+
resolvePipeline: async (id) => {
|
|
95
|
+
const graph = opts.resolvers?.pipeline?.(id) ?? null;
|
|
96
|
+
if (!graph) {
|
|
97
|
+
offenders.push(`\`${page.slug}\` embeds pipeline \`${id}\` — no resolver / ` +
|
|
98
|
+
`unknown id.`);
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
return await renderDocsGraph(graph);
|
|
102
|
+
},
|
|
103
|
+
resolveImage: async (href) => {
|
|
104
|
+
const asset = await convertImage(page, href, converter, offenders);
|
|
105
|
+
if (asset)
|
|
106
|
+
assets.set(asset.file, asset.bytes);
|
|
107
|
+
return asset
|
|
108
|
+
? { file: asset.file, width: asset.width, height: asset.height }
|
|
109
|
+
: null;
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
rendered.push({ ...page, ...result });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
highlighter.dispose();
|
|
117
|
+
}
|
|
118
|
+
// ── 3. Prove every cross-page link lands, before anything is written. ──
|
|
119
|
+
const headingIds = new Map();
|
|
120
|
+
for (const page of rendered)
|
|
121
|
+
headingIds.set(page.slug, new Set(page.headings.map((heading) => heading.id)));
|
|
122
|
+
for (const page of rendered) {
|
|
123
|
+
for (const link of page.links) {
|
|
124
|
+
const target = headingIds.get(link.slug);
|
|
125
|
+
if (!target) {
|
|
126
|
+
offenders.push(`\`${page.slug}\` links \`${link.href}\` — slug \`${link.slug}\` is not in any source.`);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
if (link.anchor && !target.has(link.anchor)) {
|
|
130
|
+
offenders.push(`\`${page.slug}\` links \`${link.href}\` — page \`${link.slug}\` has no ` +
|
|
131
|
+
`heading id \`${link.anchor}\`.`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
let assetBytes = 0;
|
|
136
|
+
for (const bytes of assets.values())
|
|
137
|
+
assetBytes += bytes.byteLength;
|
|
138
|
+
if (assetBytes > budgetBytes) {
|
|
139
|
+
offenders.push(`converted assets are ${assetBytes} bytes, over the ${budgetBytes} byte budget ` +
|
|
140
|
+
`(${assets.size} files).`);
|
|
141
|
+
}
|
|
142
|
+
if (offenders.length) {
|
|
143
|
+
throw new Error(`Docs compile failed — ${offenders.length} problem${offenders.length === 1 ? '' : 's'}:\n` +
|
|
144
|
+
offenders.map((line) => ` • ${line}`).join('\n'));
|
|
145
|
+
}
|
|
146
|
+
// ── 4. Write in place, then prune what this compile did not write. ──
|
|
147
|
+
const pagesOut = join(opts.out, 'pages');
|
|
148
|
+
await mkdir(pagesOut, { recursive: true });
|
|
149
|
+
await mkdir(opts.assetsOut, { recursive: true });
|
|
150
|
+
const writtenAssets = new Set();
|
|
151
|
+
for (const [file, bytes] of assets) {
|
|
152
|
+
await writeFile(join(opts.assetsOut, file), bytes);
|
|
153
|
+
writtenAssets.add(file);
|
|
154
|
+
}
|
|
155
|
+
const writtenPages = new Set();
|
|
156
|
+
const orderWithinSource = new Map();
|
|
157
|
+
const pageMeta = {};
|
|
158
|
+
const search = [];
|
|
159
|
+
for (const page of rendered) {
|
|
160
|
+
const relative = page.slug.split('/').join(sep) + '.html';
|
|
161
|
+
const target = join(pagesOut, relative);
|
|
162
|
+
await mkdir(dirname(target), { recursive: true });
|
|
163
|
+
const html = page.html;
|
|
164
|
+
await writeFile(target, html, 'utf8');
|
|
165
|
+
writtenPages.add(relative);
|
|
166
|
+
const position = orderWithinSource.get(page.source.id) ?? 0;
|
|
167
|
+
orderWithinSource.set(page.source.id, position + 1);
|
|
168
|
+
pageMeta[page.slug] = {
|
|
169
|
+
slug: page.slug,
|
|
170
|
+
title: docTitle(page.markdown, page.slug),
|
|
171
|
+
description: page.description,
|
|
172
|
+
source: page.source.id,
|
|
173
|
+
order: position,
|
|
174
|
+
headings: page.headings,
|
|
175
|
+
bytes: Buffer.byteLength(html, 'utf8'),
|
|
176
|
+
};
|
|
177
|
+
for (const heading of page.headings) {
|
|
178
|
+
search.push({
|
|
179
|
+
slug: page.slug,
|
|
180
|
+
anchor: heading.id,
|
|
181
|
+
title: heading.text,
|
|
182
|
+
depth: heading.depth,
|
|
183
|
+
preview: page.previews[heading.id] ?? '',
|
|
184
|
+
text: page.sectionTexts[heading.id] ?? '',
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const manifest = {
|
|
189
|
+
version: opts.version,
|
|
190
|
+
generatedAt: new Date().toISOString(),
|
|
191
|
+
linkBase,
|
|
192
|
+
sources: Object.fromEntries(opts.sources.map((source) => [
|
|
193
|
+
source.id,
|
|
194
|
+
{
|
|
195
|
+
group: source.group,
|
|
196
|
+
...(source.banner ? { banner: source.banner } : {}),
|
|
197
|
+
...(source.repo ? { repo: source.repo } : {}),
|
|
198
|
+
},
|
|
199
|
+
])),
|
|
200
|
+
nav: navGroups,
|
|
201
|
+
pages: pageMeta,
|
|
202
|
+
assets: { count: assets.size, bytes: assetBytes, budgetBytes },
|
|
203
|
+
};
|
|
204
|
+
// Only ever below `pages/` and inside `assetsOut`: the rest of `out` is the
|
|
205
|
+
// consumer's to own, and emptying it is how a stray `.gitignore` or an
|
|
206
|
+
// editor's scratch file used to disappear on every build.
|
|
207
|
+
await prune(pagesOut, writtenPages, { emptyDirs: true });
|
|
208
|
+
await prune(opts.assetsOut, writtenAssets, { emptyDirs: false });
|
|
209
|
+
// Last, deliberately: the manifest is the reader's index, and every page
|
|
210
|
+
// and asset it names is on disk by the time it names them.
|
|
211
|
+
await writeFile(join(opts.out, 'manifest.json'), JSON.stringify(manifest, null, 2), 'utf8');
|
|
212
|
+
await writeFile(join(opts.out, 'search.json'), JSON.stringify(search, null, 2), 'utf8');
|
|
213
|
+
return { manifest, warnings, pagesWritten: rendered.length, assetsWritten: assets.size };
|
|
214
|
+
}
|
|
215
|
+
async function collectPages(source) {
|
|
216
|
+
const made = (path, markdown, file) => {
|
|
217
|
+
const bareSlug = path.replace(/\.md$/i, '');
|
|
218
|
+
return {
|
|
219
|
+
source,
|
|
220
|
+
path,
|
|
221
|
+
bareSlug,
|
|
222
|
+
slug: source.prefix ? `${source.prefix}/${bareSlug}` : bareSlug,
|
|
223
|
+
markdown,
|
|
224
|
+
file,
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
const pages = [];
|
|
228
|
+
if (source.pages)
|
|
229
|
+
for (const page of source.pages)
|
|
230
|
+
pages.push(made(page.path, page.markdown));
|
|
231
|
+
if (source.dir) {
|
|
232
|
+
const root = resolve(source.dir);
|
|
233
|
+
for (const file of await markdownFilesIn(root)) {
|
|
234
|
+
const path = file
|
|
235
|
+
.slice(root.length + 1)
|
|
236
|
+
.split(sep)
|
|
237
|
+
.join('/');
|
|
238
|
+
pages.push(made(path, await readFile(file, 'utf8'), file));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (!source.pages && !source.dir)
|
|
242
|
+
throw new Error(`Docs source \`${source.id}\` has neither \`dir\` nor \`pages\`.`);
|
|
243
|
+
return pages;
|
|
244
|
+
}
|
|
245
|
+
async function markdownFilesIn(dir) {
|
|
246
|
+
const found = [];
|
|
247
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
248
|
+
for (const entry of entries.sort((a, b) => (a.name < b.name ? -1 : 1))) {
|
|
249
|
+
const full = join(dir, entry.name);
|
|
250
|
+
if (entry.isDirectory())
|
|
251
|
+
found.push(...(await markdownFilesIn(full)));
|
|
252
|
+
else if (entry.name.toLowerCase().endsWith('.md'))
|
|
253
|
+
found.push(full);
|
|
254
|
+
}
|
|
255
|
+
return found;
|
|
256
|
+
}
|
|
257
|
+
async function convertImage(page, href, converter, offenders) {
|
|
258
|
+
if (OFFSITE_IMAGE.test(href))
|
|
259
|
+
return null;
|
|
260
|
+
if (!page.file) {
|
|
261
|
+
offenders.push(`\`${page.slug}\` references the image \`${href}\`, but its source has no \`dir\` — ` +
|
|
262
|
+
`a rendered page cannot carry relative images.`);
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
const absolute = resolve(dirname(page.file), href.split(/[?#]/)[0]);
|
|
266
|
+
try {
|
|
267
|
+
await stat(absolute);
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
offenders.push(`\`${page.slug}\` references the image \`${href}\` — ${absolute} does not exist.`);
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
try {
|
|
274
|
+
return await converter.convert(absolute);
|
|
275
|
+
}
|
|
276
|
+
catch (cause) {
|
|
277
|
+
offenders.push(`\`${page.slug}\` references the image \`${href}\` — ${absolute} could not be ` +
|
|
278
|
+
`converted: ${cause.message}`);
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Delete everything under `dir` that this compile did not write.
|
|
284
|
+
*
|
|
285
|
+
* `keep` holds paths relative to `dir`, separator-joined the way `join` builds
|
|
286
|
+
* them. `dir` itself is never removed — that is the whole point; a consumer
|
|
287
|
+
* watching it keeps watching the same directory across every compile.
|
|
288
|
+
*
|
|
289
|
+
* `emptyDirs` removes subdirectories left with nothing in them, which is only
|
|
290
|
+
* wanted below `pages/`, where a directory exists solely because a nested slug
|
|
291
|
+
* needed one. The assets directory is flat and shares its parent with whatever
|
|
292
|
+
* else the consumer serves, so nothing there is rmdir'd.
|
|
293
|
+
*/
|
|
294
|
+
async function prune(dir, keep, { emptyDirs }) {
|
|
295
|
+
/** Returns whether `current` is empty once its extras are gone. */
|
|
296
|
+
const walk = async (current, prefix) => {
|
|
297
|
+
let entries;
|
|
298
|
+
try {
|
|
299
|
+
entries = await readdir(current, { withFileTypes: true });
|
|
300
|
+
}
|
|
301
|
+
catch {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
let kept = 0;
|
|
305
|
+
for (const entry of entries) {
|
|
306
|
+
const full = join(current, entry.name);
|
|
307
|
+
const relative = prefix ? prefix + sep + entry.name : entry.name;
|
|
308
|
+
if (entry.isDirectory()) {
|
|
309
|
+
const empty = await walk(full, relative);
|
|
310
|
+
if (empty && emptyDirs) {
|
|
311
|
+
// force: a concurrent writer may have refilled it; leaving
|
|
312
|
+
// a directory standing is never worth failing a compile.
|
|
313
|
+
await rmdir(full).catch(() => { });
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
kept++;
|
|
317
|
+
}
|
|
318
|
+
else if (keep.has(relative)) {
|
|
319
|
+
kept++;
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
await rm(full, { force: true });
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return kept === 0;
|
|
326
|
+
};
|
|
327
|
+
await walk(dir, '');
|
|
328
|
+
}
|
|
329
|
+
//# sourceMappingURL=compile.js.map
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { escapeHtml } from './escape.js';
|
|
2
|
+
/** Re-exported: it was this module's export first, and every caller names it here. */
|
|
3
|
+
export { escapeHtml };
|
|
4
|
+
export interface DocHeading {
|
|
5
|
+
id: string;
|
|
6
|
+
text: string;
|
|
7
|
+
depth: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* One link a page makes that the compile can prove lands: a relative `.md`
|
|
11
|
+
* href, or a bare `#anchor`, which points at the page that wrote it.
|
|
12
|
+
*/
|
|
13
|
+
export interface DocLinkRef {
|
|
14
|
+
/** The href as written. */
|
|
15
|
+
href: string;
|
|
16
|
+
/** Slug it points at, prefix included. A bare `#anchor`'s own page. */
|
|
17
|
+
slug: string;
|
|
18
|
+
/** Anchor without the '#', or '' when it has none. */
|
|
19
|
+
anchor: string;
|
|
20
|
+
}
|
|
21
|
+
/** A converted image, as the compiler hands it back to the renderer. */
|
|
22
|
+
export interface DocImageAsset {
|
|
23
|
+
/** File name inside the assets directory, e.g. '3f2a…c1.webp'. */
|
|
24
|
+
file: string;
|
|
25
|
+
width?: number;
|
|
26
|
+
height?: number;
|
|
27
|
+
}
|
|
28
|
+
export interface DocHrefContext {
|
|
29
|
+
/** Path of the page inside its source, e.g. 'pipelines/core_spec_respond.md'. */
|
|
30
|
+
path: string;
|
|
31
|
+
/** Slug prefix of the page's source, e.g. 'sdk'. */
|
|
32
|
+
prefix?: string;
|
|
33
|
+
/** URL base for page links. Default '/docs'. */
|
|
34
|
+
linkBase?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface ResolvedDocLink {
|
|
37
|
+
slug: string;
|
|
38
|
+
anchor: string;
|
|
39
|
+
href: string;
|
|
40
|
+
}
|
|
41
|
+
export interface RenderMarkdownOptions extends DocHrefContext {
|
|
42
|
+
/**
|
|
43
|
+
* Renders one fenced code block. Returning null falls back to an escaped
|
|
44
|
+
* `<pre><code>`, which is also what an unknown language gets.
|
|
45
|
+
*/
|
|
46
|
+
highlight?: (code: string, lang: string) => string | null;
|
|
47
|
+
/**
|
|
48
|
+
* Resolves an image reference against the page it was written on.
|
|
49
|
+
* Returning null leaves the reference pointing at the href as written —
|
|
50
|
+
* the compiler uses that for offsite images, and for the ones it is about
|
|
51
|
+
* to fail the compile over.
|
|
52
|
+
*/
|
|
53
|
+
resolveImage?: (href: string) => Promise<DocImageAsset | null>;
|
|
54
|
+
/**
|
|
55
|
+
* Renders a ` ```pipeline <id> ` fence into the HTML that replaces it.
|
|
56
|
+
* Resolved BEFORE the parse, exactly like an image's asset: laying a graph
|
|
57
|
+
* out is asynchronous and marked's parse is not. Returning null leaves the
|
|
58
|
+
* fence as a plain code block — which only a compile that is already
|
|
59
|
+
* failing over that same id ever sees.
|
|
60
|
+
*/
|
|
61
|
+
resolvePipeline?: (id: string) => Promise<string | null>;
|
|
62
|
+
/** URL base the emitted `<img src>` uses, e.g. '/docs/assets'. */
|
|
63
|
+
assetsBase?: string;
|
|
64
|
+
/** Prepended as `<aside class="doc-banner" role="note">`. */
|
|
65
|
+
banner?: string;
|
|
66
|
+
}
|
|
67
|
+
export interface RenderedMarkdown {
|
|
68
|
+
html: string;
|
|
69
|
+
headings: DocHeading[];
|
|
70
|
+
/** Previews by heading id — the body under that heading, ≤180 chars. */
|
|
71
|
+
previews: Record<string, string>;
|
|
72
|
+
/**
|
|
73
|
+
* Search text by heading id — the same body, longer (≤1200 chars), so a
|
|
74
|
+
* word further into a section than its preview still finds it.
|
|
75
|
+
*/
|
|
76
|
+
sectionTexts: Record<string, string>;
|
|
77
|
+
/** Every relative `.md` link and bare `#anchor`, in document order. */
|
|
78
|
+
links: DocLinkRef[];
|
|
79
|
+
/** Every image reference, in document order, as written. */
|
|
80
|
+
images: string[];
|
|
81
|
+
/** Every ` ```pipeline ` fence's id, in document order. */
|
|
82
|
+
pipelines: string[];
|
|
83
|
+
/** First H1, else undefined. */
|
|
84
|
+
title?: string;
|
|
85
|
+
/** First paragraph after the H1, inline markdown stripped, ≤200 chars. */
|
|
86
|
+
description: string;
|
|
87
|
+
}
|
|
88
|
+
declare const ADMONITION_KINDS: readonly ['note', 'tip', 'warning'];
|
|
89
|
+
export type AdmonitionKind = (typeof ADMONITION_KINDS)[number];
|
|
90
|
+
/**
|
|
91
|
+
* GitHub's heading-slug rule, via `github-slugger`.
|
|
92
|
+
*
|
|
93
|
+
* Not a choice about slugs so much as an admission of where the corpus comes
|
|
94
|
+
* from: the guides lived on GitHub for a year and link each other with the
|
|
95
|
+
* anchors GitHub gave them (`#portable--self-contained-setup`,
|
|
96
|
+
* `#serene_pub_data_dir-is-the-one-exception`), and TypeDoc's markdown emits
|
|
97
|
+
* the same shape (`#slot_value`, `#band_order`). Any other rule makes those
|
|
98
|
+
* dead on arrival.
|
|
99
|
+
*
|
|
100
|
+
* It lowercases, drops the punctuation GitHub drops — `_` and `-` are not
|
|
101
|
+
* punctuation to it, which is the whole of the `SERENE_PUB_DATA_DIR` case —
|
|
102
|
+
* and turns EACH space into a `-`, so an `&` removed from between two spaces
|
|
103
|
+
* leaves two: `Prompt Configs & Summarization Config` becomes
|
|
104
|
+
* `prompt-configs--summarization-config`.
|
|
105
|
+
*
|
|
106
|
+
* This is the stateless single-heading form — a fresh slugger per call, so
|
|
107
|
+
* nothing de-duplicates across calls. A page renders through ONE slugger (see
|
|
108
|
+
* `renderMarkdown`), which is where the `-1`, `-2` suffixes come from.
|
|
109
|
+
*
|
|
110
|
+
* Nothing is trimmed or otherwise tidied on the way in. Heading text reaches
|
|
111
|
+
* this already trimmed by the lexer, and normalisation GitHub does not do is a
|
|
112
|
+
* slug GitHub's readers do not have.
|
|
113
|
+
*/
|
|
114
|
+
export declare function slugifyHeading(text: string): string;
|
|
115
|
+
/** The app's, character for character. Used for descriptions and previews. */
|
|
116
|
+
export declare function stripInlineMarkdown(text: string): string;
|
|
117
|
+
/**
|
|
118
|
+
* Where a relative `.md` link lands, given the page that wrote it. Returns
|
|
119
|
+
* null for anchor-only, offsite and non-markdown hrefs — those pass through
|
|
120
|
+
* untouched, and are never validated.
|
|
121
|
+
*/
|
|
122
|
+
export declare function resolveDocLink(href: string, ctx: DocHrefContext): ResolvedDocLink | null;
|
|
123
|
+
/**
|
|
124
|
+
* Rewrites a relative markdown link into the route it maps to.
|
|
125
|
+
*
|
|
126
|
+
* With no context this is the app's original one-argument function, kept
|
|
127
|
+
* because the app still calls it that way: flat slugs only, `/docs` hardcoded.
|
|
128
|
+
* With a context it understands nested paths and a source prefix, which is
|
|
129
|
+
* what a catalog page linking `pipelines/core_spec_respond.md` needs.
|
|
130
|
+
*/
|
|
131
|
+
export declare function rewriteDocHref(href: string, ctx?: DocHrefContext): string;
|
|
132
|
+
/**
|
|
133
|
+
* Markdown → the article body, with everything the compile needs to check
|
|
134
|
+
* itself read off the same token tree.
|
|
135
|
+
*/
|
|
136
|
+
export declare function renderMarkdown(markdown: string, opts: RenderMarkdownOptions): Promise<RenderedMarkdown>;
|
|
137
|
+
/** The title rule: first H1 in the source, else the slug. */
|
|
138
|
+
export declare function docTitle(markdown: string, slug: string): string;
|
|
139
|
+
//# sourceMappingURL=dialect.d.ts.map
|