@pretextbook/pretext-html 0.2.0 → 0.4.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.
Files changed (48) hide show
  1. package/README.md +37 -6
  2. package/assets/preview-html.xsl +8 -4
  3. package/assets/upstream.json +1 -1
  4. package/assets/xsl/README.md +25 -24
  5. package/assets/xsl/entities.ent +20 -0
  6. package/assets/xsl/extract-biblio-csl.xsl +1 -1
  7. package/assets/xsl/extract-pg.xsl +111 -297
  8. package/assets/xsl/extract-qrcode.xsl +11 -1
  9. package/assets/xsl/extract-sageplot.xsl +1 -1
  10. package/assets/xsl/latex/pretext-latex-texstyle.xsl +1 -2
  11. package/assets/xsl/localizations/README.md +24 -24
  12. package/assets/xsl/pretext-assembly.xsl +101 -11
  13. package/assets/xsl/pretext-beamer.xsl +43 -146
  14. package/assets/xsl/pretext-braille-preprint.xsl +457 -201
  15. package/assets/xsl/pretext-common.xsl +388 -423
  16. package/assets/xsl/pretext-epub.xsl +301 -72
  17. package/assets/xsl/pretext-fo.xsl +70 -86
  18. package/assets/xsl/pretext-html.xsl +331 -259
  19. package/assets/xsl/pretext-jupyter.xsl +534 -322
  20. package/assets/xsl/pretext-latex-classic.xsl +14 -15
  21. package/assets/xsl/pretext-latex-common.xsl +385 -2389
  22. package/assets/xsl/pretext-latex.xsl +1995 -5
  23. package/assets/xsl/pretext-markdown.xsl +919 -0
  24. package/assets/xsl/pretext-numbers.xsl +22 -4
  25. package/assets/xsl/pretext-revealjs.xsl +241 -33
  26. package/assets/xsl/pretext-runestone-fitb.xsl +20 -22
  27. package/assets/xsl/pretext-runestone.xsl +3 -3
  28. package/assets/xsl/pretext-sage-doctest.xsl +2 -2
  29. package/assets/xsl/pretext-text-utilities.xsl +69 -1
  30. package/assets/xsl/pretext-text.xsl +1077 -107
  31. package/assets/xsl/publisher-variables.xsl +396 -452
  32. package/assets/xsl/support/play-button/README.md +1 -3
  33. package/assets/xsl/tests/README.md +1 -1
  34. package/assets/xsl/utilities/README.md +6 -8
  35. package/assets/xsl/utilities/report-publisher-variables.xsl +15 -0
  36. package/assets/xsl-bundle.json +1 -1
  37. package/dist/assets.d.ts +43 -0
  38. package/dist/assets.js +76 -0
  39. package/dist/cli-Cp6C0sif.js +654 -0
  40. package/dist/cli.js +1 -1
  41. package/dist/index.browser.js +367 -307
  42. package/dist/index.d.ts +5 -0
  43. package/dist/index.js +16 -11
  44. package/dist/missing-asset.d.ts +31 -0
  45. package/dist/publication.d.ts +36 -1
  46. package/dist/renderer.d.ts +49 -0
  47. package/package.json +9 -1
  48. package/dist/cli-B2LiKunq.js +0 -588
