@bagandev/bagan_cache-wasm32-wasi 0.1.0 → 0.1.1
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/bagan_cache.wasi-browser.js +1450 -0
- package/bagan_cache.wasi.cjs +2307 -0
- package/bagan_cache.wasi.d.cts +934 -0
- package/bagan_cache.wasm32-wasi.wasm +0 -0
- package/package.json +1 -1
- package/wasi-worker-browser.mjs +67 -0
- package/wasi-worker.mjs +186 -0
|
@@ -0,0 +1,934 @@
|
|
|
1
|
+
|
|
2
|
+
/** The WASI flavor this loader instantiates. */
|
|
3
|
+
export declare const __napiBindingTarget: 'wasm32-wasi'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* In-memory + archive-backed cache of the Markdown and asset files under a
|
|
7
|
+
* directory tree.
|
|
8
|
+
*
|
|
9
|
+
* Memory is the source of truth for hot content; a background worker
|
|
10
|
+
* flushes a binary shard archive to `.peisar-cache` for cold/large
|
|
11
|
+
* entries, front-ended by the `map.json` search index. Watchers keep the
|
|
12
|
+
* memory tier in sync with the filesystem.
|
|
13
|
+
*/
|
|
14
|
+
export declare class BaganCache {
|
|
15
|
+
/**
|
|
16
|
+
* JS: `new BaganCache(entryDir?, assetsDir?, options?)`.
|
|
17
|
+
*
|
|
18
|
+
* `options` configures the theme, Markdown parsing (`fragment`, GFM,
|
|
19
|
+
* …), archive thresholds, hosting resolution, and output directories.
|
|
20
|
+
* Register custom visitors and parser hooks afterwards with
|
|
21
|
+
* `usePlugin()`.
|
|
22
|
+
*/
|
|
23
|
+
constructor(entryDir?: string | undefined | null, assetsDir?: string | undefined | null, options?: BaganCacheJsOptions | undefined | null)
|
|
24
|
+
/**
|
|
25
|
+
* JS: `BaganCache.withConfigJs(config)` — full configuration form,
|
|
26
|
+
* including memory-tier budgets.
|
|
27
|
+
*/
|
|
28
|
+
static withConfigJs(config: BaganCacheConfig): BaganCache
|
|
29
|
+
/**
|
|
30
|
+
* Register a JavaScript plugin applied to every page render
|
|
31
|
+
* (JS: `cache.usePlugin({ visitBlock, visitInline, parseBlock, parseInline })`).
|
|
32
|
+
*/
|
|
33
|
+
usePlugin(plugin: Plugin): void
|
|
34
|
+
/**
|
|
35
|
+
* JS: `cache.startWatchingJs()` — start watching the entry (and
|
|
36
|
+
* assets) directories recursively; errors surface as JS exceptions.
|
|
37
|
+
*
|
|
38
|
+
* While watching is active this holds a strong (ref'd) threadsafe
|
|
39
|
+
* function on the Node event loop, so a plain script that only calls
|
|
40
|
+
* `startWatchingJs()` keeps running until `dispose()` (or process
|
|
41
|
+
* exit) stops the watcher. Without it, the native watcher thread is
|
|
42
|
+
* invisible to libuv and Node exits as soon as the script ends.
|
|
43
|
+
*/
|
|
44
|
+
startWatchingJs(): void
|
|
45
|
+
/**
|
|
46
|
+
* JS: `cache.getText(absPath)` — cached text of a file, or `null`.
|
|
47
|
+
* Reads fall through to the archive tier for evicted entries.
|
|
48
|
+
*/
|
|
49
|
+
getText(absPath: string): string | null
|
|
50
|
+
/**
|
|
51
|
+
* JS: `cache.getBinary(absPath)` — cached bytes of a binary asset, or
|
|
52
|
+
* `null`. Reads fall through to the archive tier.
|
|
53
|
+
*/
|
|
54
|
+
getBinary(absPath: string): Array<number> | null
|
|
55
|
+
/**
|
|
56
|
+
* JS: `cache.listFiles()` — absolute paths of everything cached
|
|
57
|
+
* (memory + archive tiers).
|
|
58
|
+
*/
|
|
59
|
+
listFiles(): Array<string>
|
|
60
|
+
/**
|
|
61
|
+
* JS: `cache.markdownFiles()` — absolute paths of cached markdown
|
|
62
|
+
* files (either tier).
|
|
63
|
+
*/
|
|
64
|
+
markdownFiles(): Array<string>
|
|
65
|
+
/**
|
|
66
|
+
* Accepted Markdown layouts discovered from the theme's `.html`
|
|
67
|
+
* templates, sorted by name.
|
|
68
|
+
*
|
|
69
|
+
* JS: `cache.markdownLayouts()`.
|
|
70
|
+
*/
|
|
71
|
+
markdownLayouts(): Array<string>
|
|
72
|
+
/**
|
|
73
|
+
* Absolute paths to the configured theme's layouts, assets, and data
|
|
74
|
+
* directories.
|
|
75
|
+
*/
|
|
76
|
+
themeDirs(): ThemeDirs
|
|
77
|
+
/**
|
|
78
|
+
* JS: `cache.assetFiles()` — absolute paths of cached non-markdown
|
|
79
|
+
* files (either tier).
|
|
80
|
+
*/
|
|
81
|
+
assetFiles(): Array<string>
|
|
82
|
+
/**
|
|
83
|
+
* JS: `cache.pages()` — every page object, for Liquid themes
|
|
84
|
+
* (`{{ page.title }}`, `{{ page.layout }}`, …).
|
|
85
|
+
*/
|
|
86
|
+
pages(): Array<PageObject>
|
|
87
|
+
/**
|
|
88
|
+
* JS: `cache.getPage(inputPath)` — a single page object by absolute
|
|
89
|
+
* input path, or `null`.
|
|
90
|
+
*/
|
|
91
|
+
getPage(inputPath: string): PageObject | null
|
|
92
|
+
/** JS: `cache.assets()` — every asset object. */
|
|
93
|
+
assets(): Array<AssetsObject>
|
|
94
|
+
/**
|
|
95
|
+
* JS: `cache.getAsset(inputPath)` — a single asset object by absolute
|
|
96
|
+
* input path, or `null`.
|
|
97
|
+
*/
|
|
98
|
+
getAsset(inputPath: string): AssetsObject | null
|
|
99
|
+
/** Absolute path to the configured theme package. */
|
|
100
|
+
themePath(): string
|
|
101
|
+
/** Parsed theme metadata exposed as an object to Rust and JavaScript. */
|
|
102
|
+
themeConfig(): PeisarThemeConfig
|
|
103
|
+
/**
|
|
104
|
+
* JS: `cache.archived()` — absolute paths flushed to the disk
|
|
105
|
+
* archive. Everything not listed still lives in memory only.
|
|
106
|
+
*/
|
|
107
|
+
archived(): Array<string>
|
|
108
|
+
/**
|
|
109
|
+
* JS: `cache.mapJson()` — the current `map.json` document (path →
|
|
110
|
+
* shard location + metadata, including front matter for search).
|
|
111
|
+
*/
|
|
112
|
+
mapJson(): string
|
|
113
|
+
/**
|
|
114
|
+
* JS: `cache.flush()` — write all pending archive entries now,
|
|
115
|
+
* blocking until the worker is done.
|
|
116
|
+
*/
|
|
117
|
+
flush(): void
|
|
118
|
+
/**
|
|
119
|
+
* JS: `cache.baseUrl()` — the resolved base URL path prefix for the
|
|
120
|
+
* configured hosting (e.g. `/repo/` for a GitHub Pages project site).
|
|
121
|
+
*/
|
|
122
|
+
baseUrl(): string
|
|
123
|
+
/**
|
|
124
|
+
* JS: `cache.resolveUrl(path)` — prefix a site-relative path with the
|
|
125
|
+
* resolved base URL: `resolveUrl("docs/intro")` → `/repo/docs/intro`.
|
|
126
|
+
*/
|
|
127
|
+
resolveUrl(path: string): string
|
|
128
|
+
/**
|
|
129
|
+
* JS: `cache.siteUrl()` — absolute origin URL for canonical URLs, or
|
|
130
|
+
* `null` when not configured.
|
|
131
|
+
*/
|
|
132
|
+
siteUrl(): string | null
|
|
133
|
+
/**
|
|
134
|
+
* JS: `cache.onChange(cb)` — invoke `cb(event)` on every file change the
|
|
135
|
+
* watcher detects while watching is active. Returns a subscription id
|
|
136
|
+
* that can be passed to `offChange(id)`.
|
|
137
|
+
*
|
|
138
|
+
* The callback is wrapped in a `ThreadsafeFunction` because notify
|
|
139
|
+
* events fire on the watcher thread, not the JS main thread.
|
|
140
|
+
*/
|
|
141
|
+
onChange(callback: (event: CacheChangeEvent) => void): number
|
|
142
|
+
/** JS: `cache.offChange(id)` — remove a previously registered callback. */
|
|
143
|
+
offChange(id: number): void
|
|
144
|
+
/**
|
|
145
|
+
* JS: `cache.dispose()` — stop the watcher, flush pending archive
|
|
146
|
+
* writes, and drop JS change callbacks. Safe to call more than once.
|
|
147
|
+
*
|
|
148
|
+
* Rust consumers do not need this: dropping the [`BaganCache`] stops
|
|
149
|
+
* the watcher, flushes the archive, and joins the workers.
|
|
150
|
+
*/
|
|
151
|
+
dispose(): void
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Flush thresholds for the disk-archive tier. */
|
|
155
|
+
export interface ArchiveConfig {
|
|
156
|
+
/**
|
|
157
|
+
* Pending-content threshold (bytes) that triggers writing a new
|
|
158
|
+
* shard; `0` disables size-based flushing (interval/drop only).
|
|
159
|
+
*/
|
|
160
|
+
shardBytes?: number
|
|
161
|
+
/**
|
|
162
|
+
* Maximum time (ms) pending entries may sit in the worker buffer
|
|
163
|
+
* before being flushed. `0` disables the timer.
|
|
164
|
+
*/
|
|
165
|
+
flushIntervalMs?: number
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** An asset mirrored by the cache (JS/CSS/image/video/font/…). */
|
|
169
|
+
export interface AssetsObject {
|
|
170
|
+
/** File name without extension (`foo.png` → `foo`). */
|
|
171
|
+
fileName: string
|
|
172
|
+
/** URL for the asset (`path/to/foo.png` → `/path/to/foo.png`). */
|
|
173
|
+
slug: string
|
|
174
|
+
/** Raw content: UTF-8 text for textual assets, base64 for binaries. */
|
|
175
|
+
raw: string
|
|
176
|
+
/** Build output path for the asset. */
|
|
177
|
+
outFilePath: string
|
|
178
|
+
/** Original absolute source path (watch-process identity). */
|
|
179
|
+
inputFilePath: string
|
|
180
|
+
/** File extension (lowercase, without dot). */
|
|
181
|
+
ext: string
|
|
182
|
+
/**
|
|
183
|
+
* Kind classification: `"Js"`, `"Css"`, `"Image"`, `"Video"`,
|
|
184
|
+
* `"Font"`, or `"Other"`.
|
|
185
|
+
*/
|
|
186
|
+
fileType: string
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Cache-wide configuration: directories, markdown options, memory/archive
|
|
191
|
+
* budgets, hosting/baseUrl resolution, and the build output directory.
|
|
192
|
+
*/
|
|
193
|
+
export interface BaganCacheConfig {
|
|
194
|
+
/**
|
|
195
|
+
* Entry directory holding the markdown files (absolute, or relative
|
|
196
|
+
* to the current working directory). Defaults to the current directory.
|
|
197
|
+
*/
|
|
198
|
+
entryDir?: string
|
|
199
|
+
/**
|
|
200
|
+
* Optional assets directory, resolved from the current working
|
|
201
|
+
* directory and required to be inside `entry_dir`.
|
|
202
|
+
*/
|
|
203
|
+
assetsDir?: string
|
|
204
|
+
/**
|
|
205
|
+
* Theme package name resolved from [`DEFAULT_THEME_DIR`] under the current
|
|
206
|
+
* working directory. Defaults to [`DEFAULT_THEME_NAME`].
|
|
207
|
+
*/
|
|
208
|
+
theme?: string
|
|
209
|
+
/**
|
|
210
|
+
* Markdown parsing/rendering options applied to every page render
|
|
211
|
+
* (GFM/Kramdown toggles, `fragment`, title, …). Custom visitors and
|
|
212
|
+
* parser hooks are registered separately via `usePlugin()`.
|
|
213
|
+
*/
|
|
214
|
+
markdown?: PeisarOptions
|
|
215
|
+
/**
|
|
216
|
+
* Memory-tier budgets (LRU eviction). Defaults: 64 MiB bytes,
|
|
217
|
+
* unlimited entries.
|
|
218
|
+
*/
|
|
219
|
+
memory?: MemoryConfig
|
|
220
|
+
/** Disk-archive tier thresholds. Defaults: 8 MiB shards, 2 s flush. */
|
|
221
|
+
archive?: ArchiveConfig
|
|
222
|
+
/** Static-hosting baseUrl resolution (GitHub Pages/Vercel/…). */
|
|
223
|
+
hosting?: HostingConfig
|
|
224
|
+
/**
|
|
225
|
+
* Build output directory used for `outFilePath` fields (default
|
|
226
|
+
* `".bagan"`).
|
|
227
|
+
*/
|
|
228
|
+
outDir?: string
|
|
229
|
+
/**
|
|
230
|
+
* Archive directory, relative to the current working directory
|
|
231
|
+
* (default `".peisar-cache"`).
|
|
232
|
+
*/
|
|
233
|
+
cacheDir?: string
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* JS-side options accepted by the `BaganCache` constructor (a flattened
|
|
238
|
+
* subset of [`BaganCacheConfig`]; memory budgets only apply through the
|
|
239
|
+
* `withConfig` factory).
|
|
240
|
+
*/
|
|
241
|
+
export interface BaganCacheJsOptions {
|
|
242
|
+
/**
|
|
243
|
+
* Theme package name resolved from [`DEFAULT_THEME_DIR`]; defaults to
|
|
244
|
+
* [`DEFAULT_THEME_NAME`].
|
|
245
|
+
*/
|
|
246
|
+
theme?: string
|
|
247
|
+
/** Markdown parsing/rendering options (`fragment`, GFM, …). */
|
|
248
|
+
markdown?: PeisarOptions
|
|
249
|
+
/** Disk-archive thresholds (shard size / flush interval). */
|
|
250
|
+
archive?: ArchiveConfig
|
|
251
|
+
/** Static-hosting baseUrl resolution. */
|
|
252
|
+
hosting?: HostingConfig
|
|
253
|
+
/** Build output directory. */
|
|
254
|
+
outDir?: string
|
|
255
|
+
/** Disk-archive directory. */
|
|
256
|
+
cacheDir?: string
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Resolved hosting configuration: the single source of truth for every
|
|
261
|
+
* URL the pipeline emits (page slugs, asset links, absolute URLs).
|
|
262
|
+
*/
|
|
263
|
+
export interface BaseDirInfo {
|
|
264
|
+
/** Hosting provider in effect. */
|
|
265
|
+
provider: HostingProvider
|
|
266
|
+
/** Repository name (GitHub Pages project sites): `/<repo>/` prefix. */
|
|
267
|
+
repo?: string
|
|
268
|
+
/**
|
|
269
|
+
* Custom site URL (`https://example.com` or `https://user.github.io/repo`).
|
|
270
|
+
* Used verbatim as the URL root for [`Self::site_url`].
|
|
271
|
+
*/
|
|
272
|
+
siteUrl?: string
|
|
273
|
+
/**
|
|
274
|
+
* Extra path prefix under the host (e.g. `subpath` for
|
|
275
|
+
* `example.com/subpath/`).
|
|
276
|
+
*/
|
|
277
|
+
pathPrefix?: string
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* A file-change event delivered to change callbacks
|
|
282
|
+
* (see [`BaganCache::on_change`]).
|
|
283
|
+
*/
|
|
284
|
+
export interface CacheChangeEvent {
|
|
285
|
+
/** Absolute path of the changed file. */
|
|
286
|
+
path: string
|
|
287
|
+
/** `"create"`, `"modify"`, `"remove"`, or `"other"`. */
|
|
288
|
+
kind: string
|
|
289
|
+
/** `true` when the file is under the markdown entry directory. */
|
|
290
|
+
isMarkdown: boolean
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* An entry stored in the cache: raw UTF-8 text (markdown and textual
|
|
295
|
+
* assets) or raw bytes (binary assets). Exposed to JavaScript so JS
|
|
296
|
+
* consumers can branch on the variant. The serde derives back the
|
|
297
|
+
* bincode round-trip through the disk archive.
|
|
298
|
+
*/
|
|
299
|
+
export type CachedContent =
|
|
300
|
+
| { type: 'Text'; field0: string }
|
|
301
|
+
| { type: 'Binary'; field0: Array<number> }
|
|
302
|
+
|
|
303
|
+
/** Static-hosting configuration for baseUrl resolution. */
|
|
304
|
+
export interface HostingConfig {
|
|
305
|
+
/** Hosting provider (see [`HostingProvider`]). */
|
|
306
|
+
provider?: HostingProvider
|
|
307
|
+
/** GitHub repository name for project pages (`/<repo>/` prefix). */
|
|
308
|
+
repo?: string
|
|
309
|
+
/** Custom site URL (overrides provider defaults when set). */
|
|
310
|
+
siteUrl?: string
|
|
311
|
+
/** Extra path prefix (e.g. `"subpath"` for `example.com/subpath/`). */
|
|
312
|
+
pathPrefix?: string
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** Static site hosting providers with known `baseUrl` behavior. */
|
|
316
|
+
export declare const enum HostingProvider {
|
|
317
|
+
/**
|
|
318
|
+
* GitHub Pages. User/org sites (`<user>.github.io`) serve at `/`;
|
|
319
|
+
* project sites at `/<repo>`. Pass the repository name via
|
|
320
|
+
* `repo` to get the `/<repo>/` prefix.
|
|
321
|
+
*/
|
|
322
|
+
GithubPages = 'GithubPages',
|
|
323
|
+
/** Vercel: always `/` (subpath deployments use rewrites, not paths). */
|
|
324
|
+
Vercel = 'Vercel',
|
|
325
|
+
/** Netlify: always `/`. */
|
|
326
|
+
Netlify = 'Netlify',
|
|
327
|
+
/** Cloudflare Pages: always `/`. */
|
|
328
|
+
CloudflarePages = 'CloudflarePages',
|
|
329
|
+
/** Self-hosted or custom setup: use the `site_base_url` string as given. */
|
|
330
|
+
Custom = 'Custom',
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/** LRU budgets for the memory tier. */
|
|
334
|
+
export interface MemoryConfig {
|
|
335
|
+
/**
|
|
336
|
+
* Maximum total bytes of raw content kept in memory (`0` =
|
|
337
|
+
* unlimited). When the budget is exceeded, the least recently used
|
|
338
|
+
* entries are evicted (they remain readable from the disk archive).
|
|
339
|
+
*/
|
|
340
|
+
byteBudget?: number
|
|
341
|
+
/** Maximum number of entries in memory (`0` = unlimited). */
|
|
342
|
+
entryBudget?: number
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* A page rendered for a Liquid theme: front-matter fields flattened next
|
|
347
|
+
* to pipeline-derived fields (layout, slug, html, …).
|
|
348
|
+
*/
|
|
349
|
+
export interface PageObject {
|
|
350
|
+
/**
|
|
351
|
+
* Layout name from front matter (e.g. `default`, `page`, `post`);
|
|
352
|
+
* `"default"` when front matter does not set one.
|
|
353
|
+
*/
|
|
354
|
+
layout: string
|
|
355
|
+
/**
|
|
356
|
+
* File name without extension (`foo.md` → `foo`); `index` for
|
|
357
|
+
* directory roots. Used as a search / lookup key.
|
|
358
|
+
*/
|
|
359
|
+
fileName: string
|
|
360
|
+
/** Request URL for the page (`path/to/foo.md` → `/path/to/foo`). */
|
|
361
|
+
slug: string
|
|
362
|
+
/** HTML rendered from the markdown by Peisar. */
|
|
363
|
+
html: string
|
|
364
|
+
/**
|
|
365
|
+
* Build output path (`path/to/foo.md` → `outDir/path/to/foo/index.html`),
|
|
366
|
+
* relative to the output root unless absolute.
|
|
367
|
+
*/
|
|
368
|
+
outFilePath: string
|
|
369
|
+
/** Original absolute source path (watch-process identity). */
|
|
370
|
+
inputFilePath: string
|
|
371
|
+
/** Page title (from front matter, or the first `#` heading). */
|
|
372
|
+
title?: string
|
|
373
|
+
/** Short description from front matter. */
|
|
374
|
+
summary?: string
|
|
375
|
+
/** Category tags from front matter. */
|
|
376
|
+
tags?: Array<string>
|
|
377
|
+
/** Publication date from front matter (string form `yyyy-mm-dd`). */
|
|
378
|
+
publishDate?: string
|
|
379
|
+
/**
|
|
380
|
+
* Any extra front-matter keys not mapped to a named field, exposed
|
|
381
|
+
* verbatim (as strings) so themes can render `{{ page.custom }}`.
|
|
382
|
+
*/
|
|
383
|
+
extra?: Record<string, string>
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/** Theme metadata loaded from [`THEME_CONFIG_FILE`]. */
|
|
387
|
+
export interface PeisarThemeConfig {
|
|
388
|
+
/** Theme package name. */
|
|
389
|
+
name: string
|
|
390
|
+
/** Theme package version. */
|
|
391
|
+
version: string
|
|
392
|
+
/** Optional theme author. */
|
|
393
|
+
author?: string
|
|
394
|
+
/** Relative path to the theme's HTML layout templates (default `"_layouts"`). */
|
|
395
|
+
themeLayoutsDir: string
|
|
396
|
+
/** Relative path to the theme's include templates (default `"_includes"`). */
|
|
397
|
+
includesDir: string
|
|
398
|
+
/** Relative path to the theme's static assets (default `"_assets"`). */
|
|
399
|
+
assetsDir: string
|
|
400
|
+
/** Relative path to the theme's data files (default `"_data"`). */
|
|
401
|
+
dataDir: string
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/** Resolved theme directories, as absolute paths. */
|
|
405
|
+
export interface ThemeDirs {
|
|
406
|
+
/** Directory containing the theme's HTML layout templates. */
|
|
407
|
+
layoutsDir: string
|
|
408
|
+
/** Directory containing the theme's static assets. */
|
|
409
|
+
assetsDir: string
|
|
410
|
+
/** Directory containing the theme's data files. */
|
|
411
|
+
dataDir: string
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Parses one Markdown document and exposes its AST, HTML, and front matter
|
|
416
|
+
* to JavaScript.
|
|
417
|
+
*
|
|
418
|
+
* Construct this class with the Markdown source and an optional
|
|
419
|
+
* [`PeisarOptions`] object. Properties are computed from the source document;
|
|
420
|
+
* accessing `ast`, `html`, or `astJson` also applies registered visitors.
|
|
421
|
+
*/
|
|
422
|
+
export declare class Peisar {
|
|
423
|
+
/**
|
|
424
|
+
* Creates a parser for `rawMd`.
|
|
425
|
+
*
|
|
426
|
+
* When `options` is omitted, GFM and Kramdown parsing are enabled and
|
|
427
|
+
* `html` returns a complete HTML document.
|
|
428
|
+
*/
|
|
429
|
+
constructor(rawMd: string, options?: PeisarOptions | undefined | null)
|
|
430
|
+
/**
|
|
431
|
+
* Gets the parsed Markdown document as a JavaScript AST object.
|
|
432
|
+
*
|
|
433
|
+
* Registered visitors run before the AST is returned. The returned value
|
|
434
|
+
* is a clone, so reading this property does not consume the parser state.
|
|
435
|
+
*/
|
|
436
|
+
get ast(): Document
|
|
437
|
+
/**
|
|
438
|
+
* Registers a unified JavaScript plugin.
|
|
439
|
+
*
|
|
440
|
+
* The plugin can provide `visitBlock` / `visitInline` visitor callbacks
|
|
441
|
+
* and `parseBlock` / `parseInline` parser hooks, all in one object.
|
|
442
|
+
* Visitor callbacks receive their node as a one-item tuple: for example,
|
|
443
|
+
* `visitBlock([block]) { return { recurse: true }; }`.
|
|
444
|
+
*/
|
|
445
|
+
use(plugin: Plugin): void
|
|
446
|
+
/**
|
|
447
|
+
* Renders the parsed Markdown as HTML using the configured render options.
|
|
448
|
+
*
|
|
449
|
+
* Registered visitors run before rendering.
|
|
450
|
+
*/
|
|
451
|
+
get html(): string
|
|
452
|
+
/** Gets the deserialized YAML front matter, or `null` when none exists. */
|
|
453
|
+
get frontmatter(): any | null
|
|
454
|
+
/**
|
|
455
|
+
* Gets the parsed Markdown AST serialized as JSON.
|
|
456
|
+
*
|
|
457
|
+
* Registered visitors run before serialization.
|
|
458
|
+
*/
|
|
459
|
+
get astJson(): string
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* JavaScript options for Markdown parsing and HTML rendering.
|
|
464
|
+
*
|
|
465
|
+
* Every property is optional. Omitted parsing options enable GFM and
|
|
466
|
+
* Kramdown; omitted rendering options produce a complete HTML document with
|
|
467
|
+
* charset and viewport metadata.
|
|
468
|
+
*
|
|
469
|
+
* # Defaults
|
|
470
|
+
*
|
|
471
|
+
* | Property | Default |
|
|
472
|
+
* |------------|-------------|
|
|
473
|
+
* | `gfm` | `true` |
|
|
474
|
+
* | `kramdown` | `true` |
|
|
475
|
+
* | `fragment` | `false` (full document) |
|
|
476
|
+
* | `charset` | `true` |
|
|
477
|
+
* | `viewport` | `true` |
|
|
478
|
+
* | `file_name`, `title`, `body_class`, `style` | `null` |
|
|
479
|
+
*/
|
|
480
|
+
export interface PeisarOptions {
|
|
481
|
+
/**
|
|
482
|
+
* Enable GitHub Flavored Markdown (tables, strikethrough, task lists,
|
|
483
|
+
* autolinks). Default: `true`.
|
|
484
|
+
*/
|
|
485
|
+
gfm?: boolean
|
|
486
|
+
/**
|
|
487
|
+
* Enable Kramdown-style block attributes (`{:#id .class key="val"}`).
|
|
488
|
+
* Default: `true`.
|
|
489
|
+
*/
|
|
490
|
+
kramdown?: boolean
|
|
491
|
+
/** Optional file name to attach to the parsed document. */
|
|
492
|
+
fileName?: string
|
|
493
|
+
/**
|
|
494
|
+
* If `true`, emit only the body content (no `<!DOCTYPE>`, `<html>`,
|
|
495
|
+
* `<head>`, or `<body>` wrapper). If `false`, emit a full HTML
|
|
496
|
+
* document. Default: `true` (fragment).
|
|
497
|
+
*/
|
|
498
|
+
fragment?: boolean
|
|
499
|
+
/**
|
|
500
|
+
* Include a `<meta charset="utf-8">` in the head (only relevant when
|
|
501
|
+
* `fragment` is `false`). Default: `true`.
|
|
502
|
+
*/
|
|
503
|
+
charset?: boolean
|
|
504
|
+
/**
|
|
505
|
+
* Include a `<meta name="viewport" content="width=device-width,
|
|
506
|
+
* initial-scale=1.0">` in the head (only relevant when `fragment` is
|
|
507
|
+
* `false`). Default: `true`.
|
|
508
|
+
*/
|
|
509
|
+
viewport?: boolean
|
|
510
|
+
/**
|
|
511
|
+
* Optional `<title>` for the HTML head (only relevant when
|
|
512
|
+
* `fragment` is `false`). Default: `None`.
|
|
513
|
+
*/
|
|
514
|
+
title?: string
|
|
515
|
+
/**
|
|
516
|
+
* Optional additional CSS classes to add to `<body>` (only relevant
|
|
517
|
+
* when `fragment` is `false`). Default: `None`.
|
|
518
|
+
*/
|
|
519
|
+
bodyClass?: string
|
|
520
|
+
/**
|
|
521
|
+
* Optional inline CSS to inject in a `<style>` tag in the head.
|
|
522
|
+
* Default: `None`.
|
|
523
|
+
*/
|
|
524
|
+
style?: string
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
export declare function renderDocumentHtml(doc: Document, opts?: RenderOptions | undefined | null): string
|
|
528
|
+
|
|
529
|
+
/** Options that control how the AST is rendered to HTML. */
|
|
530
|
+
export interface RenderOptions {
|
|
531
|
+
/**
|
|
532
|
+
* If `true`, emit only the body content (no `<!DOCTYPE>`, `<html>`,
|
|
533
|
+
* `<head>`, or `<body>` wrapper). If `false`, emit a full HTML
|
|
534
|
+
* document. Default: `true` (fragment).
|
|
535
|
+
*/
|
|
536
|
+
fragment: boolean
|
|
537
|
+
/**
|
|
538
|
+
* Include a `<meta charset="utf-8">` in the head (only relevant when
|
|
539
|
+
* `fragment` is `false`). Default: `true`.
|
|
540
|
+
*/
|
|
541
|
+
charset: boolean
|
|
542
|
+
/**
|
|
543
|
+
* Include a `<meta name="viewport" content="width=device-width,
|
|
544
|
+
* initial-scale=1.0">` in the head (only relevant when `fragment` is
|
|
545
|
+
* `false`). Default: `true`.
|
|
546
|
+
*/
|
|
547
|
+
viewport: boolean
|
|
548
|
+
/**
|
|
549
|
+
* Optional `<title>` for the HTML head (only relevant when
|
|
550
|
+
* `fragment` is `false`). Default: `None`.
|
|
551
|
+
*/
|
|
552
|
+
title?: string
|
|
553
|
+
/**
|
|
554
|
+
* Optional additional CSS classes to add to `<body>` (only relevant
|
|
555
|
+
* when `fragment` is `false`). Default: `None`.
|
|
556
|
+
*/
|
|
557
|
+
bodyClass?: string
|
|
558
|
+
/**
|
|
559
|
+
* Optional inline CSS to inject in a `<style>` tag in the head.
|
|
560
|
+
* Default: `None`.
|
|
561
|
+
*/
|
|
562
|
+
style?: string
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Markdown source parsed into an AST, with optional YAML front matter and
|
|
567
|
+
* registered plugins.
|
|
568
|
+
*/
|
|
569
|
+
export declare class PeisarAst {}
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* Options that control how Markdown is parsed.
|
|
573
|
+
*
|
|
574
|
+
* # Defaults
|
|
575
|
+
*
|
|
576
|
+
* Both GFM and Kramdown extensions are enabled by default. To parse
|
|
577
|
+
* strict CommonMark only:
|
|
578
|
+
*/
|
|
579
|
+
export interface AstOptions {
|
|
580
|
+
/**
|
|
581
|
+
* Enable GitHub Flavored Markdown (tables, strikethrough, task lists,
|
|
582
|
+
* autolinks). Default: `true`.
|
|
583
|
+
*/
|
|
584
|
+
gfm: boolean
|
|
585
|
+
/**
|
|
586
|
+
* Enable Kramdown-style block attributes (`{:#id .class key="val"}`).
|
|
587
|
+
* Default: `true`.
|
|
588
|
+
*/
|
|
589
|
+
kramdown: boolean
|
|
590
|
+
/**
|
|
591
|
+
* Optional file name to attach to the parsed
|
|
592
|
+
* [`Document`](crate::Document).
|
|
593
|
+
*/
|
|
594
|
+
fileName?: string
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/** Parsed Kramdown block attributes (`{:#id .class key="val"}`). */
|
|
598
|
+
export interface Attributes {
|
|
599
|
+
/** HTML `id` attribute. */
|
|
600
|
+
id?: string
|
|
601
|
+
/** CSS class list. */
|
|
602
|
+
classes?: Array<string>
|
|
603
|
+
/** Arbitrary key/value attributes. */
|
|
604
|
+
attributes?: Array<[string, string]>
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
/** Block-level nodes. */
|
|
608
|
+
export type Block =
|
|
609
|
+
| { type: 'Heading'; /** Heading level (1–6). */
|
|
610
|
+
level: number; /** Inline content of the heading. */
|
|
611
|
+
children: Array<Inline>; /** Source span. */
|
|
612
|
+
pos: Span; /** Optional Kramdown attributes. */
|
|
613
|
+
attrs?: Attributes }
|
|
614
|
+
| { type: 'Paragraph'; /** Inline content of the paragraph. */
|
|
615
|
+
children: Array<Inline>; /** Source span. */
|
|
616
|
+
pos: Span; /** Optional Kramdown attributes. */
|
|
617
|
+
attrs?: Attributes }
|
|
618
|
+
| { type: 'CodeBlock'; /** Language hint from the info string (e.g. `rust` from ` ```rust `). */
|
|
619
|
+
lang?: string; /** The raw code content. */
|
|
620
|
+
code: string; /** Source span. */
|
|
621
|
+
pos: Span; /** Optional Kramdown attributes. */
|
|
622
|
+
attrs?: Attributes }
|
|
623
|
+
| { type: 'BlockQuote'; /** Nested block content inside the quote. */
|
|
624
|
+
children: Array<Block>; /** Source span. */
|
|
625
|
+
pos: Span; /** Optional Kramdown attributes. */
|
|
626
|
+
attrs?: Attributes }
|
|
627
|
+
| { type: 'List'; /** `true` for ordered lists, `false` for unordered. */
|
|
628
|
+
ordered: boolean; /** The list items. */
|
|
629
|
+
items: Array<ListItem>; /** Source span. */
|
|
630
|
+
pos: Span; /** Optional Kramdown attributes. */
|
|
631
|
+
attrs?: Attributes }
|
|
632
|
+
| { type: 'ThematicBreak'; /** Source span. */
|
|
633
|
+
pos: Span }
|
|
634
|
+
| { type: 'HtmlBlock'; /** The raw HTML content. */
|
|
635
|
+
html: string; /** Source span. */
|
|
636
|
+
pos: Span; /** Optional Kramdown attributes. */
|
|
637
|
+
attrs?: Attributes }
|
|
638
|
+
| { type: 'Table'; /** The table structure (header, rows, alignments). */
|
|
639
|
+
table: Table; /** Source span. */
|
|
640
|
+
pos: Span; /** Optional Kramdown attributes. */
|
|
641
|
+
attrs?: Attributes }
|
|
642
|
+
| { type: 'LinkReferenceDefinition'; /** Normalized label (lowercased, trimmed). */
|
|
643
|
+
label: string; /** The destination URL. */
|
|
644
|
+
url: string; /** Optional link title. */
|
|
645
|
+
title?: string; /** Source span. */
|
|
646
|
+
pos: Span }
|
|
647
|
+
| { type: 'Comment'; /** The comment text (markers stripped). */
|
|
648
|
+
value: string; /** Source span. */
|
|
649
|
+
pos: Span }
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Synchronous block-visitor callback. Receives a `Block`, returns
|
|
653
|
+
* `VisitControlJs` (or `undefined` for no changes).
|
|
654
|
+
*/
|
|
655
|
+
export type BlockCallback = (arg: [Block]) => VisitorControl | null
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* Synchronous block parser hook. Receives a [`BlockParserContext`], returns
|
|
659
|
+
* a [`BlockParseResultJs`] (or `undefined` to decline).
|
|
660
|
+
*/
|
|
661
|
+
export type BlockParseCallback = (arg: [BlockParserContext]) => BlockParseResult | null
|
|
662
|
+
|
|
663
|
+
/** Context passed to block parser hooks. */
|
|
664
|
+
export interface BlockParserContext {
|
|
665
|
+
/** The current (unmodified) source line. */
|
|
666
|
+
line: string
|
|
667
|
+
/** 0-based index of the current line in the (sub-)document. */
|
|
668
|
+
lineIndex: number
|
|
669
|
+
/** Remaining lines starting at the current line (`lines[0]` is `line`). */
|
|
670
|
+
lines: Array<string>
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* Result returned from the JS `parseBlock` callback.
|
|
675
|
+
*
|
|
676
|
+
* All fields are optional; omitting `block` (or returning `undefined`)
|
|
677
|
+
* declines the position so the next hook / built-in parser handles it.
|
|
678
|
+
*/
|
|
679
|
+
export interface BlockParseResult {
|
|
680
|
+
/** The parsed block node. */
|
|
681
|
+
block?: Block
|
|
682
|
+
/** Number of source lines consumed (must be at least `1`). */
|
|
683
|
+
consumed?: number
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* A Markdown document — the root of the AST.
|
|
688
|
+
*
|
|
689
|
+
* Contains the top-level block children and all link reference definitions
|
|
690
|
+
* collected from the source text.
|
|
691
|
+
*/
|
|
692
|
+
export interface Document {
|
|
693
|
+
/** Always `"root"`. */
|
|
694
|
+
nodeType: string
|
|
695
|
+
/** Optional source file name. */
|
|
696
|
+
fileName?: string
|
|
697
|
+
/** Span of the whole document in the source text. */
|
|
698
|
+
pos: Span
|
|
699
|
+
/** Top-level block children. */
|
|
700
|
+
children: Array<Block>
|
|
701
|
+
/** All link reference definitions collected from the document. */
|
|
702
|
+
linkReferences: Array<LinkReferenceDefinition>
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
/** Inline-level nodes. */
|
|
706
|
+
export type Inline =
|
|
707
|
+
| { type: 'Text'; /** The text value. */
|
|
708
|
+
value: string; /** Source span. */
|
|
709
|
+
pos: Span }
|
|
710
|
+
| { type: 'Emphasis'; /** Emphasis level (italic or bold). */
|
|
711
|
+
level: PeisarEmphasisLevel; /** Nested inline content. */
|
|
712
|
+
children: Array<Inline>; /** Source span. */
|
|
713
|
+
pos: Span }
|
|
714
|
+
| { type: 'Code'; /** The code text. */
|
|
715
|
+
code: string; /** Source span. */
|
|
716
|
+
pos: Span }
|
|
717
|
+
| { type: 'HtmlInline'; /** The raw HTML string. */
|
|
718
|
+
html: string; /** Source span. */
|
|
719
|
+
pos: Span }
|
|
720
|
+
| { type: 'Strikethrough'; /** Nested inline content. */
|
|
721
|
+
children: Array<Inline>; /** Source span. */
|
|
722
|
+
pos: Span }
|
|
723
|
+
| { type: 'HardBreak'; /** Source span. */
|
|
724
|
+
pos: Span }
|
|
725
|
+
| { type: 'SoftBreak'; /** Source span. */
|
|
726
|
+
pos: Span }
|
|
727
|
+
| { type: 'Image'; /** Alternative text. */
|
|
728
|
+
alt: string; /** Image URL. */
|
|
729
|
+
url: string; /** Optional title. */
|
|
730
|
+
title?: string; /** Source span. */
|
|
731
|
+
pos: Span }
|
|
732
|
+
| { type: 'Link'; /** Link text (inline children). */
|
|
733
|
+
text: Array<Inline>; /** Destination URL. */
|
|
734
|
+
url: string; /** Optional link title. */
|
|
735
|
+
title?: string; /** `true` if this is a GFM autolink (bare URL). */
|
|
736
|
+
autolink: boolean; /** Source span. */
|
|
737
|
+
pos: Span }
|
|
738
|
+
| { type: 'LinkReference'; /** Link text (inline children). */
|
|
739
|
+
text: Array<Inline>; /** Normalized label used to look up the reference. */
|
|
740
|
+
label: string; /** Resolved destination URL. */
|
|
741
|
+
url: string; /** Optional resolved title. */
|
|
742
|
+
title?: string; /** Source span. */
|
|
743
|
+
pos: Span }
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* Synchronous inline-visitor callback. Receives an `Inline`, returns
|
|
747
|
+
* `InlineVisitControlJs` (or `undefined` for no changes).
|
|
748
|
+
*/
|
|
749
|
+
export type InlineCallback = (arg: [Inline]) => InlineVisitorControl | null
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* Synchronous inline parser hook. Receives an [`InlineParserContext`],
|
|
753
|
+
* returns an [`InlineParseResultJs`] (or `undefined` to decline).
|
|
754
|
+
*/
|
|
755
|
+
export type InlineParseCallback = (arg: [InlineParserContext]) => InlineParseResult | null
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* Context passed to inline parser hooks.
|
|
759
|
+
*
|
|
760
|
+
* On the JavaScript side the fields are exposed as `rest` and `index`.
|
|
761
|
+
*/
|
|
762
|
+
export interface InlineParserContext {
|
|
763
|
+
/** Remaining inline text starting at the current character position. */
|
|
764
|
+
rest: string
|
|
765
|
+
/** 0-based character index of the current position in the inline text. */
|
|
766
|
+
index: number
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* Result returned from the JS `parseInline` callback.
|
|
771
|
+
*
|
|
772
|
+
* All fields are optional; omitting `inline` (or returning `undefined`)
|
|
773
|
+
* declines the position so the next hook / built-in parser handles it.
|
|
774
|
+
*/
|
|
775
|
+
export interface InlineParseResult {
|
|
776
|
+
/** The parsed inline node. */
|
|
777
|
+
inline?: Inline
|
|
778
|
+
/** Number of characters consumed (`0` or missing declines). */
|
|
779
|
+
consumed?: number
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* JS-facing mirror of [`InlineVisitControl`].
|
|
784
|
+
*
|
|
785
|
+
* Returned from the JS `visitInline` callback. All fields are optional;
|
|
786
|
+
* omitting a field means "no change" for that operation.
|
|
787
|
+
*/
|
|
788
|
+
export interface InlineVisitorControl {
|
|
789
|
+
/** Nodes to insert before the current node. */
|
|
790
|
+
insertBefore?: Array<Inline>
|
|
791
|
+
/** Nodes to insert after the current node. */
|
|
792
|
+
insertAfter?: Array<Inline>
|
|
793
|
+
/** Replace the current node with these nodes. */
|
|
794
|
+
replaceWith?: Array<Inline>
|
|
795
|
+
/** Remove the current node entirely. */
|
|
796
|
+
remove?: boolean
|
|
797
|
+
/** Whether to recurse into this node's children. */
|
|
798
|
+
recurse?: boolean
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
/** A link reference definition collected at the document level. */
|
|
802
|
+
export interface LinkReferenceDefinition {
|
|
803
|
+
/** Normalized label (lowercased, trimmed). */
|
|
804
|
+
label: string
|
|
805
|
+
/** The destination URL. */
|
|
806
|
+
url: string
|
|
807
|
+
/** Optional link title. */
|
|
808
|
+
title?: string
|
|
809
|
+
/** Source span. */
|
|
810
|
+
pos: Span
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
/** A single list item (an `<li>`). Contains nested block content. */
|
|
814
|
+
export interface ListItem {
|
|
815
|
+
/** Nested block content of the item. */
|
|
816
|
+
children: Array<Block>
|
|
817
|
+
/** GFM task-list state: `None` = not a task, `Some` = checked / unchecked. */
|
|
818
|
+
task?: PeisarTaskState
|
|
819
|
+
/** Span of the item in the *sub-document* of its enclosing list. */
|
|
820
|
+
pos: Span
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* A plugin containing optional Markdown parser hooks and AST visitor
|
|
825
|
+
* callbacks.
|
|
826
|
+
*/
|
|
827
|
+
export interface Plugin {
|
|
828
|
+
/** Optional JS callback for block nodes (JS: `visitBlock`). */
|
|
829
|
+
visitBlock?: BlockCallback
|
|
830
|
+
/** Optional JS callback for inline nodes (JS: `visitInline`). */
|
|
831
|
+
visitInline?: InlineCallback
|
|
832
|
+
/** Optional JS block parser hook (JS: `parseBlock`). */
|
|
833
|
+
parseBlock?: BlockParseCallback
|
|
834
|
+
/** Optional JS inline parser hook (JS: `parseInline`). */
|
|
835
|
+
parseInline?: InlineParseCallback
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/** A zero-based point in the source text. */
|
|
839
|
+
export interface Position {
|
|
840
|
+
/** Line number, 0-based. */
|
|
841
|
+
line: number
|
|
842
|
+
/** Column number, 0-based (in characters). */
|
|
843
|
+
column: number
|
|
844
|
+
/** Byte offset from the start of the input. */
|
|
845
|
+
offset: number
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
/**
|
|
849
|
+
* A half-open span `[start, end)` covering a node's source text.
|
|
850
|
+
*
|
|
851
|
+
* `start` is inclusive and `end` is exclusive; both positions point into the
|
|
852
|
+
* original source string.
|
|
853
|
+
*/
|
|
854
|
+
export interface Span {
|
|
855
|
+
/** The start position (inclusive). */
|
|
856
|
+
start: Position
|
|
857
|
+
/** The end position (exclusive). */
|
|
858
|
+
end: Position
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
/** A GFM table. */
|
|
862
|
+
export interface Table {
|
|
863
|
+
/** The header row. */
|
|
864
|
+
header: TableRow
|
|
865
|
+
/** Body rows. */
|
|
866
|
+
rows: Array<TableRow>
|
|
867
|
+
/** Column alignment specifications (one per column). */
|
|
868
|
+
alignments: PeisarTableCellAlignments
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
/** A single table cell. */
|
|
872
|
+
export interface TableCell {
|
|
873
|
+
/** Inline content of the cell. */
|
|
874
|
+
children: Array<Inline>
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
/** A single table row (header or body). */
|
|
878
|
+
export interface TableRow {
|
|
879
|
+
/** The cells in this row. */
|
|
880
|
+
cells: Array<TableCell>
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
/**
|
|
884
|
+
* JS-facing mirror of [`VisitControl`].
|
|
885
|
+
*
|
|
886
|
+
* Returned from the JS `visitBlock` callback. All fields are optional;
|
|
887
|
+
* omitting a field means "no change" for that operation.
|
|
888
|
+
*/
|
|
889
|
+
export interface VisitorControl {
|
|
890
|
+
/** Nodes to insert before the current node. */
|
|
891
|
+
insertBefore?: Array<Block>
|
|
892
|
+
/** Nodes to insert after the current node. */
|
|
893
|
+
insertAfter?: Array<Block>
|
|
894
|
+
/** Replace the current node with these nodes. */
|
|
895
|
+
replaceWith?: Array<Block>
|
|
896
|
+
/** Remove the current node entirely. */
|
|
897
|
+
remove?: boolean
|
|
898
|
+
/** Whether to recurse into this node's children. */
|
|
899
|
+
recurse?: boolean
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
/**
|
|
903
|
+
* Parses YAML front matter from Markdown content.
|
|
904
|
+
*
|
|
905
|
+
* Returns an N-API error if the front matter is present but invalid.
|
|
906
|
+
*/
|
|
907
|
+
export declare function frontmatter(content: string): FrontmatterResult
|
|
908
|
+
|
|
909
|
+
export interface FrontmatterResult {
|
|
910
|
+
/** Clean content after the leading YAML front matter is removed. */
|
|
911
|
+
cleanContent: string
|
|
912
|
+
/** Deserialized YAML front matter, or `null` when no front matter exists. */
|
|
913
|
+
yamlData?: Record<string, any>
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
/**
|
|
917
|
+
* Reads and parses a YAML file relative to the process's current working
|
|
918
|
+
* directory.
|
|
919
|
+
*
|
|
920
|
+
* The parsed YAML value is returned to Node.js as a JavaScript value. File
|
|
921
|
+
* read failures panic in this N-API wrapper; parse failures are returned as
|
|
922
|
+
* N-API errors.
|
|
923
|
+
*/
|
|
924
|
+
export declare function loadYaml(filePath: string): Record<string, any>
|
|
925
|
+
|
|
926
|
+
/**
|
|
927
|
+
* Parses a YAML document into a JSON-compatible value.
|
|
928
|
+
*
|
|
929
|
+
* When consumed from Node.js, the result is exposed as a JavaScript object
|
|
930
|
+
* with the TypeScript type `Record<string, any>`.
|
|
931
|
+
*
|
|
932
|
+
* Returns an N-API error if the YAML input cannot be parsed.
|
|
933
|
+
*/
|
|
934
|
+
export declare function yamlParser(yamlStr: string): Record<string, any>
|