@pretextbook/pretext-html 0.8.0 → 0.9.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 (36) hide show
  1. package/assets/preview-html.xsl +16 -0
  2. package/assets/upstream.json +1 -1
  3. package/assets/xsl/extract-dynamic.xsl +54 -3
  4. package/assets/xsl/extract-gdscript.xsl +61 -0
  5. package/assets/xsl/extract-sageplot.xsl +3 -0
  6. package/assets/xsl/localizations/it-IT.xml +37 -41
  7. package/assets/xsl/pretext-assembly.xsl +188 -24
  8. package/assets/xsl/pretext-beamer.xsl +57 -12
  9. package/assets/xsl/pretext-common.xsl +156 -28
  10. package/assets/xsl/pretext-epub.xsl +0 -5
  11. package/assets/xsl/pretext-fo.xsl +110 -48
  12. package/assets/xsl/pretext-html.xsl +147 -54
  13. package/assets/xsl/pretext-jupyter.xsl +1 -0
  14. package/assets/xsl/pretext-latex-classic.xsl +2 -2
  15. package/assets/xsl/pretext-latex-common.xsl +268 -134
  16. package/assets/xsl/pretext-latex.xsl +16 -6
  17. package/assets/xsl/pretext-numbers.xsl +10 -0
  18. package/assets/xsl/pretext-revealjs.xsl +68 -1
  19. package/assets/xsl/pretext-runestone-fitb.xsl +179 -84
  20. package/assets/xsl/pretext-runestone-static.xsl +72 -20
  21. package/assets/xsl/pretext-runestone.xsl +27 -4
  22. package/assets/xsl/pretext-text-utilities.xsl +7 -0
  23. package/assets/xsl/pretext-text.xsl +17 -0
  24. package/assets/xsl/publisher-variables.xsl +39 -0
  25. package/assets/xsl-bundle.json +1 -1
  26. package/dist/cli-BUrNZxov.js +1098 -0
  27. package/dist/cli.js +1 -1
  28. package/dist/html-static.d.ts +2 -2
  29. package/dist/index.browser.js +595 -386
  30. package/dist/index.d.ts +4 -0
  31. package/dist/index.js +35 -30
  32. package/dist/renderer.d.ts +35 -0
  33. package/dist/skeleton.d.ts +41 -0
  34. package/dist/xrefs.d.ts +54 -0
  35. package/package.json +1 -1
  36. package/dist/cli-Bcn4t3B1.js +0 -871
package/dist/index.d.ts CHANGED
@@ -9,6 +9,10 @@ export type { RenderTarget } from './target.js';
9
9
  export { injectRevealBridge, isRevealView, revealBridgeScript, } from './reveal.js';
10
10
  export type { RevealView, RevealViewOptions } from './reveal.js';
11
11
  export { openBornHiddenKnowls } from './knowls.js';
12
+ export { buildSkeleton, divisionLevel, replaceDivision } from './skeleton.js';
13
+ export type { Skeleton } from './skeleton.js';
14
+ export { OFF_PAGE_MESSAGE, rewriteXrefLinks } from './xrefs.js';
15
+ export type { RewriteXrefLinkOptions } from './xrefs.js';
12
16
  export { rewriteAssetUrls } from './assets.js';
13
17
  export type { AssetKind, AssetUrlResolver } from './assets.js';
14
18
  export { describeAsset, missingAssetPlaceholder, missingAssetSvg, } from './missing-asset.js';