package/README.md CHANGED
@@ -69,6 +69,17 @@ const { html } = await renderHtml({
69
69
  - The user's publication file is respected, except
70
70
  `<html><platform portable="yes"/></html>` is always forced — that is what
71
71
  makes single-page in-memory output possible.
72
+ - `cssTheme: "denver"` supplies the PreTeXt HTML theme for projects that do not
73
+ choose one, by adding `<html><css theme="…"/></html>` to the publication file
74
+ used for the build (including the minimal one synthesized when you pass no
75
+ `publicationPath`). It is a default, never an override: a publication file
76
+ that already names a theme — `@theme`, or the deprecated `@style`/`@shell` —
77
+ keeps it, so the preview goes on matching what `pretext build` produces. The
78
+ themes the bundled stylesheets know are `default-modern` (PreTeXt's own
79
+ default), `denver`, `tacoma`, `salem`, `greeley` and `boulder`; a portable
80
+ build loads `theme-<name>.min.css` from the CDN, so an unrecognised name
81
+ gives an unstyled page. Not to be confused with `theme` below, which is the
82
+ light/dark mode _within_ whichever css theme is in force.
72
83
  - The compiled stylesheet is cached per `xslDir` (~1s to compile, then
73
84
  ~100ms–1s per render depending on document size).
74
85
  - `theme: "dark" | "light" | "system"` makes the preview follow the embedding
@@ -213,17 +224,37 @@ the message helper.
213
224
 
214
225
  ## Limitations (current WASM build)
215
226
 
216
- | Limitation | Cause | Fix |
217
- | ---------------------------------------------- | ----------------------------------------------- | --------------------------------------------------------------------------- |
218
- | No multi-file output (`exsl:document`) | Compiled with `FILESYSTEM=0` | Rebuild with `FILESYSTEM=1` (files land in MEMFS) |
219
- | JSPI required (flagged on Node) | Loader fetches resources mid-transform via JSPI | Feature-detect with `isJspiAvailable()`; engines without it need a fallback |
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 |
221
- | `xi:include` with `xpointer` unsupported | JS resolver stands in for libxml2's | Rebuild adding `xmlXIncludeProcessFlags` to the JSPI export list |
227
+ | Limitation | Cause | Fix |
228
+ | ---------------------------------------------- | ---------------------------------------------------- | --------------------------------------------------------------------------- |
229
+ | No multi-file output (`exsl:document`) | Compiled with `FILESYSTEM=0` | Rebuild with `FILESYSTEM=1` (files land in MEMFS) |
230
+ | JSPI required (flagged on Node) | Loader fetches resources mid-transform via JSPI | Feature-detect with `isJspiAvailable()`; engines without it need a fallback |
231
+ | 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 |
232
+ | `xi:include` with `xpointer` unsupported | JS resolver stands in for libxml2's | Rebuild adding `xmlXIncludeProcessFlags` to the JSPI export list |
233
+ | Renders run one at a time, never in parallel | Shared libxslt state; the transform suspends mid-run | Inherent; `renderHtml` queues concurrent calls for you |
222
234
 
223
235
  The whole-book stack overflow ("memory access out of bounds") that the stock
224
236
  `libxslt-wasm` build hit on large documents is **fixed** in the
225
237
  `@pretextbook/libxslt-wasm` fork, which links with a larger WASM stack.
226
238
 
239
+ ### Concurrency
240
+
241
+ A render is not reentrant. It drives a single cached compiled stylesheet
242
+ through a patched `globalThis.fetch` and shared mount tables, and it _suspends_
243
+ mid-transform to fetch stylesheets — which is precisely the window in which
244
+ another render would get to run. Overlapping renders interleave inside libxslt
245
+ and corrupt it.
246
+
247
+ `renderHtml` therefore **queues**: concurrent calls are safe, and each resolves
248
+ with its own result, but they execute one at a time rather than in parallel. A
249
+ render that rejects does not stall the queue.
250
+
251
+ This matters mainly if you drive the internals yourself. If you do, serialize
252
+ your own calls — the corruption is not self-describing: it surfaces as an
253
+ out-of-bounds memory fault, and afterwards the WASM instance aborts on _every_
254
+ later call for the lifetime of the process. Once that has happened, only a
255
+ restart (or a page reload) recovers; `renderHtml` detects the state and says so
256
+ rather than repeating the underlying assertion.
257
+
227
258
  Missing generated assets degrade gracefully: the transform serves a stub for
228
259
  missing files, PreTeXt emits its usual `PTX:ERROR` advice, and the preview
229
260
  renders without the image.
@@ -111,11 +111,15 @@
111
111
  <!-- this *must* be first for maximum utility -->
112
112
  <xsl:call-template name="skip-to-content-link" />
113
113
  <!-- HTML5 body/header will be a "banner" landmark automatically -->
114
- <header id="ptx-masthead" class="ptx-masthead">
114
+ <header id="ptx-masthead" class="ptx-masthead" role="banner">
115
115
  <div class="ptx-banner">
116
116
  <xsl:call-template name="brand-logo" />
117
117
  <div class="title-container">
118
- <h1 class="heading">
118
+ <xsl:variable name="banner-heading-element-type">
119
+ <xsl:apply-templates select="." mode="banner-heading-element-type"/>
120
+ </xsl:variable>
121
+ <xsl:element name="{$banner-heading-element-type}">
122
+ <xsl:attribute name="class">heading ptx-banner-heading</xsl:attribute>
119
123
  <xsl:variable name="root-filename">
120
124
  <xsl:apply-templates select="$document-root" mode="containing-filename" />
121
125
  </xsl:variable>
@@ -133,7 +137,7 @@
133
137
  </span>
134
138
  </xsl:if>
135
139
  </a>
136
- </h1>
140
+ </xsl:element>
137
141
  <!-- Serial list of authors/editors -->
138
142
  <xsl:if test="$b-html-banner-byline">
139
143
  <p class="byline">
@@ -142,7 +146,7 @@
142
146
  </p>
143
147
  </xsl:if>
144
148
  </div> <!-- title-container -->
145
- </div> <!-- banner -->
149
+ </div> <!-- banner -->
146
150
  </header> <!-- masthead -->
147
151
  <xsl:apply-templates select="." mode="primary-navigation"/>
148
152
  <xsl:apply-templates select="." mode="latex-macros"/>
@@ -3,5 +3,5 @@
3
3
  "repository": "PreTeXtBook/pretext",
4
4
  "ref": "master"
5
5
  },
6
- "refreshed": "2026-07-08T00:48:30.933Z"
6
+ "refreshed": "2026-07-26T23:26:59.210Z"
7
7
  }
