@pretextbook/pretext-html 0.8.0 → 0.10.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/assets/preview-html.xsl +16 -0
- package/assets/upstream.json +1 -1
- package/assets/xsl/extract-dynamic.xsl +54 -3
- package/assets/xsl/extract-gdscript.xsl +61 -0
- package/assets/xsl/extract-sageplot.xsl +3 -0
- package/assets/xsl/localizations/it-IT.xml +37 -41
- package/assets/xsl/pretext-assembly.xsl +188 -24
- package/assets/xsl/pretext-beamer.xsl +57 -12
- package/assets/xsl/pretext-common.xsl +156 -28
- package/assets/xsl/pretext-epub.xsl +0 -5
- package/assets/xsl/pretext-fo.xsl +110 -48
- package/assets/xsl/pretext-html.xsl +147 -54
- package/assets/xsl/pretext-jupyter.xsl +1 -0
- package/assets/xsl/pretext-latex-classic.xsl +2 -2
- package/assets/xsl/pretext-latex-common.xsl +268 -134
- package/assets/xsl/pretext-latex.xsl +16 -6
- package/assets/xsl/pretext-numbers.xsl +10 -0
- package/assets/xsl/pretext-revealjs.xsl +68 -1
- package/assets/xsl/pretext-runestone-fitb.xsl +179 -84
- package/assets/xsl/pretext-runestone-static.xsl +72 -20
- package/assets/xsl/pretext-runestone.xsl +27 -4
- package/assets/xsl/pretext-text-utilities.xsl +7 -0
- package/assets/xsl/pretext-text.xsl +17 -0
- package/assets/xsl/publisher-variables.xsl +39 -0
- package/assets/xsl-bundle.json +1 -1
- package/dist/cli-BONFCRgl.js +1099 -0
- package/dist/cli.js +1 -1
- package/dist/html-static.d.ts +2 -2
- package/dist/index.browser.d.ts +4 -0
- package/dist/index.browser.js +607 -393
- package/dist/index.d.ts +4 -0
- package/dist/index.js +35 -30
- package/dist/renderer.d.ts +53 -0
- package/dist/skeleton.d.ts +41 -0
- package/dist/xrefs.d.ts +54 -0
- package/package.json +1 -1
- 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 {
|
|
2
|
-
import { injectRevealBridge as
|
|
3
|
-
import { describeAsset as
|
|
4
|
-
import { PREVIEW_THEME_MESSAGE as
|
|
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-BONFCRgl.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
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
n as
|
|
13
|
-
o as
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
c as
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
};
|
package/dist/renderer.d.ts
CHANGED
|
@@ -134,6 +134,59 @@ 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
|
+
* Optional when `contextSourceContent` is given — see there — but still
|
|
161
|
+
* used as the virtual base for xi:include resolution and source-map paths
|
|
162
|
+
* even then, so pass it whenever a real path is available.
|
|
163
|
+
*/
|
|
164
|
+
contextSourcePath?: string;
|
|
165
|
+
/**
|
|
166
|
+
* The complete document's source text, used instead of reading
|
|
167
|
+
* `contextSourcePath` from disk. Lets a browser host that already holds the
|
|
168
|
+
* whole project in memory place a fragment in its document — with
|
|
169
|
+
* correct numbering and resolved `<xref>`s — without a filesystem or
|
|
170
|
+
* network round trip, and lets the skeleton see *unsaved* sibling
|
|
171
|
+
* divisions that a read from disk never would.
|
|
172
|
+
*
|
|
173
|
+
* `contextSourcePath` becomes optional when this is given, defaulting to
|
|
174
|
+
* `sourcePath` as the virtual base for resolving the document's own
|
|
175
|
+
* xi:includes; pass `contextSourcePath` too when a real one is available,
|
|
176
|
+
* for more useful source-map/error paths. Exactly parallel to
|
|
177
|
+
* `sourceContent` vs. `sourcePath`.
|
|
178
|
+
*/
|
|
179
|
+
contextSourceContent?: string;
|
|
180
|
+
/**
|
|
181
|
+
* Tooltip for links whose target is not on the previewed page — the table of
|
|
182
|
+
* contents, and cross-references reaching outside the fragment. Those cannot
|
|
183
|
+
* navigate in a single-page preview, so they are stripped of their `@href`
|
|
184
|
+
* and given this as an explanation (see xrefs.ts). Defaults to
|
|
185
|
+
* {@link OFF_PAGE_MESSAGE}.
|
|
186
|
+
*
|
|
187
|
+
* Whole-document previews link only within the page, so nothing is affected.
|
|
188
|
+
*/
|
|
189
|
+
offPageMessage?: string;
|
|
137
190
|
/**
|
|
138
191
|
* Also compute a source map: one entry per element, in document order,
|
|
139
192
|
* 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;
|
package/dist/xrefs.d.ts
ADDED
|
@@ -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.
|
|
3
|
+
"version": "0.10.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",
|