@pretextbook/pretext-html 0.2.0 → 0.3.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 +20 -0
- package/dist/assets.d.ts +43 -0
- package/dist/assets.js +76 -0
- package/dist/{cli-B2LiKunq.js → cli-CzoinNle.js} +264 -213
- package/dist/cli.js +1 -1
- package/dist/index.browser.js +343 -292
- 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 +27 -0
- package/dist/renderer.d.ts +29 -0
- package/package.json +9 -1
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-CzoinNle.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
|
@@ -14,3 +14,30 @@
|
|
|
14
14
|
* forced, preserving everything else from `publicationXml` when given.
|
|
15
15
|
*/
|
|
16
16
|
export declare function forcePortablePublication(publicationXml?: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Where a project's images live, as declared by
|
|
19
|
+
* `<source><directories external generated/></source>`.
|
|
20
|
+
*
|
|
21
|
+
* Both paths are relative to the directory of the *main* source file — the one
|
|
22
|
+
* holding `<pretext>` — not to whichever file is being rendered. See
|
|
23
|
+
* RenderOptions.mainSourcePath.
|
|
24
|
+
*/
|
|
25
|
+
export interface AssetDirectories {
|
|
26
|
+
/** e.g. "../assets/" — trailing slash, relative to the main source dir. */
|
|
27
|
+
external?: string;
|
|
28
|
+
/** e.g. "../generated-assets/" — likewise. */
|
|
29
|
+
generated?: string;
|
|
30
|
+
/**
|
|
31
|
+
* True when the publication declares both attributes ("managed
|
|
32
|
+
* directories"). Only then does PreTeXt emit asset URLs under the fixed
|
|
33
|
+
* `external/` and `generated/` prefixes that {@link rewriteAssetUrls} keys
|
|
34
|
+
* on; legacy projects emit bare or `images/`-prefixed paths that cannot be
|
|
35
|
+
* told apart from anything else, so the preview leaves them alone.
|
|
36
|
+
*/
|
|
37
|
+
managed: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Read the asset directories from a publication file, falling back to the
|
|
41
|
+
* defaults baked into MINIMAL_PUBLICATION when none is supplied.
|
|
42
|
+
*/
|
|
43
|
+
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
|
|
@@ -77,6 +90,19 @@ export interface RenderResult {
|
|
|
77
90
|
html: string;
|
|
78
91
|
/** Present when RenderOptions.sourceMap was set. */
|
|
79
92
|
sourceMap?: PtxSourceMap;
|
|
93
|
+
/**
|
|
94
|
+
* Absolute directories that the `external/` and `generated/` URL prefixes in
|
|
95
|
+
* `html` refer to, resolved from the publication file against the main
|
|
96
|
+
* source file's directory. Feed these to `rewriteAssetUrls` to point the
|
|
97
|
+
* page at assets the host can actually serve (see assets.ts).
|
|
98
|
+
*
|
|
99
|
+
* Absent for legacy projects that declare neither directory: those emit bare
|
|
100
|
+
* or `images/`-prefixed URLs that cannot be identified reliably.
|
|
101
|
+
*/
|
|
102
|
+
assetDirs?: {
|
|
103
|
+
external: string;
|
|
104
|
+
generated: string;
|
|
105
|
+
};
|
|
80
106
|
}
|
|
81
107
|
/**
|
|
82
108
|
* Vendored stylesheets shipped with this package. A directory under Node, a
|
|
@@ -93,5 +119,8 @@ export declare function xpathStringLiteral(value: string): string;
|
|
|
93
119
|
* per-section rendering: roughly 100ms for a small article, a few seconds for
|
|
94
120
|
* a 150-section book. Generated assets (latex-image, sageplot, …) are not
|
|
95
121
|
* produced — those require the Python toolchain.
|
|
122
|
+
*
|
|
123
|
+
* Concurrent calls are safe but not parallel: they queue and run one at a
|
|
124
|
+
* time (see {@link renderQueue}).
|
|
96
125
|
*/
|
|
97
126
|
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.3.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,
|