@@ -1,31 +1,32 @@
1
- # eXtensible Stylesheet Language (XSL) Stylesheets
1
+ eXtensible Stylesheet Language (XSL) Stylesheets
2
+ ================================================
2
3
 
3
4
  XSL stylesheets are the primary vehicle for converting PreTeXt XML
4
- source into various output formats. As such, they are sometimes
5
- simply called "conversions." Here we list **some** of the available
6
- conversions, the list is not exhaustive. See _The PreTeXt Guide_
5
+ source into various output formats. As such, they are sometimes
6
+ simply called "conversions." Here we list **some** of the available
7
+ conversions, the list is not exhaustive. See _The PreTeXt Guide_
7
8
  for detailed documentation of use, in chapters of the part
8
9
  titled _Publisher's Guide_.
9
10
 
10
- - `pretext-latex.xsl` - conversion to LaTeX, which can then
11
- be converted to PDF, in print or electronic flavors.
12
- - `pretext-html.xsl` - conversion to HTML for online use.
13
- - `pretext-epub.xsl` - conversion to EPUB, which
14
- requires significant additional processing. So this stylesheet
15
- is not meant to be applied in isolation. See the `pretext/pretext`
16
- Python script for an option to initiate the processing pipeline.
17
- - `pretext-jupyter.xsl` - conversion to Jupyter notebooks.
18
- - `pretext-revealjs.xsl` - conversion of slideshows to HTML.
19
- - `pretext-beamer.xsl` - conversion of slideshows to PDF.
20
- - `pretext-braille.xsl` - conversion to a precursor for braille output, which
21
- requires significant further processing. So this stylesheet
22
- is not meant to be applied in isolation. See the `pretext/pretext`
23
- Python script for an option to initiate the processing pipeline.
24
- - `pretext-common.xsl` - base templates, and not useful in isolation.
25
- - `pretext-assembly.xsl` - pre-processing stylesheet, which creates an
26
- enhanced version of source. Applied in a controlled way by other stylesheets.
27
- See the `utilities\pretext-enhanced-source.xsl` stylesheet for a demonstration.
28
- - `extract-*.xsl` - used to isolate particular parts of a PreTeXt
29
- document, typically for subsequent processing by a script.
11
+ * `pretext-latex.xsl` - conversion to LaTeX, which can then
12
+ be converted to PDF, in print or electronic flavors.
13
+ * `pretext-html.xsl` - conversion to HTML for online use.
14
+ * `pretext-epub.xsl` - conversion to EPUB, which
15
+ requires significant additional processing. So this stylesheet
16
+ is not meant to be applied in isolation. See the `pretext/pretext`
17
+ Python script for an option to initiate the processing pipeline.
18
+ * `pretext-jupyter.xsl` - conversion to Jupyter notebooks.
19
+ * `pretext-revealjs.xsl` - conversion of slideshows to HTML.
20
+ * `pretext-beamer.xsl` - conversion of slideshows to PDF.
21
+ * `pretext-braille.xsl` - conversion to a precursor for braille output, which
22
+ requires significant further processing. So this stylesheet
23
+ is not meant to be applied in isolation. See the `pretext/pretext`
24
+ Python script for an option to initiate the processing pipeline.
25
+ * `pretext-common.xsl` - base templates, and not useful in isolation.
26
+ * `pretext-assembly.xsl` - pre-processing stylesheet, which creates an
27
+ enhanced version of source. Applied in a controlled way by other stylesheets.
28
+ See the `utilities\pretext-enhanced-source.xsl` stylesheet for a demonstration.
29
+ * `extract-*.xsl` - used to isolate particular parts of a PreTeXt
30
+ document, typically for subsequent processing by a script.
30
31
 
31
32
  (Updated: 2020-06-12)
@@ -37,6 +37,14 @@
37
37
 
38
38
  <!ENTITY SPECIALIZED-DIVISION "exercises|worksheet|handout|reading-questions|references|glossary|solutions">
39
39
 
