@pretextbook/pretext-html 0.17.0 → 0.18.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 +86 -15
- package/assets/preview-html.xsl +25 -14
- package/assets/preview-revealjs.xsl +7 -2
- package/dist/assets.d.ts +9 -5
- package/dist/banner.d.ts +2 -2
- package/dist/{cli-C0JwLhuv.js → cli-CKAOX3L6.js} +549 -511
- package/dist/cli.d.ts +12 -1
- package/dist/cli.js +8 -3
- package/dist/index.browser.d.ts +1 -1
- package/dist/index.browser.js +764 -748
- package/dist/index.d.ts +1 -1
- package/dist/index.js +42 -41
- package/dist/publication.d.ts +54 -21
- package/dist/renderer.d.ts +18 -11
- package/dist/target.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,11 +10,13 @@ CLI uses via lxml), so the HTML matches a real `pretext build`. It is a fork of
|
|
|
10
10
|
with a larger WASM stack so whole-book documents render without overflowing
|
|
11
11
|
(see [Forking libxslt-wasm](#forking-libxslt-wasm)).
|
|
12
12
|
|
|
13
|
-
The output is a single, standalone HTML page
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
The output is a single, standalone HTML page. The theme css/js and MathJax
|
|
14
|
+
load from public CDNs, the whole document is rendered as one page, and images
|
|
15
|
+
are linked rather than embedded, so the host serves them from wherever it
|
|
16
|
+
keeps them (see [Images and other assets](#images-and-other-assets)). This is
|
|
17
|
+
what powers the "Live Preview" in the PreTeXt-tools VS Code extension, and it
|
|
18
|
+
is published so other tools (e.g. pretext.plus) can render previews the same
|
|
19
|
+
way.
|
|
18
20
|
|
|
19
21
|
## Usage
|
|
20
22
|
|
|
@@ -66,9 +68,19 @@ const { html } = await renderHtml({
|
|
|
66
68
|
element has no HTML id of its own, and `findSourceMapEntry(entries, line)`
|
|
67
69
|
picks the element nearest a cursor line. (This powers the two-way sync in
|
|
68
70
|
the VS Code Instant Preview; the same map works for any embedder.)
|
|
69
|
-
- The user's publication file is respected, except
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
- The user's publication file is respected, except for four settings that
|
|
72
|
+
single-page in-memory output needs, which are always forced (see
|
|
73
|
+
`src/publication.ts`):
|
|
74
|
+
- `<html><resources host="cdn"/>`: css/js, theme and icon font from the CDN.
|
|
75
|
+
- `<common><chunking level="0"/>`: the whole document on one page.
|
|
76
|
+
- `<html><cross-references knowled="never"/>`: cross-references are links,
|
|
77
|
+
because the knowl files they would open are never written.
|
|
78
|
+
- `<html><platform portable="no"/>`: PreTeXt's _portable HTML_ mode is off,
|
|
79
|
+
even for a project that builds portable. Portable mode would do the first
|
|
80
|
+
three as well, and earlier releases relied on it, but it also inlines
|
|
81
|
+
every latex-image and PreFigure SVG into the page. Without it those are
|
|
82
|
+
linked like every other image. The search index stays embedded in the
|
|
83
|
+
page, as portable mode had it.
|
|
72
84
|
- `cssTheme: "denver"` supplies the PreTeXt HTML theme for projects that do not
|
|
73
85
|
choose one, by adding `<html><css theme="…"/></html>` to the publication file
|
|
74
86
|
used for the build (including the minimal one synthesized when you pass no
|
|
@@ -76,9 +88,9 @@ const { html } = await renderHtml({
|
|
|
76
88
|
that already names a theme — `@theme`, or the deprecated `@style`/`@shell` —
|
|
77
89
|
keeps it, so the preview goes on matching what `pretext build` produces. The
|
|
78
90
|
themes the bundled stylesheets know are `default-modern` (PreTeXt's own
|
|
79
|
-
default), `denver`, `tacoma`, `salem`, `greeley` and `boulder`;
|
|
80
|
-
|
|
81
|
-
|
|
91
|
+
default), `denver`, `tacoma`, `salem`, `greeley` and `boulder`; the preview
|
|
92
|
+
loads `theme-<name>.min.css` from the CDN, so an unrecognised name gives an
|
|
93
|
+
unstyled page. Not to be confused with `theme` below, which is the
|
|
82
94
|
light/dark mode _within_ whichever css theme is in force.
|
|
83
95
|
- The compiled stylesheet is cached per `xslDir` (~1s to compile, then
|
|
84
96
|
~100ms–1s per render depending on document size).
|
|
@@ -91,6 +103,65 @@ const { html } = await renderHtml({
|
|
|
91
103
|
alone. Pass `openKnowls: false` (`--no-open-knowls` on the CLI) for the
|
|
92
104
|
collapsed reading experience of a real `pretext build`.
|
|
93
105
|
|
|
106
|
+
### Images and other assets
|
|
107
|
+
|
|
108
|
+
Every image the page shows is an ordinary link under one of two fixed
|
|
109
|
+
prefixes, exactly as in a real build. Author-supplied files are under
|
|
110
|
+
`external/`, and everything `pretext generate` makes (latex-image, PreFigure,
|
|
111
|
+
sageplot, asymptote, …) is under `generated/`:
|
|
112
|
+
|
|
113
|
+
```html
|
|
114
|
+
<img src="external/kitten.png" />
|
|
115
|
+
<img src="generated/latex-image/diagram.svg" />
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
A real build copies both directories next to its pages. A preview has no such
|
|
119
|
+
directory, so the host maps each URL to wherever it keeps the file:
|
|
120
|
+
|
|
121
|
+
```js
|
|
122
|
+
import { renderHtml } from "@pretextbook/pretext-html";
|
|
123
|
+
import {
|
|
124
|
+
rewriteAssetUrls,
|
|
125
|
+
missingAssetPlaceholder,
|
|
126
|
+
} from "@pretextbook/pretext-html/assets"; // dependency-free subpath
|
|
127
|
+
|
|
128
|
+
const { html, assetDirs } = await renderHtml({ sourcePath: "source/main.ptx" });
|
|
129
|
+
|
|
130
|
+
const page = rewriteAssetUrls(html, (kind, relPath) => {
|
|
131
|
+
// kind is "external" or "generated"; relPath is e.g. "latex-image/diagram.svg"
|
|
132
|
+
const url = lookUp(kind, relPath); // a webview URI, a blob URL, a hosted URL…
|
|
133
|
+
return url ?? missingAssetPlaceholder(kind, relPath);
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
- `assetDirs` gives the absolute directories behind the two prefixes, resolved
|
|
138
|
+
the way PreTeXt resolves them. `external` comes from the document's
|
|
139
|
+
`<docinfo><directories external="…"/>`, falling back to the publication
|
|
140
|
+
file's deprecated `source/directories/@external`; it is absent when neither
|
|
141
|
+
declares one, which PreTeXt reads as "no external assets". `generated` comes
|
|
142
|
+
from the publication file's `source/directories/@generated` and defaults to
|
|
143
|
+
`generated/` beside the main source file.
|
|
144
|
+
- A host without a filesystem (a browser editor) ignores `assetDirs` and
|
|
145
|
+
answers from its own store of uploaded or generated files. Nothing reads
|
|
146
|
+
image files during the render itself.
|
|
147
|
+
- Give a file a new URL when it changes, for instance with a version or
|
|
148
|
+
modification-time query. A page never fetches an `<img>` again while its
|
|
149
|
+
`src` is unchanged, and a live patch leaves an unchanged element alone, so a
|
|
150
|
+
regenerated image behind the same URL keeps showing the old picture. With a
|
|
151
|
+
new URL, a live patch updates just that `src` in place and only that image
|
|
152
|
+
reloads. Re-deliver the page when the files change (the VS Code preview
|
|
153
|
+
watches the asset directories), not only when the source does.
|
|
154
|
+
- `missingAssetPlaceholder` returns a data-URI SVG that names the missing file
|
|
155
|
+
and says what to do (`pretext generate latex-image`, or "check @source"),
|
|
156
|
+
which reads better than the browser's broken-image glyph. Return `undefined`
|
|
157
|
+
from the resolver instead to leave a URL as it is.
|
|
158
|
+
- Only `src` attributes are rewritten. An annotated PreFigure diagram (one with
|
|
159
|
+
`<annotations>`) is drawn by a script from `data-src`/`data-cml` attributes,
|
|
160
|
+
which are left alone.
|
|
161
|
+
- The CLI applies this itself when it writes a file (`--output`), linking each
|
|
162
|
+
asset relative to the output file. HTML written to stdout keeps PreTeXt's
|
|
163
|
+
own URLs.
|
|
164
|
+
|
|
94
165
|
### Previewing one division of a large document
|
|
95
166
|
|
|
96
167
|
A render costs what PreTeXt's assembly costs, and that tracks the number of
|
|
@@ -483,7 +554,7 @@ through `stringParams` to link no Runestone code at all.
|
|
|
483
554
|
| ---------------------------------------------- | ---------------------------------------------------- | --------------------------------------------------------------------------- |
|
|
484
555
|
| No multi-file output (`exsl:document`) | Compiled with `FILESYSTEM=0` | Rebuild with `FILESYSTEM=1` (files land in MEMFS) |
|
|
485
556
|
| JSPI required (flagged on Node) | Loader fetches resources mid-transform via JSPI | Feature-detect with `isJspiAvailable()`; engines without it need a fallback |
|
|
486
|
-
| No generated images (latex-image, sageplot, …) | Produced by the Python toolchain, not XSLT | Out of scope; run `pretext generate` and the
|
|
557
|
+
| No generated images (latex-image, sageplot, …) | Produced by the Python toolchain, not XSLT | Out of scope; run `pretext generate` and the page links the files it made |
|
|
487
558
|
| `xi:include` with `xpointer` unsupported | JS resolver stands in for libxml2's | Rebuild adding `xmlXIncludeProcessFlags` to the JSPI export list |
|
|
488
559
|
| Renders run one at a time, never in parallel | Shared libxslt state; the transform suspends mid-run | Inherent; `renderHtml` queues concurrent calls for you |
|
|
489
560
|
|
|
@@ -510,9 +581,9 @@ later call for the lifetime of the process. Once that has happened, only a
|
|
|
510
581
|
restart (or a page reload) recovers; `renderHtml` detects the state and says so
|
|
511
582
|
rather than repeating the underlying assertion.
|
|
512
583
|
|
|
513
|
-
Missing generated assets
|
|
514
|
-
|
|
515
|
-
|
|
584
|
+
Missing generated assets cost the render nothing: the page links every image
|
|
585
|
+
whether or not the file exists, and deciding what to show for a missing one is
|
|
586
|
+
the host's (see [Images and other assets](#images-and-other-assets)).
|
|
516
587
|
|
|
517
588
|
## Forking libxslt-wasm
|
|
518
589
|
|
package/assets/preview-html.xsl
CHANGED
|
@@ -4,12 +4,15 @@
|
|
|
4
4
|
Regenerate with: npm run refresh-xsl -w @pretextbook/pretext-html
|
|
5
5
|
|
|
6
6
|
Wrapper around pretext-html.xsl for single-page in-memory HTML builds
|
|
7
|
-
(previews). The "file-wrap" template below is a
|
|
8
|
-
|
|
9
|
-
page is emitted on the main result tree
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
(previews). The "file-wrap" template below is a copy of the upstream
|
|
8
|
+
template with two changes: the <exsl:document> element is removed, so the
|
|
9
|
+
complete page is emitted on the main result tree, and the search index is
|
|
10
|
+
embedded in the page whether or not the build is portable. Intended to be
|
|
11
|
+
applied together with a publication file that forces CDN-hosted css/js
|
|
12
|
+
(<html><resources host="cdn"/>), chunk level 0 (one page), cross-references
|
|
13
|
+
as links rather than knowls, and portable mode off, so that latex-image and
|
|
14
|
+
PreFigure SVGs are linked rather than inlined. Remaining file writers are
|
|
15
|
+
stubbed at the end.
|
|
13
16
|
-->
|
|
14
17
|
<xsl:stylesheet
|
|
15
18
|
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
|
|
@@ -29,7 +32,9 @@
|
|
|
29
32
|
<xsl:import href="pretext-html.xsl"/>
|
|
30
33
|
<xsl:output method="html" encoding="UTF-8" doctype-system="about:legacy-compat"/>
|
|
31
34
|
|
|
32
|
-
<!-- Copied from pretext-html.xsl (mode="file-wrap"), exsl:document removed -->
|
|
35
|
+
<!-- Copied from pretext-html.xsl (mode="file-wrap"), exsl:document removed, -->
|
|
36
|
+
<!-- and the search index embedded in every build, not only portable ones. -->
|
|
37
|
+
<!-- See EMBEDDED_SEARCH_TEST in refresh-xsl.mjs. -->
|
|
33
38
|
<xsl:template match="*" mode="file-wrap">
|
|
34
39
|
<xsl:param name="content" />
|
|
35
40
|
<xsl:param name="title" select="''"/>
|
|
@@ -199,7 +204,7 @@
|
|
|
199
204
|
</div>
|
|
200
205
|
<xsl:copy-of select="$file-wrap-full-endbody-cache"/>
|
|
201
206
|
<!-- For portable builds we stash the lunr search here -->
|
|
202
|
-
<xsl:if test="$
|
|
207
|
+
<xsl:if test="$has-native-search">
|
|
203
208
|
<xsl:call-template name="embedded-search-construction"/>
|
|
204
209
|
</xsl:if>
|
|
205
210
|
<!-- optional body content that needs to be inserted after all content -->
|
|
@@ -211,8 +216,8 @@
|
|
|
211
216
|
</xsl:template>
|
|
212
217
|
|
|
213
218
|
<!-- Chunk at the subtree root's own level, so a fragment preview can name a -->
|
|
214
|
-
<!-- division of any depth as $subtree. Without this,
|
|
215
|
-
<!-- of 0 makes upstream abort on every division below the
|
|
219
|
+
<!-- division of any depth as $subtree. Without this, the preview's chunk -->
|
|
220
|
+
<!-- level of 0 makes upstream abort on every division below the root. -->
|
|
216
221
|
<!-- See SUBTREE_CHUNK_LEVEL_OVERRIDE in refresh-xsl.mjs. -->
|
|
217
222
|
<xsl:param name="subtree-level" select="''"/>
|
|
218
223
|
<xsl:variable name="chunk-level">
|
|
@@ -311,11 +316,17 @@
|
|
|
311
316
|
</div>
|
|
312
317
|
</xsl:template>
|
|
313
318
|
|
|
319
|
+
<!-- Skip the passes whose only product is a file the preview never writes: -->
|
|
320
|
+
<!-- knowl files for cross-references, and standalone pages for media. -->
|
|
321
|
+
<!-- See SKIPPED_WORK_STUBS in refresh-xsl.mjs. -->
|
|
322
|
+
<xsl:template match="*" mode="make-xref-knowls"/>
|
|
323
|
+
<xsl:template match="audio|video" mode="media-standalone-page"/>
|
|
324
|
+
|
|
314
325
|
<!-- Stub out the remaining file writers (every other template reachable -->
|
|
315
|
-
<!-- from pretext-html.xsl that contains exsl:document).
|
|
316
|
-
<!--
|
|
317
|
-
<!-- rest and act as a safety net if publication settings change.
|
|
318
|
-
<!-- exsl:document that does fire aborts the FILESYSTEM=0 WASM build.
|
|
326
|
+
<!-- from pretext-html.xsl that contains exsl:document). The preview's -->
|
|
327
|
+
<!-- publication settings keep some of these from being reached; the stubs -->
|
|
328
|
+
<!-- cover the rest and act as a safety net if publication settings change. -->
|
|
329
|
+
<!-- Any exsl:document that does fire aborts the FILESYSTEM=0 WASM build. -->
|
|
319
330
|
<xsl:template name="index-redirect-page"/>
|
|
320
331
|
<xsl:template match="*" mode="manufacture-knowl"/>
|
|
321
332
|
<xsl:template name="ol-marker-styles"/>
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
Intended to be applied together with a publication file that forces
|
|
13
13
|
<revealjs><resources host="cdn" math="online"/></revealjs>, since neither
|
|
14
|
-
locally hosted nor embedded reveal.js resources exist for an in-memory build
|
|
14
|
+
locally hosted nor embedded reveal.js resources exist for an in-memory build,
|
|
15
|
+
and <html><resources host="cdn"/> for PreTeXt's own css/js on the slides.
|
|
15
16
|
-->
|
|
16
17
|
<xsl:stylesheet
|
|
17
18
|
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
|
|
@@ -65,7 +66,11 @@
|
|
|
65
66
|
</xsl:for-each>
|
|
66
67
|
</xsl:template>
|
|
67
68
|
|
|
68
|
-
<!-- Same file-writer stubs as preview-html.xsl
|
|
69
|
+
<!-- Same skipped passes and file-writer stubs as preview-html.xsl (a video -->
|
|
70
|
+
<!-- on a slide renders through the same templates); see SKIPPED_WORK_STUBS -->
|
|
71
|
+
<!-- and FILE_WRITER_STUBS. -->
|
|
72
|
+
<xsl:template match="*" mode="make-xref-knowls"/>
|
|
73
|
+
<xsl:template match="audio|video" mode="media-standalone-page"/>
|
|
69
74
|
<xsl:template name="index-redirect-page"/>
|
|
70
75
|
<xsl:template match="*" mode="manufacture-knowl"/>
|
|
71
76
|
<xsl:template name="ol-marker-styles"/>
|
package/dist/assets.d.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Retargeting the asset URLs PreTeXt emits.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* — author-supplied images and media, sageplot, asymptote — is emitted as a
|
|
8
|
-
* *runtime* URL under one of two fixed prefixes:
|
|
4
|
+
* Every asset a preview shows — author-supplied images and media, and
|
|
5
|
+
* everything `pretext generate` makes (latex-image, PreFigure, sageplot,
|
|
6
|
+
* asymptote) — is emitted as a *runtime* URL under one of two fixed prefixes:
|
|
9
7
|
*
|
|
10
8
|
* <img src="external/kitten.png">
|
|
9
|
+
* <img src="generated/latex-image/diagram.svg">
|
|
11
10
|
* <img src="generated/sageplot/plot.svg">
|
|
12
11
|
*
|
|
12
|
+
* (A portable build would instead inline the latex-image and PreFigure SVGs,
|
|
13
|
+
* reading them during the transform. The preview no longer builds portable,
|
|
14
|
+
* so those images reach the host here like the rest, and nothing has to read
|
|
15
|
+
* image files while rendering. See publication.ts.)
|
|
16
|
+
*
|
|
13
17
|
* Those prefixes (`$external-directory` / `$generated-directory` in
|
|
14
18
|
* publisher-variables.xsl) name directories a real build populates by copying
|
|
15
19
|
* files next to the output HTML. The preview has no output directory, so the
|
package/dist/banner.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Dismissible "this is a live preview" warning banner.
|
|
3
3
|
*
|
|
4
|
-
* The preview forces
|
|
5
|
-
* {@link
|
|
4
|
+
* The preview forces a few publication settings of its own (see
|
|
5
|
+
* {@link forcePreviewPublication}) and skips the asset-generation step
|
|
6
6
|
* entirely, so what an author sees while editing can genuinely differ from a
|
|
7
7
|
* real build — different chunking, no locally generated images, etc. The
|
|
8
8
|
* banner exists to say so, once, without nagging: it renders across the top
|