@markup-carve/carve-wasm 0.1.1 → 0.1.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/README.md +123 -6
- package/carve_wasm.d.ts +113 -0
- package/carve_wasm.js +1 -1
- package/carve_wasm_bg.js +202 -0
- package/carve_wasm_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -132,11 +132,25 @@ toHtmlWithOptions('# A\n\np\n', { sections: false })
|
|
|
132
132
|
toHtmlWithOptions(src, { sections: false, symbols: { rocket: '🚀' }, full: true })
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
-
Every field is optional
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
Every field is optional. Omitting the object, or passing `null`, renders with
|
|
136
|
+
defaults, so the three shorthands above remain the zero-config forms.
|
|
137
|
+
|
|
138
|
+
| Field | Default | What it does |
|
|
139
|
+
|---|---|---|
|
|
140
|
+
| `sections` | `true` | Wrap each top-level heading and its content in a `<section>` |
|
|
141
|
+
| `symbols` | none | `:name:` to value, TRUSTED-RAW (see above) |
|
|
142
|
+
| `extensions` | none | Array of registry names; takes precedence over `full` |
|
|
143
|
+
| `full` | `false` | Enable the preview extension set |
|
|
144
|
+
| `rawHtml` | `true` | Emit an explicit passthrough as markup; `false` escapes it |
|
|
145
|
+
| `profile` | none | `full` / `article` / `comment` / `minimal`; rejection throws |
|
|
146
|
+
| `profileBaseHost` | none | The host the profile's link policy counts as internal |
|
|
147
|
+
| `mode` | `interactive` | `static` renders the self-contained form: no client scripts |
|
|
148
|
+
| `sourceLine` | `false` | Stamp top-level blocks with `data-source-line` |
|
|
149
|
+
| `positions` | `false` | Keep source offsets on the nodes |
|
|
150
|
+
| `labels` | none | Override engine-written strings, for a page not in English |
|
|
151
|
+
| `smartTypography` | `glyph` | `source` keeps the author's run instead of the glyph |
|
|
152
|
+
| `lowercaseHeadingIds` | `false` | Lowercase the generated heading ids |
|
|
153
|
+
| `asciiHeadingIds` | `off` | `fold` transliterates, `strict` guarantees ASCII |
|
|
140
154
|
|
|
141
155
|
An unrecognized key is ignored, because the object is configuration and a typo
|
|
142
156
|
should not break a render. A recognized key with the wrong type throws a
|
|
@@ -154,6 +168,72 @@ Nothing else changes: ids, collision dedup, `</#id>` cross-references, implicit
|
|
|
154
168
|
rather than the element carrying it. The endnotes
|
|
155
169
|
`<section role="doc-endnotes">` is a separate construct and is still emitted.
|
|
156
170
|
|
|
171
|
+
### Rendering a document you did not write
|
|
172
|
+
|
|
173
|
+
`rawHtml: false` renders an explicit passthrough - the `=html` raw block and the
|
|
174
|
+
`` `…`{=html} `` inline raw span - as escaped text instead of markup. It is the
|
|
175
|
+
switch carve-js spells `allowRawHtml`.
|
|
176
|
+
|
|
177
|
+
```js
|
|
178
|
+
toHtmlWithOptions(fromTheReader, { rawHtml: false })
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Reach for it whenever the document comes from somewhere other than the person
|
|
182
|
+
running the page: a shared link, a comment field, a pasted file. A passthrough is
|
|
183
|
+
the one construct that puts author-controlled markup on your origin, so leaving
|
|
184
|
+
it on for a document a reader supplied is a way to run their script.
|
|
185
|
+
|
|
186
|
+
The symbols map is unaffected and stays TRUSTED-RAW either way - it is
|
|
187
|
+
configuration the host wrote, not content the document carries.
|
|
188
|
+
|
|
189
|
+
### Rendering with a profile
|
|
190
|
+
|
|
191
|
+
`rawHtml: false` closes the passthrough vector. It does not cap input length,
|
|
192
|
+
deny a construct, or constrain link schemes - that is what a profile is for, and
|
|
193
|
+
the four presets match the ones the spec and the sibling bindings describe.
|
|
194
|
+
|
|
195
|
+
```js
|
|
196
|
+
toHtmlWithOptions(fromTheReader, { profile: 'comment', rawHtml: false })
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
**A rejected document throws.** The engine's infallible entry point turns a
|
|
200
|
+
profile rejection - input past `max_length`, or a denied construct when the
|
|
201
|
+
action is Error - into an EMPTY STRING, and a caller cannot tell that from a
|
|
202
|
+
document that legitimately rendered to nothing. This binding renders through the
|
|
203
|
+
fallible one, so a rejection arrives as an `Error` whose `name` is
|
|
204
|
+
`ProfileViolationError` and whose `violations` array carries one message per
|
|
205
|
+
refused construct.
|
|
206
|
+
|
|
207
|
+
```js
|
|
208
|
+
try {
|
|
209
|
+
html = toHtmlWithOptions(fromTheReader, { profile: 'comment' })
|
|
210
|
+
} catch (error) {
|
|
211
|
+
if (error.name === 'ProfileViolationError') report(error.violations)
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Editing a tree, and reading one back
|
|
216
|
+
|
|
217
|
+
`parseJson` serializes a document out. `astJsonToHtml` renders one back, and
|
|
218
|
+
`astJsonToCarve` writes one back as source, so a host that reads the tree in
|
|
219
|
+
order to change something can display and save the result without a server.
|
|
220
|
+
|
|
221
|
+
```js
|
|
222
|
+
const tree = JSON.parse(parseJson(source))
|
|
223
|
+
tree.children.unshift({ type: 'heading', level: 1, children: [{ type: 'text', value: 'Added' }] })
|
|
224
|
+
const html = astJsonToHtml(JSON.stringify(tree), { full: true })
|
|
225
|
+
const carve = astJsonToCarve(JSON.stringify(tree))
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
A tree carrying something no Carve source can spell is refused by
|
|
229
|
+
`astJsonToCarve` rather than written approximately, and an invalid tree throws
|
|
230
|
+
from either.
|
|
231
|
+
|
|
232
|
+
`lintCarve` returns the degradation diagnostics as
|
|
233
|
+
`{ line, column, rule, message, start, end }`, with the rule ids carve-js and
|
|
234
|
+
carve-php use for the same triggers. Offsets are BYTE offsets into the source,
|
|
235
|
+
matching the engine.
|
|
236
|
+
|
|
157
237
|
### TypeScript
|
|
158
238
|
|
|
159
239
|
The package ships `.d.ts` declarations. Types are inferred automatically when
|
|
@@ -173,13 +253,20 @@ const html: string = toHtml('_Hello_')
|
|
|
173
253
|
| `toHtml` | `(source: string) => string` | Core renderer, no extensions |
|
|
174
254
|
| `toHtmlWithSymbols` | `(source: string, symbols?: object \| null) => string` | Core renderer + a `:name:` -> value symbols map (values are raw, see above) |
|
|
175
255
|
| `toHtmlFull` | `(source: string, symbols?: object \| null) => string` | Core + common extensions (matches playground), optional symbols map |
|
|
176
|
-
| `toHtmlWithOptions` | `(source: string, options?: object \| null) => string` | General form
|
|
256
|
+
| `toHtmlWithOptions` | `(source: string, options?: object \| null) => string` | General form; see the options table above. Throws `ProfileViolationError` when a profile rejects the document |
|
|
177
257
|
| `toHtmlWithReport` | `(source: string, strict?: boolean, maximum?: number) => RenderResult` | HTML plus bounded `raw-format-dropped` losses; strict mode throws `RenderLossError` |
|
|
178
258
|
| `toMarkdownWithReport` | `(source: string, strict?: boolean, maximum?: number) => RenderResult` | Checked Markdown render |
|
|
179
259
|
| `toPlainTextWithReport` | `(source: string, strict?: boolean, maximum?: number) => RenderResult` | Checked plain-text render |
|
|
180
260
|
| `toAnsiWithReport` | `(source: string, strict?: boolean, maximum?: number) => RenderResult` | Checked ANSI render |
|
|
181
261
|
| `toCarveWithReport` | `(source: string, strict?: boolean, maximum?: number) => RenderResult` | Checked canonical Carve render (lossless) |
|
|
182
262
|
| `parseJson` | `(source: string) => string` | The parsed AST as JSON (PART 12 exchange shape) |
|
|
263
|
+
| `astJsonToHtml` | `(json: string, options?: object \| null) => string` | Render an AST-JSON document; takes the same options object |
|
|
264
|
+
| `astJsonToCarve` | `(json: string) => string` | Write an AST-JSON document back as canonical Carve source |
|
|
265
|
+
| `lintCarve` | `(source: string) => LintWarning[]` | Degradation diagnostics, with the rule ids carve-js and carve-php share |
|
|
266
|
+
| `readStamp` | `(source: string) => { version, generatedBy } \| null` | The document's provenance marker, if it carries one |
|
|
267
|
+
| `needsReview` | `(source: string, currentVersion: string) => boolean` | Whether the stamp predates `currentVersion`; unstamped counts as yes |
|
|
268
|
+
| `fromDjot` | `(source: string) => string` | Convert Djot source to Carve |
|
|
269
|
+
| `fromBbcode` | `(source: string) => string` | Convert BBCode source to Carve; throws past the engine's size cap |
|
|
183
270
|
| `version` | `() => string` | Returns the carve-wasm package version |
|
|
184
271
|
|
|
185
272
|
### The parsed AST
|
|
@@ -309,6 +396,36 @@ CARVE_WASM_PKG=some/other/pkg node tests/smoke.mjs
|
|
|
309
396
|
Both wasm-pack targets load. Unset, it is `pkg/`, so nothing changes for the
|
|
310
397
|
ordinary loop.
|
|
311
398
|
|
|
399
|
+
### Rendering-only browser build
|
|
400
|
+
|
|
401
|
+
All capabilities are enabled by default, so ordinary builds and the published
|
|
402
|
+
package keep their complete API. A browser host that only renders Carve to HTML
|
|
403
|
+
can leave the importers, reports, AST serialization, and other output formats
|
|
404
|
+
out of its artifact:
|
|
405
|
+
|
|
406
|
+
```sh
|
|
407
|
+
wasm-pack build --target web --release --out-dir pkg-render . --no-default-features
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
The basic HTML rendering exports, including `toHtml`, `toHtmlFull`, and
|
|
411
|
+
`toHtmlWithOptions`, remain available. Checked rendering through
|
|
412
|
+
`toHtmlWithReport` is part of the omitted `reports` capability. The optional
|
|
413
|
+
features are:
|
|
414
|
+
|
|
415
|
+
| Feature | Exports |
|
|
416
|
+
| --- | --- |
|
|
417
|
+
| `html-import` | `htmlToCarve`, `fromHtml` |
|
|
418
|
+
| `markdown-import` | `fromMarkdown` |
|
|
419
|
+
| `reports` | all five `*WithReport` renderers |
|
|
420
|
+
| `ast-json` | `parseJson`, `astJsonToHtml`, `astJsonToCarve` |
|
|
421
|
+
| `other-renderers` | the basic Markdown, plain-text, ANSI, and Carve renderers |
|
|
422
|
+
| `lint` | `lintCarve` |
|
|
423
|
+
| `stamp` | `readStamp`, `needsReview` |
|
|
424
|
+
| `other-imports` | `fromDjot`, `fromBbcode` |
|
|
425
|
+
|
|
426
|
+
Use a separate output directory as above if a full build also exists in the
|
|
427
|
+
checkout.
|
|
428
|
+
|
|
312
429
|
## Release
|
|
313
430
|
|
|
314
431
|
Publishing is gated. `.github/workflows/release.yml` has two jobs, and
|
package/carve_wasm.d.ts
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
|
|
4
|
+
export interface LintWarning {
|
|
5
|
+
/** 1-based line number. */
|
|
6
|
+
line: number;
|
|
7
|
+
/** 1-based column number. */
|
|
8
|
+
column: number;
|
|
9
|
+
/** Stable rule id, shared with carve-js and carve-php. */
|
|
10
|
+
rule: string;
|
|
11
|
+
message: string;
|
|
12
|
+
/** 0-based BYTE offset into the source, inclusive. */
|
|
13
|
+
start: number;
|
|
14
|
+
/** 0-based BYTE offset into the source, exclusive. */
|
|
15
|
+
end: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface Stamp {
|
|
19
|
+
/** The spec version the document was last processed under. */
|
|
20
|
+
version: string;
|
|
21
|
+
/** The engine that wrote the marker, when it recorded one. */
|
|
22
|
+
generatedBy: string | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Render an AST-JSON document (PART 12) back to canonical Carve source.
|
|
29
|
+
*
|
|
30
|
+
* The round trip a host needs to SAVE an edited tree, rather than only display
|
|
31
|
+
* it. A tree holding something no Carve source can spell is refused rather
|
|
32
|
+
* than written approximately.
|
|
33
|
+
*/
|
|
34
|
+
export function astJsonToCarve(json: string): string;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Render an AST-JSON document (PART 12) to HTML.
|
|
38
|
+
*
|
|
39
|
+
* The other half of `parseJson`. A host that reads the tree in a browser does
|
|
40
|
+
* it to CHANGE something, and until now there was no way to render the result:
|
|
41
|
+
* the binding could serialize a tree out and not take one back.
|
|
42
|
+
*
|
|
43
|
+
* Takes the same options object as [`to_html_with_options`], so an edited tree
|
|
44
|
+
* renders under the profile, labels and switches the host already configured.
|
|
45
|
+
*/
|
|
46
|
+
export function astJsonToHtml(json: string, options?: object | null): string;
|
|
47
|
+
|
|
4
48
|
/**
|
|
5
49
|
* Every extension name this build accepts, in registry order.
|
|
6
50
|
*
|
|
@@ -9,6 +53,24 @@
|
|
|
9
53
|
*/
|
|
10
54
|
export function extensions(): string[];
|
|
11
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Convert BBCode source to Carve.
|
|
58
|
+
*
|
|
59
|
+
* Rejects input past the engine's `BBCODE_MAX_INPUT_LENGTH` rather than
|
|
60
|
+
* working on it: the importer's cost is superlinear in places, and a browser
|
|
61
|
+
* host cannot afford to find that out on the main thread.
|
|
62
|
+
*/
|
|
63
|
+
export function fromBbcode(source: string): string;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Convert Djot source to Carve.
|
|
67
|
+
*
|
|
68
|
+
* Carve diverges from Djot deliberately - the emphasis delimiters are swapped,
|
|
69
|
+
* among others - so a Djot document is not Carve source and pasting one in
|
|
70
|
+
* renders wrongly rather than failing.
|
|
71
|
+
*/
|
|
72
|
+
export function fromDjot(source: string): string;
|
|
73
|
+
|
|
12
74
|
export function fromHtml(source: string, mode?: string | null): any;
|
|
13
75
|
|
|
14
76
|
export function fromMarkdown(source: string): any;
|
|
@@ -21,6 +83,25 @@ export function fromMarkdown(source: string): any;
|
|
|
21
83
|
*/
|
|
22
84
|
export function htmlToCarve(source: string, mode?: string | null): any;
|
|
23
85
|
|
|
86
|
+
/**
|
|
87
|
+
* Lint a document for the degradations PART 15 describes.
|
|
88
|
+
*
|
|
89
|
+
* Returns an array of `{ line, column, rule, message, start, end }`. The rule
|
|
90
|
+
* ids are shared with carve-js and carve-php, so the same trigger reports the
|
|
91
|
+
* same id everywhere. Offsets are BYTE offsets into the source, matching the
|
|
92
|
+
* engine.
|
|
93
|
+
*
|
|
94
|
+
* Built as JS objects rather than a JSON string: a message carries arbitrary
|
|
95
|
+
* document text, and hand-rolled JSON escaping is where that goes wrong.
|
|
96
|
+
*/
|
|
97
|
+
export function lintCarve(source: string): LintWarning[];
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Whether a document was last processed under an older spec version than
|
|
101
|
+
* `currentVersion`. An unstamped document counts as needing review.
|
|
102
|
+
*/
|
|
103
|
+
export function needsReview(source: string, current_version: string): boolean;
|
|
104
|
+
|
|
24
105
|
/**
|
|
25
106
|
* Parse Carve source and return its AST as a JSON string.
|
|
26
107
|
*
|
|
@@ -41,6 +122,11 @@ export function htmlToCarve(source: string, mode?: string | null): any;
|
|
|
41
122
|
*/
|
|
42
123
|
export function parseJson(source: string): string;
|
|
43
124
|
|
|
125
|
+
/**
|
|
126
|
+
* Read a document's provenance marker: `{ version, generatedBy }`, or `null`.
|
|
127
|
+
*/
|
|
128
|
+
export function readStamp(source: string): Stamp | null;
|
|
129
|
+
|
|
44
130
|
export function toAnsi(source: string): string;
|
|
45
131
|
|
|
46
132
|
export function toAnsiWithReport(source: string, strict?: boolean | null, maximum?: number | null): any;
|
|
@@ -76,6 +162,8 @@ export function toHtmlFull(source: string, symbols?: object | null): string;
|
|
|
76
162
|
* // '<h1 id="A">A</h1>\n<p>p</p>'
|
|
77
163
|
*
|
|
78
164
|
* toHtmlWithOptions(src, { sections: false, symbols: { rocket: '🚀' }, full: true })
|
|
165
|
+
*
|
|
166
|
+
* toHtmlWithOptions(untrusted, { rawHtml: false })
|
|
79
167
|
* ```
|
|
80
168
|
*
|
|
81
169
|
* Every field is optional:
|
|
@@ -98,6 +186,31 @@ export function toHtmlFull(source: string, symbols?: object | null): string;
|
|
|
98
186
|
* over `full`.
|
|
99
187
|
* * `full` (default `false`) - enable the preview extension set instead of
|
|
100
188
|
* rendering core-only.
|
|
189
|
+
* * `rawHtml` (default `true`) - render an explicit passthrough - the `=html`
|
|
190
|
+
* raw block and the `` `…`{=html} `` inline raw span - as markup. `false`
|
|
191
|
+
* emits it as escaped text instead, the same switch carve-js spells
|
|
192
|
+
* `allowRawHtml`. A host that renders a document it did not author (a shared
|
|
193
|
+
* link, a comment field, anything a reader supplies) wants `false`: without
|
|
194
|
+
* it a passthrough is a way to run script on the host's origin.
|
|
195
|
+
* * `profile` - one of `"full"`, `"article"`, `"comment"`, `"minimal"`. The
|
|
196
|
+
* rest of the untrusted-input story: input length, denied constructs, link
|
|
197
|
+
* policy. A document the profile REJECTS throws a `ProfileViolationError`
|
|
198
|
+
* carrying `violations`, rather than resolving to an empty string.
|
|
199
|
+
* * `profileBaseHost` - the host counted as internal when the profile's link
|
|
200
|
+
* policy distinguishes internal from external links.
|
|
201
|
+
* * `mode` - `"interactive"` (default) or `"static"`, the self-contained form
|
|
202
|
+
* for print, PDF and archival: no client scripts.
|
|
203
|
+
* * `sourceLine` (default `false`) - stamp top-level blocks with
|
|
204
|
+
* `data-source-line`, for editor preview scroll-sync.
|
|
205
|
+
* * `positions` (default `false`) - keep source offsets on the nodes.
|
|
206
|
+
* * `labels` - override the engine-written strings (admonition names, the
|
|
207
|
+
* endnotes heading, backlink text) for a page that is not in English. These
|
|
208
|
+
* are TEXT and are escaped where they land, unlike `symbols`.
|
|
209
|
+
* * `smartTypography` - `"glyph"` (default) resolves `...` to an ellipsis,
|
|
210
|
+
* `"source"` keeps the author's run.
|
|
211
|
+
* * `lowercaseHeadingIds` (default `false`) and `asciiHeadingIds`
|
|
212
|
+
* (`"off"` (default), `"fold"`, `"strict"`) - the slug policy, for a host
|
|
213
|
+
* whose anchors have to match another generator's.
|
|
101
214
|
*
|
|
102
215
|
* An unrecognized key is ignored: the object is configuration, and a caller
|
|
103
216
|
* who mistypes one deserves the render to still work. A wrong TYPE on a key
|
package/carve_wasm.js
CHANGED
|
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./carve_wasm_bg.js";
|
|
|
5
5
|
__wbg_set_wasm(wasm);
|
|
6
6
|
wasm.__wbindgen_start();
|
|
7
7
|
export {
|
|
8
|
-
extensions, fromHtml, fromMarkdown, htmlToCarve, parseJson, toAnsi, toAnsiWithReport, toCarve, toCarveWithReport, toHtml, toHtmlFull, toHtmlWithOptions, toHtmlWithReport, toHtmlWithSymbols, toMarkdown, toMarkdownWithReport, toPlainText, toPlainTextWithReport, version
|
|
8
|
+
astJsonToCarve, astJsonToHtml, extensions, fromBbcode, fromDjot, fromHtml, fromMarkdown, htmlToCarve, lintCarve, needsReview, parseJson, readStamp, toAnsi, toAnsiWithReport, toCarve, toCarveWithReport, toHtml, toHtmlFull, toHtmlWithOptions, toHtmlWithReport, toHtmlWithSymbols, toMarkdown, toMarkdownWithReport, toPlainText, toPlainTextWithReport, version
|
|
9
9
|
} from "./carve_wasm_bg.js";
|
package/carve_wasm_bg.js
CHANGED
|
@@ -1,3 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render an AST-JSON document (PART 12) back to canonical Carve source.
|
|
3
|
+
*
|
|
4
|
+
* The round trip a host needs to SAVE an edited tree, rather than only display
|
|
5
|
+
* it. A tree holding something no Carve source can spell is refused rather
|
|
6
|
+
* than written approximately.
|
|
7
|
+
* @param {string} json
|
|
8
|
+
* @returns {string}
|
|
9
|
+
*/
|
|
10
|
+
export function astJsonToCarve(json) {
|
|
11
|
+
let deferred3_0;
|
|
12
|
+
let deferred3_1;
|
|
13
|
+
try {
|
|
14
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
15
|
+
const len0 = WASM_VECTOR_LEN;
|
|
16
|
+
const ret = wasm.astJsonToCarve(ptr0, len0);
|
|
17
|
+
var ptr2 = ret[0];
|
|
18
|
+
var len2 = ret[1];
|
|
19
|
+
if (ret[3]) {
|
|
20
|
+
ptr2 = 0; len2 = 0;
|
|
21
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
22
|
+
}
|
|
23
|
+
deferred3_0 = ptr2;
|
|
24
|
+
deferred3_1 = len2;
|
|
25
|
+
return getStringFromWasm0(ptr2, len2);
|
|
26
|
+
} finally {
|
|
27
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Render an AST-JSON document (PART 12) to HTML.
|
|
33
|
+
*
|
|
34
|
+
* The other half of `parseJson`. A host that reads the tree in a browser does
|
|
35
|
+
* it to CHANGE something, and until now there was no way to render the result:
|
|
36
|
+
* the binding could serialize a tree out and not take one back.
|
|
37
|
+
*
|
|
38
|
+
* Takes the same options object as [`to_html_with_options`], so an edited tree
|
|
39
|
+
* renders under the profile, labels and switches the host already configured.
|
|
40
|
+
* @param {string} json
|
|
41
|
+
* @param {object | null} [options]
|
|
42
|
+
* @returns {string}
|
|
43
|
+
*/
|
|
44
|
+
export function astJsonToHtml(json, options) {
|
|
45
|
+
let deferred3_0;
|
|
46
|
+
let deferred3_1;
|
|
47
|
+
try {
|
|
48
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
49
|
+
const len0 = WASM_VECTOR_LEN;
|
|
50
|
+
const ret = wasm.astJsonToHtml(ptr0, len0, isLikeNone(options) ? 0 : addToExternrefTable0(options));
|
|
51
|
+
var ptr2 = ret[0];
|
|
52
|
+
var len2 = ret[1];
|
|
53
|
+
if (ret[3]) {
|
|
54
|
+
ptr2 = 0; len2 = 0;
|
|
55
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
56
|
+
}
|
|
57
|
+
deferred3_0 = ptr2;
|
|
58
|
+
deferred3_1 = len2;
|
|
59
|
+
return getStringFromWasm0(ptr2, len2);
|
|
60
|
+
} finally {
|
|
61
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
1
65
|
/**
|
|
2
66
|
* Every extension name this build accepts, in registry order.
|
|
3
67
|
*
|
|
@@ -12,6 +76,60 @@ export function extensions() {
|
|
|
12
76
|
return v1;
|
|
13
77
|
}
|
|
14
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Convert BBCode source to Carve.
|
|
81
|
+
*
|
|
82
|
+
* Rejects input past the engine's `BBCODE_MAX_INPUT_LENGTH` rather than
|
|
83
|
+
* working on it: the importer's cost is superlinear in places, and a browser
|
|
84
|
+
* host cannot afford to find that out on the main thread.
|
|
85
|
+
* @param {string} source
|
|
86
|
+
* @returns {string}
|
|
87
|
+
*/
|
|
88
|
+
export function fromBbcode(source) {
|
|
89
|
+
let deferred3_0;
|
|
90
|
+
let deferred3_1;
|
|
91
|
+
try {
|
|
92
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
93
|
+
const len0 = WASM_VECTOR_LEN;
|
|
94
|
+
const ret = wasm.fromBbcode(ptr0, len0);
|
|
95
|
+
var ptr2 = ret[0];
|
|
96
|
+
var len2 = ret[1];
|
|
97
|
+
if (ret[3]) {
|
|
98
|
+
ptr2 = 0; len2 = 0;
|
|
99
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
100
|
+
}
|
|
101
|
+
deferred3_0 = ptr2;
|
|
102
|
+
deferred3_1 = len2;
|
|
103
|
+
return getStringFromWasm0(ptr2, len2);
|
|
104
|
+
} finally {
|
|
105
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Convert Djot source to Carve.
|
|
111
|
+
*
|
|
112
|
+
* Carve diverges from Djot deliberately - the emphasis delimiters are swapped,
|
|
113
|
+
* among others - so a Djot document is not Carve source and pasting one in
|
|
114
|
+
* renders wrongly rather than failing.
|
|
115
|
+
* @param {string} source
|
|
116
|
+
* @returns {string}
|
|
117
|
+
*/
|
|
118
|
+
export function fromDjot(source) {
|
|
119
|
+
let deferred2_0;
|
|
120
|
+
let deferred2_1;
|
|
121
|
+
try {
|
|
122
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
123
|
+
const len0 = WASM_VECTOR_LEN;
|
|
124
|
+
const ret = wasm.fromDjot(ptr0, len0);
|
|
125
|
+
deferred2_0 = ret[0];
|
|
126
|
+
deferred2_1 = ret[1];
|
|
127
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
128
|
+
} finally {
|
|
129
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
15
133
|
/**
|
|
16
134
|
* @param {string} source
|
|
17
135
|
* @param {string | null} [mode]
|
|
@@ -64,6 +182,45 @@ export function htmlToCarve(source, mode) {
|
|
|
64
182
|
return takeFromExternrefTable0(ret[0]);
|
|
65
183
|
}
|
|
66
184
|
|
|
185
|
+
/**
|
|
186
|
+
* Lint a document for the degradations PART 15 describes.
|
|
187
|
+
*
|
|
188
|
+
* Returns an array of `{ line, column, rule, message, start, end }`. The rule
|
|
189
|
+
* ids are shared with carve-js and carve-php, so the same trigger reports the
|
|
190
|
+
* same id everywhere. Offsets are BYTE offsets into the source, matching the
|
|
191
|
+
* engine.
|
|
192
|
+
*
|
|
193
|
+
* Built as JS objects rather than a JSON string: a message carries arbitrary
|
|
194
|
+
* document text, and hand-rolled JSON escaping is where that goes wrong.
|
|
195
|
+
* @param {string} source
|
|
196
|
+
* @returns {LintWarning[]}
|
|
197
|
+
*/
|
|
198
|
+
export function lintCarve(source) {
|
|
199
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
200
|
+
const len0 = WASM_VECTOR_LEN;
|
|
201
|
+
const ret = wasm.lintCarve(ptr0, len0);
|
|
202
|
+
if (ret[2]) {
|
|
203
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
204
|
+
}
|
|
205
|
+
return takeFromExternrefTable0(ret[0]);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Whether a document was last processed under an older spec version than
|
|
210
|
+
* `currentVersion`. An unstamped document counts as needing review.
|
|
211
|
+
* @param {string} source
|
|
212
|
+
* @param {string} current_version
|
|
213
|
+
* @returns {boolean}
|
|
214
|
+
*/
|
|
215
|
+
export function needsReview(source, current_version) {
|
|
216
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
217
|
+
const len0 = WASM_VECTOR_LEN;
|
|
218
|
+
const ptr1 = passStringToWasm0(current_version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
219
|
+
const len1 = WASM_VECTOR_LEN;
|
|
220
|
+
const ret = wasm.needsReview(ptr0, len0, ptr1, len1);
|
|
221
|
+
return ret !== 0;
|
|
222
|
+
}
|
|
223
|
+
|
|
67
224
|
/**
|
|
68
225
|
* Parse Carve source and return its AST as a JSON string.
|
|
69
226
|
*
|
|
@@ -99,6 +256,21 @@ export function parseJson(source) {
|
|
|
99
256
|
}
|
|
100
257
|
}
|
|
101
258
|
|
|
259
|
+
/**
|
|
260
|
+
* Read a document's provenance marker: `{ version, generatedBy }`, or `null`.
|
|
261
|
+
* @param {string} source
|
|
262
|
+
* @returns {Stamp | null}
|
|
263
|
+
*/
|
|
264
|
+
export function readStamp(source) {
|
|
265
|
+
const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
266
|
+
const len0 = WASM_VECTOR_LEN;
|
|
267
|
+
const ret = wasm.readStamp(ptr0, len0);
|
|
268
|
+
if (ret[2]) {
|
|
269
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
270
|
+
}
|
|
271
|
+
return takeFromExternrefTable0(ret[0]);
|
|
272
|
+
}
|
|
273
|
+
|
|
102
274
|
/**
|
|
103
275
|
* @param {string} source
|
|
104
276
|
* @returns {string}
|
|
@@ -235,6 +407,8 @@ export function toHtmlFull(source, symbols) {
|
|
|
235
407
|
* // '<h1 id="A">A</h1>\n<p>p</p>'
|
|
236
408
|
*
|
|
237
409
|
* toHtmlWithOptions(src, { sections: false, symbols: { rocket: '🚀' }, full: true })
|
|
410
|
+
*
|
|
411
|
+
* toHtmlWithOptions(untrusted, { rawHtml: false })
|
|
238
412
|
* ```
|
|
239
413
|
*
|
|
240
414
|
* Every field is optional:
|
|
@@ -257,6 +431,31 @@ export function toHtmlFull(source, symbols) {
|
|
|
257
431
|
* over `full`.
|
|
258
432
|
* * `full` (default `false`) - enable the preview extension set instead of
|
|
259
433
|
* rendering core-only.
|
|
434
|
+
* * `rawHtml` (default `true`) - render an explicit passthrough - the `=html`
|
|
435
|
+
* raw block and the `` `…`{=html} `` inline raw span - as markup. `false`
|
|
436
|
+
* emits it as escaped text instead, the same switch carve-js spells
|
|
437
|
+
* `allowRawHtml`. A host that renders a document it did not author (a shared
|
|
438
|
+
* link, a comment field, anything a reader supplies) wants `false`: without
|
|
439
|
+
* it a passthrough is a way to run script on the host's origin.
|
|
440
|
+
* * `profile` - one of `"full"`, `"article"`, `"comment"`, `"minimal"`. The
|
|
441
|
+
* rest of the untrusted-input story: input length, denied constructs, link
|
|
442
|
+
* policy. A document the profile REJECTS throws a `ProfileViolationError`
|
|
443
|
+
* carrying `violations`, rather than resolving to an empty string.
|
|
444
|
+
* * `profileBaseHost` - the host counted as internal when the profile's link
|
|
445
|
+
* policy distinguishes internal from external links.
|
|
446
|
+
* * `mode` - `"interactive"` (default) or `"static"`, the self-contained form
|
|
447
|
+
* for print, PDF and archival: no client scripts.
|
|
448
|
+
* * `sourceLine` (default `false`) - stamp top-level blocks with
|
|
449
|
+
* `data-source-line`, for editor preview scroll-sync.
|
|
450
|
+
* * `positions` (default `false`) - keep source offsets on the nodes.
|
|
451
|
+
* * `labels` - override the engine-written strings (admonition names, the
|
|
452
|
+
* endnotes heading, backlink text) for a page that is not in English. These
|
|
453
|
+
* are TEXT and are escaped where they land, unlike `symbols`.
|
|
454
|
+
* * `smartTypography` - `"glyph"` (default) resolves `...` to an ellipsis,
|
|
455
|
+
* `"source"` keeps the author's run.
|
|
456
|
+
* * `lowercaseHeadingIds` (default `false`) and `asciiHeadingIds`
|
|
457
|
+
* (`"off"` (default), `"fold"`, `"strict"`) - the slug policy, for a host
|
|
458
|
+
* whose anchors have to match another generator's.
|
|
260
459
|
*
|
|
261
460
|
* An unrecognized key is ignored: the object is configuration, and a caller
|
|
262
461
|
* who mistypes one deserves the render to still work. A wrong TYPE on a key
|
|
@@ -537,6 +736,9 @@ export function __wbg_set_8ee2d34facb8466e() { return handleError(function (arg0
|
|
|
537
736
|
const ret = Reflect.set(arg0, arg1, arg2);
|
|
538
737
|
return ret;
|
|
539
738
|
}, arguments); }
|
|
739
|
+
export function __wbg_set_name_ab9c98596fd7310a(arg0, arg1, arg2) {
|
|
740
|
+
arg0.name = getStringFromWasm0(arg1, arg2);
|
|
741
|
+
}
|
|
540
742
|
export function __wbindgen_cast_0000000000000001(arg0) {
|
|
541
743
|
// Cast intrinsic for `F64 -> Externref`.
|
|
542
744
|
const ret = arg0;
|
package/carve_wasm_bg.wasm
CHANGED
|
Binary file
|