40
+ <!-- "Division companions" are the non-structural companions of a -->
41
+ <!-- structured traditional division: they may earn their own page -->
42
+ <!-- (and links) when their parent is realized as a summary page in -->
43
+ <!-- a chunked conversion (HTML and derivatives). The schema only -->
44
+ <!-- allows these four elements, division-flavored, in the parents -->
45
+ <!-- listed. The filter form presumes context has qualified parents. -->
46
+ <!ENTITY DIVISION-COMPANION "introduction[parent::article or parent::chapter or parent::appendix or parent::section or parent::subsection]|conclusion[parent::article or parent::chapter or parent::appendix or parent::section or parent::subsection]|objectives[parent::article or parent::chapter or parent::appendix or parent::section or parent::subsection]|outcomes[parent::article or parent::chapter or parent::appendix or parent::section or parent::subsection]">
47
+
40
48
  <!-- for filtering nodes, eg *[&STRUCTURAL-FILTER;], *[not(&STRUCTURAL-FILTER;)] -->
41
49
  <!ENTITY STRUCTURAL-FILTER "self::book or self::article or self::slideshow or self::letter or self::memo or self::frontmatter or self::part or self::chapter or self::appendix or self::index or self::preface or self::acknowledgement or self::biography or self::foreword or self::dedication or self::colophon or self::section or self::subsection or self::subsubsection or self::slide or self::exercises or self::worksheet or self::handout or self::reading-questions or self::solutions or self::references or self::glossary or self::backmatter">
42
50
 
@@ -44,6 +52,8 @@
44
52
 
45
53
  <!ENTITY SPECIALIZED-DIVISION-FILTER "self::exercises or self::worksheet or self::handout or self::reading-questions or self::references or self::glossary or self::solutions">
46
54
 
55
+ <!ENTITY DIVISION-COMPANION-FILTER "self::introduction or self::conclusion or self::objectives or self::outcomes">
56
+
47
57
  <!-- NB: (2019-06-12) Only the two metadata "filters" seem to -->
48
58
  <!-- be in use, so only those are being maintained. grep'ing on -->
49
59
  <!-- METADATA v. METADATA-FILTER, and applying "wc" makes this evident. -->
@@ -139,6 +149,16 @@
139
149
  <!ENTITY FUNDAMENTAL-BLOCK-FILTER "(&DEFINITION-FILTER;) or (&THEOREM-FILTER;) or (&AXIOM-FILTER;) or (&REMARK-FILTER;) or (&COMPUTATION-FILTER;) or (&EXAMPLE-FILTER;)">
140
150
  <!ENTITY TOP-FIGURE-FILTER "(&FIGURE-FILTER;) and not(parent::sidebyside/parent::figure or parent::sidebyside/parent::sbsgroup/parent::figure)">
141
151
 
152
+ <!-- Panels of a "sidebyside", and content of a "stack" panel. The -->
153
+ <!-- lists mirror the schema, plus grandfathered items the code still -->
154
+ <!-- tolerates: "audio", "video", "interactive" (precluded -->
155
+ <!-- 2026-07-22, may someday be removed). An "exercise" panel -->
156
+ <!-- (worksheet or handout only) and a "slate" panel (within an -->
157
+ <!-- "interactive" only) are policed by the validation-plus -->
158
+ <!-- stylesheet. -->
159
+ <!ENTITY SBSPANEL "p|pre|ol|ul|dl|program|console|poem|audio|video|interactive|slate|exercise|image|figure|table|listing|list|tabular|stack">
160
+ <!ENTITY STACKABLE "tabular|image|p|pre|ol|ul|dl|audio|video|interactive|slate|program|console">
161
+
142
162
  <!-- appendages of examples, exercises, tasks -->
143
163
  <!ENTITY SOLUTION-LIKE "hint|answer|solution">
144
164
  <!ENTITY SOLUTION-FILTER "self::hint or self::answer or self::solution">
@@ -100,7 +100,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
100
100
  <!-- TODO: perhaps report content also, as a better assist, or the self/parent/ancestor biblio id -->
101
101
  <!-- TODO: refine to include un-implemented bits of "citeproc-py" (e/g static-ordering) -->
102
102
  <xsl:template match="*" mode="biblio-to-json">
103
- <xsl:message>BUG: PreTeXt "biblio" markup using a "<xsl:value-of select="local-name()"/>" element is not implemented</xsl:message>
103
+ <xsl:message>PTX:BUG: PreTeXt "biblio" markup using a "<xsl:value-of select="local-name()"/>" element is not implemented</xsl:message>
104
104
  </xsl:template>
105
105
 
106
106
  <!-- Gross JSON array structure, duplicate an ID for the division -->