@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.
- package/README.md +37 -6
- package/assets/preview-html.xsl +8 -4
- package/assets/upstream.json +1 -1
- package/assets/xsl/README.md +25 -24
- package/assets/xsl/entities.ent +20 -0
- package/assets/xsl/extract-biblio-csl.xsl +1 -1
- package/assets/xsl/extract-pg.xsl +111 -297
- package/assets/xsl/extract-qrcode.xsl +11 -1
- package/assets/xsl/extract-sageplot.xsl +1 -1
- package/assets/xsl/latex/pretext-latex-texstyle.xsl +1 -2
- package/assets/xsl/localizations/README.md +24 -24
- package/assets/xsl/pretext-assembly.xsl +101 -11
- package/assets/xsl/pretext-beamer.xsl +43 -146
- package/assets/xsl/pretext-braille-preprint.xsl +457 -201
- package/assets/xsl/pretext-common.xsl +388 -423
- package/assets/xsl/pretext-epub.xsl +301 -72
- package/assets/xsl/pretext-fo.xsl +70 -86
- package/assets/xsl/pretext-html.xsl +331 -259
- package/assets/xsl/pretext-jupyter.xsl +534 -322
- package/assets/xsl/pretext-latex-classic.xsl +14 -15
- package/assets/xsl/pretext-latex-common.xsl +385 -2389
- package/assets/xsl/pretext-latex.xsl +1995 -5
- package/assets/xsl/pretext-markdown.xsl +919 -0
- package/assets/xsl/pretext-numbers.xsl +22 -4
- package/assets/xsl/pretext-revealjs.xsl +241 -33
- package/assets/xsl/pretext-runestone-fitb.xsl +20 -22
- package/assets/xsl/pretext-runestone.xsl +3 -3
- package/assets/xsl/pretext-sage-doctest.xsl +2 -2
- package/assets/xsl/pretext-text-utilities.xsl +69 -1
- package/assets/xsl/pretext-text.xsl +1077 -107
- package/assets/xsl/publisher-variables.xsl +396 -452
- package/assets/xsl/support/play-button/README.md +1 -3
- package/assets/xsl/tests/README.md +1 -1
- package/assets/xsl/utilities/README.md +6 -8
- package/assets/xsl/utilities/report-publisher-variables.xsl +15 -0
- package/assets/xsl-bundle.json +1 -1
- package/dist/assets.d.ts +43 -0
- package/dist/assets.js +76 -0
- package/dist/cli-Cp6C0sif.js +654 -0
- package/dist/cli.js +1 -1
- package/dist/index.browser.js +367 -307
- package/dist/index.d.ts +5 -0
- package/dist/index.js +16 -11
- package/dist/missing-asset.d.ts +31 -0
- package/dist/publication.d.ts +36 -1
- package/dist/renderer.d.ts +49 -0
- package/package.json +9 -1
- package/dist/cli-B2LiKunq.js +0 -588
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,11 @@ export type { RenderOptions, RenderResult } from './renderer.js';
|
|
|
3
3
|
export { findSourceMapEntry } from './sourcemap.js';
|
|
4
4
|
export type { PtxSourceMap, SourceMapEntry } from './sourcemap.js';
|
|
5
5
|
export { forcePortablePublication } from './publication.js';
|
|
6
|
+
export { rewriteAssetUrls } from './assets.js';
|
|
7
|
+
export type { AssetKind, AssetUrlResolver } from './assets.js';
|
|
8
|
+
export { describeAsset, missingAssetPlaceholder, missingAssetSvg, } from './missing-asset.js';
|
|
9
|
+
export type { MissingAsset } from './missing-asset.js';
|
|
10
|
+
export type { AssetDirectories } from './publication.js';
|
|
6
11
|
export { PREVIEW_THEME_MESSAGE, isPreviewTheme, previewThemeMessage, themeBridgeScript, injectThemeBridge, } from './theme.js';
|
|
7
12
|
export type { PreviewTheme, PreviewThemeMessage } from './theme.js';
|
|
8
13
|
export { main as runCli } from './cli.js';
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
import { d as
|
|
2
|
-
import {
|
|
1
|
+
import { d as r, f as i, a as t, i as a, r as l, m as o, s as m, b as n, x as d } from "./cli-Cp6C0sif.js";
|
|
2
|
+
import { describeAsset as c, missingAssetPlaceholder as f, missingAssetSvg as g, rewriteAssetUrls as A } from "./assets.js";
|
|
3
|
+
import { PREVIEW_THEME_MESSAGE as h, injectThemeBridge as S, isPreviewTheme as b, previewThemeMessage as u, themeBridgeScript as x } from "./theme.js";
|
|
3
4
|
export {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
i as
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
h as PREVIEW_THEME_MESSAGE,
|
|
6
|
+
r as defaultXslDir,
|
|
7
|
+
c as describeAsset,
|
|
8
|
+
i as findSourceMapEntry,
|
|
9
|
+
t as forcePortablePublication,
|
|
10
|
+
S as injectThemeBridge,
|
|
11
|
+
a as isJspiAvailable,
|
|
12
|
+
b as isPreviewTheme,
|
|
13
|
+
f as missingAssetPlaceholder,
|
|
14
|
+
g as missingAssetSvg,
|
|
15
|
+
u as previewThemeMessage,
|
|
12
16
|
l as renderHtml,
|
|
17
|
+
A as rewriteAssetUrls,
|
|
13
18
|
o as runCli,
|
|
14
19
|
m as setAssetsBase,
|
|
15
20
|
n as setMountReader,
|
|
16
|
-
|
|
21
|
+
x as themeBridgeScript,
|
|
17
22
|
d as xpathStringLiteral
|
|
18
23
|
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AssetKind } from './assets.js';
|
|
2
|
+
/** What a missing asset is, in the terms an author would recognise. */
|
|
3
|
+
export interface MissingAsset {
|
|
4
|
+
kind: AssetKind;
|
|
5
|
+
/**
|
|
6
|
+
* For generated assets, the producing tool — `latex-image`, `sageplot`,
|
|
7
|
+
* `asymptote`, `prefigure` — which under managed directories is literally
|
|
8
|
+
* the first path segment, and is also the `pretext generate` target. For
|
|
9
|
+
* external assets, a coarse media word derived from the extension.
|
|
10
|
+
*/
|
|
11
|
+
assetType: string;
|
|
12
|
+
/** Basename, for display. */
|
|
13
|
+
fileName: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Classify an asset path. Generated paths are `<tool>/<name>` under managed
|
|
17
|
+
* directories; a path with no directory segment predates that scheme, so there
|
|
18
|
+
* is no tool name to report.
|
|
19
|
+
*/
|
|
20
|
+
export declare function describeAsset(kind: AssetKind, relPath: string): MissingAsset;
|
|
21
|
+
/** Render the placeholder as standalone SVG markup. */
|
|
22
|
+
export declare function missingAssetSvg(asset: MissingAsset): string;
|
|
23
|
+
/**
|
|
24
|
+
* The placeholder as a `data:` URI, ready to drop into an `img` `src`.
|
|
25
|
+
*
|
|
26
|
+
* Percent-encoded rather than base64 so the `data-ptx-missing` marker stays
|
|
27
|
+
* greppable in the emitted page (see the module comment), and so the payload
|
|
28
|
+
* stays readable when someone views source. Only the characters that would
|
|
29
|
+
* break a URI or an HTML attribute are escaped.
|
|
30
|
+
*/
|
|
31
|
+
export declare function missingAssetPlaceholder(kind: AssetKind, relPath: string): string;
|
package/dist/publication.d.ts
CHANGED
|
@@ -8,9 +8,44 @@
|
|
|
8
8
|
* variables can only come from a publication file — there is no stringparam
|
|
9
9
|
* for `portable` — so we rewrite the user's publication file (or synthesize a
|
|
10
10
|
* minimal one) and serve it through the fetch shim as a virtual file.
|
|
11
|
+
*
|
|
12
|
+
* That rewrite is also how an embedder's default HTML theme gets in
|
|
13
|
+
* (`<html><css theme="..."/></html>`): same reason, no stringparam for it
|
|
14
|
+
* either, short of `debug.html.theme-name`.
|
|
11
15
|
*/
|
|
12
16
|
/**
|
|
13
17
|
* Return publication-file XML with `<html><platform portable="yes"/></html>`
|
|
14
18
|
* forced, preserving everything else from `publicationXml` when given.
|
|
19
|
+
*
|
|
20
|
+
* `cssTheme`, when given, supplies `<html><css theme="..."/></html>` for
|
|
21
|
+
* projects that do not choose an HTML theme themselves; see
|
|
22
|
+
* `RenderOptions.cssTheme`. A blank value is ignored.
|
|
23
|
+
*/
|
|
24
|
+
export declare function forcePortablePublication(publicationXml?: string, cssTheme?: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Where a project's images live, as declared by
|
|
27
|
+
* `<source><directories external generated/></source>`.
|
|
28
|
+
*
|
|
29
|
+
* Both paths are relative to the directory of the *main* source file — the one
|
|
30
|
+
* holding `<pretext>` — not to whichever file is being rendered. See
|
|
31
|
+
* RenderOptions.mainSourcePath.
|
|
32
|
+
*/
|
|
33
|
+
export interface AssetDirectories {
|
|
34
|
+
/** e.g. "../assets/" — trailing slash, relative to the main source dir. */
|
|
35
|
+
external?: string;
|
|
36
|
+
/** e.g. "../generated-assets/" — likewise. */
|
|
37
|
+
generated?: string;
|
|
38
|
+
/**
|
|
39
|
+
* True when the publication declares both attributes ("managed
|
|
40
|
+
* directories"). Only then does PreTeXt emit asset URLs under the fixed
|
|
41
|
+
* `external/` and `generated/` prefixes that {@link rewriteAssetUrls} keys
|
|
42
|
+
* on; legacy projects emit bare or `images/`-prefixed paths that cannot be
|
|
43
|
+
* told apart from anything else, so the preview leaves them alone.
|
|
44
|
+
*/
|
|
45
|
+
managed: boolean;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Read the asset directories from a publication file, falling back to the
|
|
49
|
+
* defaults baked into MINIMAL_PUBLICATION when none is supplied.
|
|
15
50
|
*/
|
|
16
|
-
export declare function
|
|
51
|
+
export declare function readAssetDirectories(publicationXml?: string): AssetDirectories;
|
package/dist/renderer.d.ts
CHANGED
|
@@ -3,6 +3,19 @@ import { PreviewTheme } from './theme.js';
|
|
|
3
3
|
export interface RenderOptions {
|
|
4
4
|
/** Path to the root PreTeXt source file (typically source/main.ptx). */
|
|
5
5
|
sourcePath: string;
|
|
6
|
+
/**
|
|
7
|
+
* Path to the project's *main* source file — the one holding `<pretext>`.
|
|
8
|
+
* Defaults to `sourcePath`, which is correct whenever a complete document is
|
|
9
|
+
* being rendered.
|
|
10
|
+
*
|
|
11
|
+
* PreTeXt anchors the publication file's relative asset directories
|
|
12
|
+
* (`source/directories/@external|@generated`) at this file's directory, and
|
|
13
|
+
* so does every `document()` the stylesheets make. Rendering a fragment from
|
|
14
|
+
* a subdirectory therefore needs it: previewing `source/chapters/ch1.ptx`
|
|
15
|
+
* must still resolve `../generated-assets/` from `source/`, not from
|
|
16
|
+
* `source/chapters/`. Without it, generated images silently render empty.
|
|
17
|
+
*/
|
|
18
|
+
mainSourcePath?: string;
|
|
6
19
|
/**
|
|
7
20
|
* Source text to transform instead of reading `sourcePath` from disk.
|
|
8
21
|
* `sourcePath` is still used to resolve relative xi:includes. Lets callers
|
|
@@ -22,6 +35,26 @@ export interface RenderOptions {
|
|
|
22
35
|
* `<html><platform portable="yes"/></html>`, which the preview forces.
|
|
23
36
|
*/
|
|
24
37
|
publicationPath?: string;
|
|
38
|
+
/**
|
|
39
|
+
* PreTeXt HTML theme to fall back on, inserted into the publication file
|
|
40
|
+
* used for the build as `<html><css theme="..."/></html>`.
|
|
41
|
+
*
|
|
42
|
+
* A default, not an override: it applies only when the project's own
|
|
43
|
+
* publication file names no theme (neither `@theme` nor the deprecated
|
|
44
|
+
* `@style`/`@shell`), so a project that has chosen one keeps it. Blank is
|
|
45
|
+
* ignored, and with no publication file at all it themes the synthesized
|
|
46
|
+
* minimal one.
|
|
47
|
+
*
|
|
48
|
+
* Portable builds load `theme-<name>.min.css` from the CDN, so an
|
|
49
|
+
* unrecognised name renders an unstyled page. The themes the vendored
|
|
50
|
+
* stylesheets know are default-modern (PreTeXt's own default), denver,
|
|
51
|
+
* tacoma, salem, greeley and boulder; `custom` additionally needs a locally
|
|
52
|
+
* compiled stylesheet, which this renderer cannot produce.
|
|
53
|
+
*
|
|
54
|
+
* Distinct from {@link RenderOptions.theme}, which is the light/dark mode
|
|
55
|
+
* *within* whichever css theme is in force.
|
|
56
|
+
*/
|
|
57
|
+
cssTheme?: string;
|
|
25
58
|
/** Additional XSLT string parameters, passed as strings (quoted for you). */
|
|
26
59
|
stringParams?: Record<string, string>;
|
|
27
60
|
/** Directory of PreTeXt XSL stylesheets. Defaults to the vendored copy. */
|
|
@@ -77,6 +110,19 @@ export interface RenderResult {
|
|
|
77
110
|
html: string;
|
|
78
111
|
/** Present when RenderOptions.sourceMap was set. */
|
|
79
112
|
sourceMap?: PtxSourceMap;
|
|
113
|
+
/**
|
|
114
|
+
* Absolute directories that the `external/` and `generated/` URL prefixes in
|
|
115
|
+
* `html` refer to, resolved from the publication file against the main
|
|
116
|
+
* source file's directory. Feed these to `rewriteAssetUrls` to point the
|
|
117
|
+
* page at assets the host can actually serve (see assets.ts).
|
|
118
|
+
*
|
|
119
|
+
* Absent for legacy projects that declare neither directory: those emit bare
|
|
120
|
+
* or `images/`-prefixed URLs that cannot be identified reliably.
|
|
121
|
+
*/
|
|
122
|
+
assetDirs?: {
|
|
123
|
+
external: string;
|
|
124
|
+
generated: string;
|
|
125
|
+
};
|
|
80
126
|
}
|
|
81
127
|
/**
|
|
82
128
|
* Vendored stylesheets shipped with this package. A directory under Node, a
|
|
@@ -93,5 +139,8 @@ export declare function xpathStringLiteral(value: string): string;
|
|
|
93
139
|
* per-section rendering: roughly 100ms for a small article, a few seconds for
|
|
94
140
|
* a 150-section book. Generated assets (latex-image, sageplot, …) are not
|
|
95
141
|
* produced — those require the Python toolchain.
|
|
142
|
+
*
|
|
143
|
+
* Concurrent calls are safe but not parallel: they queue and run one at a
|
|
144
|
+
* time (see {@link renderQueue}).
|
|
96
145
|
*/
|
|
97
146
|
export declare function renderHtml(options: RenderOptions): Promise<RenderResult>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pretextbook/pretext-html",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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",
|
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
"*": {
|
|
21
21
|
"theme": [
|
|
22
22
|
"./dist/theme.d.ts"
|
|
23
|
+
],
|
|
24
|
+
"assets": [
|
|
25
|
+
"./dist/assets.d.ts"
|
|
23
26
|
]
|
|
24
27
|
}
|
|
25
28
|
},
|
|
@@ -41,6 +44,11 @@
|
|
|
41
44
|
"import": "./dist/theme.js",
|
|
42
45
|
"default": "./dist/theme.js"
|
|
43
46
|
},
|
|
47
|
+
"./assets": {
|
|
48
|
+
"types": "./dist/assets.d.ts",
|
|
49
|
+
"import": "./dist/assets.js",
|
|
50
|
+
"default": "./dist/assets.js"
|
|
51
|
+
},
|
|
44
52
|
"./cli": "./dist/cli.js"
|
|
45
53
|
},
|
|
46
54
|
"sideEffects": false,
|