package/dist/index.js CHANGED
@@ -1,32 +1,37 @@
1
- import { P as r, d as i, a, f as t, b as n, i as o, c as l, o as d, p, r as c, m, s as E, e as g, x as v } from "./cli-Bcn4t3B1.js";
2
- import { injectRevealBridge as B, isRevealView as S, revealBridgeScript as f } from "./reveal.js";
3
- import { describeAsset as R, missingAssetPlaceholder as w, missingAssetSvg as h, rewriteAssetUrls as x } from "./assets.js";
4
- import { PREVIEW_THEME_MESSAGE as b, injectThemeBridge as u, isPreviewTheme as M, previewThemeMessage as _, themeBridgeScript as j } from "./theme.js";
1
+ import { O as r, P as i, b as a, d as t, a as n, c as o, f as l, e as d, i as p, g as E, o as c, p as m, r as v, h as S, j as g, m as A, s as f, k as B, x as P } from "./cli-BUrNZxov.js";
2
+ import { injectRevealBridge as R, isRevealView as h, revealBridgeScript as _ } from "./reveal.js";
3
+ import { describeAsset as u, missingAssetPlaceholder as x, missingAssetSvg as M, rewriteAssetUrls as T } from "./assets.js";
4
+ import { PREVIEW_THEME_MESSAGE as G, injectThemeBridge as k, isPreviewTheme as H, previewThemeMessage as L, themeBridgeScript as O } from "./theme.js";
5
5
  export {
6
- r as PREVIEW_BANNER_STORAGE_KEY,
7
- b as PREVIEW_THEME_MESSAGE,
8
- i as defaultXslDir,
9
- R as describeAsset,
10
- a as detectRenderTarget,
11
- t as findSourceMapEntry,
12
- n as forcePortablePublication,
13
- o as injectPreviewBanner,
14
- B as injectRevealBridge,
15
- u as injectThemeBridge,
16
- l as isJspiAvailable,
17
- M as isPreviewTheme,
18
- S as isRevealView,
19
- w as missingAssetPlaceholder,
20
- h as missingAssetSvg,
21
- d as openBornHiddenKnowls,
22
- p as previewBannerScript,
23
- _ as previewThemeMessage,
24
- c as renderHtml,
25
- f as revealBridgeScript,
26
- x as rewriteAssetUrls,
27
- m as runCli,
28
- E as setAssetsBase,
29
- g as setMountReader,
30
- j as themeBridgeScript,
31
- v as xpathStringLiteral
6
+ r as OFF_PAGE_MESSAGE,
7
+ i as PREVIEW_BANNER_STORAGE_KEY,
8
+ G as PREVIEW_THEME_MESSAGE,
9
+ a as buildSkeleton,
10
+ t as defaultXslDir,
11
+ u as describeAsset,
12
+ n as detectRenderTarget,
13
+ o as divisionLevel,
14
+ l as findSourceMapEntry,
15
+ d as forcePortablePublication,
16
+ p as injectPreviewBanner,
17
+ R as injectRevealBridge,
18
+ k as injectThemeBridge,
19
+ E as isJspiAvailable,
20
+ H as isPreviewTheme,
21
+ h as isRevealView,
22
+ x as missingAssetPlaceholder,
23
+ M as missingAssetSvg,
24
+ c as openBornHiddenKnowls,
25
+ m as previewBannerScript,
26
+ L as previewThemeMessage,
27
+ v as renderHtml,
28
+ S as replaceDivision,
29
+ _ as revealBridgeScript,
30
+ T as rewriteAssetUrls,
31
+ g as rewriteXrefLinks,
32
+ A as runCli,
33
+ f as setAssetsBase,
34
+ B as setMountReader,
35
+ O as themeBridgeScript,
36
+ P as xpathStringLiteral
32
37
  };
