@pretextbook/pretext-html 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -1
- package/assets/preview-html.xsl +0 -0
- package/assets/upstream.json +0 -0
- package/assets/xsl/README.md +0 -0
- package/assets/xsl/entities.ent +0 -0
- package/assets/xsl/extract-asymptote.xsl +0 -0
- package/assets/xsl/extract-biblio-csl.xsl +0 -0
- package/assets/xsl/extract-datafile.xsl +0 -0
- package/assets/xsl/extract-dynamic.xsl +0 -0
- package/assets/xsl/extract-identity.xsl +0 -0
- package/assets/xsl/extract-interactive.xsl +0 -0
- package/assets/xsl/extract-latex-image.xsl +0 -0
- package/assets/xsl/extract-mermaid.xsl +0 -0
- package/assets/xsl/extract-mom.xsl +0 -0
- package/assets/xsl/extract-pg.xsl +0 -0
- package/assets/xsl/extract-prefigure.xsl +0 -0
- package/assets/xsl/extract-qrcode.xsl +0 -0
- package/assets/xsl/extract-runestone-page-template.xsl +0 -0
- package/assets/xsl/extract-sageplot.xsl +0 -0
- package/assets/xsl/extract-stack.xsl +0 -0
- package/assets/xsl/extract-trace.xsl +0 -0
- package/assets/xsl/extract-youtube.xsl +0 -0
- package/assets/xsl/html-symbols.xsl +0 -0
- package/assets/xsl/latex/pretext-latex-AIM.xsl +0 -0
- package/assets/xsl/latex/pretext-latex-CLP.xsl +0 -0
- package/assets/xsl/latex/pretext-latex-chaos.xsl +0 -0
- package/assets/xsl/latex/pretext-latex-dyslexic-font.xsl +0 -0
- package/assets/xsl/latex/pretext-latex-guide.xsl +0 -0
- package/assets/xsl/latex/pretext-latex-texstyle.xsl +0 -0
- package/assets/xsl/localizations/README.md +0 -0
- package/assets/xsl/localizations/af-ZA.xml +0 -0
- package/assets/xsl/localizations/bg-BG.xml +0 -0
- package/assets/xsl/localizations/ca-ES.xml +0 -0
- package/assets/xsl/localizations/cs-CZ.xml +0 -0
- package/assets/xsl/localizations/de-DE.xml +0 -0
- package/assets/xsl/localizations/en-US.xml +0 -0
- package/assets/xsl/localizations/es-ES.xml +0 -0
- package/assets/xsl/localizations/fi-FI.xml +0 -0
- package/assets/xsl/localizations/fr-CA.xml +0 -0
- package/assets/xsl/localizations/fr-FR.xml +0 -0
- package/assets/xsl/localizations/hu-HU.xml +0 -0
- package/assets/xsl/localizations/it-IT.xml +0 -0
- package/assets/xsl/localizations/ku-CKB.xml +0 -0
- package/assets/xsl/localizations/localizations.xml +0 -0
- package/assets/xsl/localizations/nl-NL.xml +0 -0
- package/assets/xsl/localizations/pt-BR.xml +0 -0
- package/assets/xsl/localizations/pt-PT.xml +0 -0
- package/assets/xsl/localizations/zh-HANS.xml +0 -0
- package/assets/xsl/pretext-assembly.xsl +0 -0
- package/assets/xsl/pretext-basic-html.xsl +0 -0
- package/assets/xsl/pretext-beamer.xsl +0 -0
- package/assets/xsl/pretext-braille-preprint.xsl +0 -0
- package/assets/xsl/pretext-common.xsl +0 -0
- package/assets/xsl/pretext-dynamic.xsl +0 -0
- package/assets/xsl/pretext-epub.xsl +0 -0
- package/assets/xsl/pretext-fo.xsl +0 -0
- package/assets/xsl/pretext-html.xsl +0 -0
- package/assets/xsl/pretext-json-manifest.xsl +0 -0
- package/assets/xsl/pretext-jupyter.xsl +0 -0
- package/assets/xsl/pretext-latex-classic.xsl +0 -0
- package/assets/xsl/pretext-latex-common.xsl +0 -0
- package/assets/xsl/pretext-latex.xsl +0 -0
- package/assets/xsl/pretext-litprog.xsl +0 -0
- package/assets/xsl/pretext-merge.xsl +0 -0
- package/assets/xsl/pretext-numbers.xsl +0 -0
- package/assets/xsl/pretext-revealjs.xsl +0 -0
- package/assets/xsl/pretext-runestone-fitb.xsl +0 -0
- package/assets/xsl/pretext-runestone-static.xsl +0 -0
- package/assets/xsl/pretext-runestone.xsl +0 -0
- package/assets/xsl/pretext-sage-doctest.xsl +0 -0
- package/assets/xsl/pretext-smc.xsl +0 -0
- package/assets/xsl/pretext-solution-manual-latex.xsl +0 -0
- package/assets/xsl/pretext-text-utilities.xsl +0 -0
- package/assets/xsl/pretext-text.xsl +0 -0
- package/assets/xsl/pretext-units.xsl +0 -0
- package/assets/xsl/pretext-view-source.xsl +0 -0
- package/assets/xsl/pretext-ww-problem-sets.xsl +0 -0
- package/assets/xsl/publisher-variables.xsl +0 -0
- package/assets/xsl/support/README.md +0 -0
- package/assets/xsl/support/extract-math.xsl +0 -0
- package/assets/xsl/support/package-math.xsl +0 -0
- package/assets/xsl/support/play-button/README.md +0 -0
- package/assets/xsl/support/play-button/play-button.png +0 -0
- package/assets/xsl/support/play-button/play-button.svg +0 -0
- package/assets/xsl/support/pretext-pg-macros.xsl +0 -0
- package/assets/xsl/support/webpack_static_imports.xml +0 -0
- package/assets/xsl/tests/README.md +0 -0
- package/assets/xsl/tests/null.xml +0 -0
- package/assets/xsl/tests/pretext-text-utilities-test.xsl +0 -0
- package/assets/xsl/utilities/README.md +0 -0
- package/assets/xsl/utilities/author-report.xsl +0 -0
- package/assets/xsl/utilities/deprecate-autoname.sed +0 -0
- package/assets/xsl/utilities/deprecate-index.sed +0 -0
- package/assets/xsl/utilities/fix-deprecations.xsl +0 -0
- package/assets/xsl/utilities/pretext-enhanced-source.xsl +0 -0
- package/assets/xsl/utilities/report-publisher-variables.xsl +0 -0
- package/assets/xsl/xml-to-json.xsl +0 -0
- package/assets/xsl/xml-to-string.xsl +0 -0
- package/assets/xsl-bundle.json +1 -0
- package/dist/{cli-BQizBK0N.js → cli-B2LiKunq.js} +267 -234
- package/dist/cli.d.ts +0 -0
- package/dist/cli.js +1 -1
- package/dist/host.browser.d.ts +29 -0
- package/dist/host.d.ts +41 -0
- package/dist/index.browser.d.ts +29 -0
- package/dist/index.browser.js +650 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +14 -12
- package/dist/internal/posix-path.d.ts +59 -0
- package/dist/mounts.d.ts +18 -0
- package/dist/publication.d.ts +0 -0
- package/dist/renderer.d.ts +4 -1
- package/dist/sourcemap.d.ts +0 -0
- package/dist/theme.d.ts +0 -0
- package/dist/theme.js +0 -0
- package/dist/xinclude.d.ts +0 -0
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -74,6 +74,58 @@ const { html } = await renderHtml({
|
|
|
74
74
|
- `theme: "dark" | "light" | "system"` makes the preview follow the embedding
|
|
75
75
|
app's light/dark theme (see [Theme control](#theme-control)).
|
|
76
76
|
|
|
77
|
+
### API (browser)
|
|
78
|
+
|
|
79
|
+
The same renderer runs in a browser — no server, no Python. Bundlers pick it up
|
|
80
|
+
through the `browser` export condition automatically; there is nothing to
|
|
81
|
+
configure.
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
import { renderHtml, isJspiAvailable } from "@pretextbook/pretext-html";
|
|
85
|
+
|
|
86
|
+
if (!isJspiAvailable()) {
|
|
87
|
+
// No WebAssembly JSPI in this engine — fall back to a server-side build.
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const { html } = await renderHtml({
|
|
91
|
+
sourcePath: "/source/main.ptx", // a *virtual* path: no filesystem is read
|
|
92
|
+
sourceContent: editorText, // required in the browser
|
|
93
|
+
projectDir: "/source",
|
|
94
|
+
fragment: true, // rendering one division on its own
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Differences from the Node API, all of them consequences of there being no
|
|
99
|
+
filesystem:
|
|
100
|
+
|
|
101
|
+
- **`sourceContent` is required.** `sourcePath` still anchors relative
|
|
102
|
+
`xi:include`s and the output's URLs, but nothing is read from it.
|
|
103
|
+
- **`xi:include`s are not resolved from disk.** Pre-merge them, or pass the
|
|
104
|
+
already-merged document as `sourceContent`. An unresolvable include uses its
|
|
105
|
+
`<xi:fallback>` if it has one, and otherwise throws.
|
|
106
|
+
- **`publicationPath` / `docinfoSourcePath` need absolute URLs**, since those
|
|
107
|
+
are the only readable locations. Prefer `docinfo` (a string) over
|
|
108
|
+
`docinfoSourcePath`.
|
|
109
|
+
- **Stylesheets are fetched from jsDelivr**, version-pinned to the installed
|
|
110
|
+
package, so no build configuration is needed. To self-host them, copy this
|
|
111
|
+
package's `assets/` directory somewhere your app serves and call
|
|
112
|
+
`setAssetsBase("/pretext-assets")` before the first render. (Under Node the
|
|
113
|
+
equivalent is `PRETEXT_HTML_ASSETS`, or the same `setAssetsBase`.)
|
|
114
|
+
- **A cold render costs two requests**, not ~32: `assets/xsl-bundle.json` packs
|
|
115
|
+
the whole stylesheet closure (13 stylesheets plus the 17 locale files
|
|
116
|
+
`pretext-common.xsl` eagerly loads) into one file. It is purely an
|
|
117
|
+
optimisation — if it is missing, each file is fetched individually and the
|
|
118
|
+
render still succeeds. It is recorded from a real render by
|
|
119
|
+
`npm run build-xsl-bundle`, which runs as part of `npm run build`.
|
|
120
|
+
|
|
121
|
+
Typical timings, measured on a single-division fragment: **~400ms cold**
|
|
122
|
+
(stylesheet compile plus asset fetch, paid once per session and then cached)
|
|
123
|
+
and **~90ms warm**. That is what makes preview-on-save feel instant.
|
|
124
|
+
|
|
125
|
+
`setMountReader()` is the escape hatch if neither delivery mode fits — it lets
|
|
126
|
+
you serve the stylesheets from an in-memory map, a zip, or a webview resource
|
|
127
|
+
URI.
|
|
128
|
+
|
|
77
129
|
### Theme control
|
|
78
130
|
|
|
79
131
|
A rendered page can already switch between light and dark — pretext-core.js
|
|
@@ -149,13 +201,22 @@ the message helper.
|
|
|
149
201
|
(libxml2's own XInclude pass cannot suspend in the current WASM build).
|
|
150
202
|
Supports nested includes, `parse="text"`, and `xi:fallback`; `xpointer` is
|
|
151
203
|
not supported.
|
|
204
|
+
5. **Platform seam** — `src/host.ts` holds everything that touches the outside
|
|
205
|
+
world: read a file under a mount, read a caller-named file, locate
|
|
206
|
+
`assets/`. Under Node those are filesystem calls; in the browser build
|
|
207
|
+
(`src/host.browser.ts`, swapped in by `vite.config.mts`) they are `fetch`es.
|
|
208
|
+
The browser build also substitutes a posix-only `node:path`
|
|
209
|
+
(`src/internal/posix-path.ts`), which is sound because no path this package
|
|
210
|
+
computes ever reaches a real filesystem — with `FILESYSTEM=0` they are all
|
|
211
|
+
virtual, ending up as mount keys or `.ptx.invalid` URL segments. The result
|
|
212
|
+
has no `node:` imports at all; rollup fails the build if one survives.
|
|
152
213
|
|
|
153
214
|
## Limitations (current WASM build)
|
|
154
215
|
|
|
155
216
|
| Limitation | Cause | Fix |
|
|
156
217
|
| ---------------------------------------------- | ----------------------------------------------- | --------------------------------------------------------------------------- |
|
|
157
218
|
| No multi-file output (`exsl:document`) | Compiled with `FILESYSTEM=0` | Rebuild with `FILESYSTEM=1` (files land in MEMFS) |
|
|
158
|
-
|
|
|
219
|
+
| JSPI required (flagged on Node) | Loader fetches resources mid-transform via JSPI | Feature-detect with `isJspiAvailable()`; engines without it need a fallback |
|
|
159
220
|
| No generated images (latex-image, sageplot, …) | Produced by the Python toolchain, not XSLT | Out of scope; run `pretext generate` and the preview will pick the files up |
|
|
160
221
|
| `xi:include` with `xpointer` unsupported | JS resolver stands in for libxml2's | Rebuild adding `xmlXIncludeProcessFlags` to the JSPI export list |
|
|
161
222
|
|
package/assets/preview-html.xsl
CHANGED
|
File without changes
|
package/assets/upstream.json
CHANGED
|
File without changes
|
package/assets/xsl/README.md
CHANGED
|
File without changes
|
package/assets/xsl/entities.ent
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|