@@ -134,6 +134,41 @@ export interface RenderOptions {
134
134
  * the book's chapters. Only used in fragment mode.
135
135
  */
136
136
  docinfoSourcePath?: string;
137
+ /**
138
+ * Path to the complete document (typically the project's main.ptx) that the
139
+ * fragment being rendered belongs to. Renders the fragment **in place** in
140
+ * that document instead of standalone, which is what makes its numbering and
141
+ * its cross-references match the built book.
142
+ *
143
+ * A fragment rendered on its own restarts numbering at 1 and cannot see any
144
+ * `<xref>` target outside itself, so previewing section 3.2 shows "Theorem
145
+ * 1.1" where the book says "Theorem 3.2.1", and references leaving the
146
+ * section render as PreTeXt's `[cross-reference to target(s) ... missing]`
147
+ * placeholder. With this set, the document is pruned to a skeleton — every
148
+ * division, the previewed fragment verbatim, and the divisions holding the
149
+ * targets it references — and rendered with upstream's `subtree` parameter,
150
+ * which emits only the previewed division. See skeleton.ts for why that
151
+ * numbers identically to rendering the whole document, and for the cost.
152
+ *
153
+ * The fragment supplies its own content, so unsaved editor text is what gets
154
+ * rendered; the document on disk supplies only the structure around it. That
155
+ * matching is by `@xml:id`: a fragment whose root element has none, or whose
156
+ * id is not in the document, silently falls back to the standalone wrapper.
157
+ *
158
+ * Supersedes `docinfoSourcePath`, since the skeleton carries the document's
159
+ * real `<docinfo>`. Only used in fragment mode; ignored for whole documents.
160
+ */
161
+ contextSourcePath?: string;
162
+ /**
163
+ * Tooltip for links whose target is not on the previewed page — the table of
164
+ * contents, and cross-references reaching outside the fragment. Those cannot
165
+ * navigate in a single-page preview, so they are stripped of their `@href`
166
+ * and given this as an explanation (see xrefs.ts). Defaults to
167
+ * {@link OFF_PAGE_MESSAGE}.
168
+ *
169
+ * Whole-document previews link only within the page, so nothing is affected.
170
+ */
171
+ offPageMessage?: string;
137
172
  /**
138
173
  * Also compute a source map: one entry per element, in document order,
139
174
  * mapping the element's @unique-id (its HTML id, when the page emits one)
@@ -0,0 +1,41 @@
1
+ import { Element, Root } from 'xast';
2
+ /** A pruned document, ready to render as a fragment preview. */
3
+ export interface Skeleton {
4
+ /** The pruned document, serialized. */
5
+ content: string;
6
+ /** `@xml:id` of the division to render; pass as the `subtree` param. */
7
+ divisionId: string;
8
+ /** That division's numbering level; pass as the `subtree-level` param. */
9
+ level: number;
10
+ }
11
+ /**
12
+ * A division's numbering level, mirroring `mode="level"` in
13
+ * pretext-numbers.xsl. `ancestors` runs from the document element down to (and
14
+ * including) the division itself.
15
+ *
16
+ * `hasParts` is upstream's `$b-has-parts` (`boolean($root/book/part)`), which
17
+ * pushes a book's chapters down a level.
18
+ */
19
+ export declare function divisionLevel(ancestors: Element[], hasParts: boolean): number;
20
+ /**
21
+ * Swap the division carrying `id` for `replacement`, in place. Returns false
22
+ * when the tree holds no such division.
23
+ *
24
+ * This is what lets a preview show *unsaved* work: the document on disk
25
+ * supplies the structure around the fragment, while the fragment itself comes
26
+ * from the editor's buffer.
27
+ */
28
+ export declare function replaceDivision(tree: Root, id: string, replacement: Element): boolean;
29
+ /**
30
+ * Build a skeleton of `tree` that preserves the numbering of the division
31
+ * carrying `divisionId` and resolves the cross-references it makes.
32
+ *
33
+ * Prunes `tree` in place and serializes the result, so the caller can go on to
34
+ * use the same tree — computing a source map from it, for instance, which is
35
+ * what the renderer does.
36
+ *
37
+ * Returns undefined when the tree holds no such division — an unsaved file
38
+ * whose `@xml:id` is not yet in the main document, say — which the caller
39
+ * should treat as "fall back to the standalone fragment wrapper".
40
+ */
41
+ export declare function buildSkeleton(tree: Root, divisionId: string): Skeleton | undefined;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Reconcile a subtree render's links with the single page it actually
3
+ * produced.
4
+ *
5
+ * A fragment preview is rendered with upstream's `subtree` parameter: the
6
+ * whole document is assembled — so numbering is right and every `<xref>`
7
+ * finds its target — but only one division is emitted. The links, though, are
8
+ * written for the multi-page build that assembling implies. PreTeXt hands back
9
+ * `sec-two.html#thm-b` for a theorem in another section, `sec-one.html#thm-a`
10
+ * for one on this very page, and a bare `sec-three.html` for each table of
11
+ * contents entry. None of those files exist: there is one page, in memory.
12
+ *
13
+ * Two fixes, from one question — is the target on this page?
14
+ *
15
+ * - **On the page.** Rewrite to a bare `#id`. The link then does exactly
16
+ * what the built book's would: scroll to the target. Answering by looking
17
+ * for the `id` in the rendered HTML, rather than by reasoning about
18
+ * PreTeXt's filename scheme, means this cannot drift when that scheme
19
+ * changes, and it costs one pass over the page.
20
+ *
21
+ * - **Not on the page.** Drop the `@href` and explain in a tooltip. A link
22
+ * that silently does nothing is worse than an obvious non-link, and the
23
+ * reader has no other way to learn that the preview is showing one section
24
+ * of something larger. The element, its classes and its text are all left
25
+ * alone, so the page still reads like the built one — the same tactic, and
26
+ * the same `aria-disabled` spelling, as the inert print-preview button in
27
+ * preview-html.xsl (see PRINTOUT_LINK_OVERRIDE in scripts/refresh-xsl.mjs).
28
+ *
29
+ * Applied to the rendered HTML rather than in the stylesheet because the
30
+ * question cannot be answered during the transform: whether a target lands on
31
+ * the page is a fact about the finished output, and upstream computes every
32
+ * URL through `mode="url"` from a dozen call sites. One pass over the result
33
+ * is one rule that cannot fall out of step with them.
34
+ */
35
+ /** Default tooltip on a link whose target is not on the previewed page. */
36
+ export declare const OFF_PAGE_MESSAGE = "This live preview shows a single division, so links into the rest of the document do not work here.";
37
+ export interface RewriteXrefLinkOptions {
38
+ /**
39
+ * Tooltip for a link whose target is not on this page. Defaults to
40
+ * {@link OFF_PAGE_MESSAGE}. When the link already carries a tooltip — an
41
+ * `<xref>` is given one naming its target, like "Theorem 2.1: Beta" — the
42
+ * two are joined rather than the original being thrown away.
43
+ */
44
+ offPageMessage?: string;
45
+ }
46
+ /**
47
+ * Point every link in `html` at something real: same-page targets become
48
+ * `#id`, and links leaving the page become inert with an explanatory tooltip.
49
+ *
50
+ * Safe to run on any rendered page. A whole-document preview emits only
51
+ * same-page anchors and absolute URLs, so nothing matches and the HTML comes
52
+ * back unchanged.
53
+ */
54
+ export declare function rewriteXrefLinks(html: string, options?: RewriteXrefLinkOptions): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pretextbook/pretext-html",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Convert PreTeXt documents to HTML in pure JavaScript using the official PreTeXt XSLT stylesheets via libxslt-wasm. No Python or PreTeXt installation required.",
5
5
  "author": "Oscar Levin",
6
6
  "license": "MIT",