@pretextbook/pretext-html 0.1.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 +160 -0
- package/assets/preview-html.xsl +230 -0
- package/assets/upstream.json +7 -0
- package/assets/xsl/README.md +31 -0
- package/assets/xsl/entities.ent +154 -0
- package/assets/xsl/extract-asymptote.xsl +68 -0
- package/assets/xsl/extract-biblio-csl.xsl +327 -0
- package/assets/xsl/extract-datafile.xsl +71 -0
- package/assets/xsl/extract-dynamic.xsl +139 -0
- package/assets/xsl/extract-identity.xsl +136 -0
- package/assets/xsl/extract-interactive.xsl +81 -0
- package/assets/xsl/extract-latex-image.xsl +118 -0
- package/assets/xsl/extract-mermaid.xsl +58 -0
- package/assets/xsl/extract-mom.xsl +63 -0
- package/assets/xsl/extract-pg.xsl +2897 -0
- package/assets/xsl/extract-prefigure.xsl +157 -0
- package/assets/xsl/extract-qrcode.xsl +100 -0
- package/assets/xsl/extract-runestone-page-template.xsl +139 -0
- package/assets/xsl/extract-sageplot.xsl +166 -0
- package/assets/xsl/extract-stack.xsl +56 -0
- package/assets/xsl/extract-trace.xsl +134 -0
- package/assets/xsl/extract-youtube.xsl +63 -0
- package/assets/xsl/html-symbols.xsl +3344 -0
- package/assets/xsl/latex/pretext-latex-AIM.xsl +56 -0
- package/assets/xsl/latex/pretext-latex-CLP.xsl +148 -0
- package/assets/xsl/latex/pretext-latex-chaos.xsl +317 -0
- package/assets/xsl/latex/pretext-latex-dyslexic-font.xsl +76 -0
- package/assets/xsl/latex/pretext-latex-guide.xsl +104 -0
- package/assets/xsl/latex/pretext-latex-texstyle.xsl +862 -0
- package/assets/xsl/localizations/README.md +56 -0
- package/assets/xsl/localizations/af-ZA.xml +276 -0
- package/assets/xsl/localizations/bg-BG.xml +276 -0
- package/assets/xsl/localizations/ca-ES.xml +285 -0
- package/assets/xsl/localizations/cs-CZ.xml +280 -0
- package/assets/xsl/localizations/de-DE.xml +281 -0
- package/assets/xsl/localizations/en-US.xml +427 -0
- package/assets/xsl/localizations/es-ES.xml +287 -0
- package/assets/xsl/localizations/fi-FI.xml +275 -0
- package/assets/xsl/localizations/fr-CA.xml +276 -0
- package/assets/xsl/localizations/fr-FR.xml +280 -0
- package/assets/xsl/localizations/hu-HU.xml +280 -0
- package/assets/xsl/localizations/it-IT.xml +276 -0
- package/assets/xsl/localizations/ku-CKB.xml +275 -0
- package/assets/xsl/localizations/localizations.xml +48 -0
- package/assets/xsl/localizations/nl-NL.xml +275 -0
- package/assets/xsl/localizations/pt-BR.xml +288 -0
- package/assets/xsl/localizations/pt-PT.xml +292 -0
- package/assets/xsl/localizations/zh-HANS.xml +269 -0
- package/assets/xsl/pretext-assembly.xsl +4795 -0
- package/assets/xsl/pretext-basic-html.xsl +86 -0
- package/assets/xsl/pretext-beamer.xsl +662 -0
- package/assets/xsl/pretext-braille-preprint.xsl +2249 -0
- package/assets/xsl/pretext-common.xsl +12018 -0
- package/assets/xsl/pretext-dynamic.xsl +65 -0
- package/assets/xsl/pretext-epub.xsl +1483 -0
- package/assets/xsl/pretext-fo.xsl +4593 -0
- package/assets/xsl/pretext-html.xsl +14791 -0
- package/assets/xsl/pretext-json-manifest.xsl +150 -0
- package/assets/xsl/pretext-jupyter.xsl +868 -0
- package/assets/xsl/pretext-latex-classic.xsl +952 -0
- package/assets/xsl/pretext-latex-common.xsl +11563 -0
- package/assets/xsl/pretext-latex.xsl +47 -0
- package/assets/xsl/pretext-litprog.xsl +105 -0
- package/assets/xsl/pretext-merge.xsl +41 -0
- package/assets/xsl/pretext-numbers.xsl +875 -0
- package/assets/xsl/pretext-revealjs.xsl +522 -0
- package/assets/xsl/pretext-runestone-fitb.xsl +1233 -0
- package/assets/xsl/pretext-runestone-static.xsl +1438 -0
- package/assets/xsl/pretext-runestone.xsl +3083 -0
- package/assets/xsl/pretext-sage-doctest.xsl +289 -0
- package/assets/xsl/pretext-smc.xsl +492 -0
- package/assets/xsl/pretext-solution-manual-latex.xsl +323 -0
- package/assets/xsl/pretext-text-utilities.xsl +1217 -0
- package/assets/xsl/pretext-text.xsl +392 -0
- package/assets/xsl/pretext-units.xsl +195 -0
- package/assets/xsl/pretext-view-source.xsl +157 -0
- package/assets/xsl/pretext-ww-problem-sets.xsl +391 -0
- package/assets/xsl/publisher-variables.xsl +4756 -0
- package/assets/xsl/support/README.md +22 -0
- package/assets/xsl/support/extract-math.xsl +256 -0
- package/assets/xsl/support/package-math.xsl +141 -0
- package/assets/xsl/support/play-button/README.md +46 -0
- package/assets/xsl/support/play-button/play-button.png +0 -0
- package/assets/xsl/support/play-button/play-button.svg +3 -0
- package/assets/xsl/support/pretext-pg-macros.xsl +110 -0
- package/assets/xsl/support/webpack_static_imports.xml +14 -0
- package/assets/xsl/tests/README.md +24 -0
- package/assets/xsl/tests/null.xml +4 -0
- package/assets/xsl/tests/pretext-text-utilities-test.xsl +334 -0
- package/assets/xsl/utilities/README.md +31 -0
- package/assets/xsl/utilities/author-report.xsl +107 -0
- package/assets/xsl/utilities/deprecate-autoname.sed +18 -0
- package/assets/xsl/utilities/deprecate-index.sed +33 -0
- package/assets/xsl/utilities/fix-deprecations.xsl +663 -0
- package/assets/xsl/utilities/pretext-enhanced-source.xsl +112 -0
- package/assets/xsl/utilities/report-publisher-variables.xsl +162 -0
- package/assets/xsl/xml-to-json.xsl +326 -0
- package/assets/xsl/xml-to-string.xsl +328 -0
- package/cli.mjs +29 -0
- package/dist/cli-C6tfAVvi.js +553 -0
- package/dist/cli.d.ts +10 -0
- package/dist/cli.js +7 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +10 -0
- package/dist/mounts.d.ts +23 -0
- package/dist/publication.d.ts +16 -0
- package/dist/renderer.d.ts +84 -0
- package/dist/sourcemap.d.ts +41 -0
- package/dist/xinclude.d.ts +45 -0
- package/package.json +52 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { PtxSourceMap } from './sourcemap.js';
|
|
2
|
+
export interface RenderOptions {
|
|
3
|
+
/** Path to the root PreTeXt source file (typically source/main.ptx). */
|
|
4
|
+
sourcePath: string;
|
|
5
|
+
/**
|
|
6
|
+
* Source text to transform instead of reading `sourcePath` from disk.
|
|
7
|
+
* `sourcePath` is still used to resolve relative xi:includes. Lets callers
|
|
8
|
+
* render unsaved editor content.
|
|
9
|
+
*/
|
|
10
|
+
sourceContent?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Directory served to the transform for xi:includes and relative
|
|
13
|
+
* references. Defaults to the directory containing `sourcePath`. Set it to
|
|
14
|
+
* the project root when the publication file or includes live outside the
|
|
15
|
+
* source directory. Files outside this directory are not readable by the
|
|
16
|
+
* transform.
|
|
17
|
+
*/
|
|
18
|
+
projectDir?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Path to a publication file. Its settings are respected except
|
|
21
|
+
* `<html><platform portable="yes"/></html>`, which the preview forces.
|
|
22
|
+
*/
|
|
23
|
+
publicationPath?: string;
|
|
24
|
+
/** Additional XSLT string parameters, passed as strings (quoted for you). */
|
|
25
|
+
stringParams?: Record<string, string>;
|
|
26
|
+
/** Directory of PreTeXt XSL stylesheets. Defaults to the vendored copy. */
|
|
27
|
+
xslDir?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Allow rendering a file that is not a complete PreTeXt document. After
|
|
30
|
+
* xi:includes are resolved, a fragment (a lone <section>, <chapter>, ...)
|
|
31
|
+
* is wrapped in a minimal complete document — <pretext><book> for
|
|
32
|
+
* <chapter>/<part> fragments, <pretext><article> otherwise — and built as
|
|
33
|
+
* normal. Numbering restarts at the fragment and cross-references leaving the
|
|
34
|
+
* fragment are unresolved; supply `docinfo` to restore the project's custom
|
|
35
|
+
* LaTeX macros and settings. Complete documents are unaffected.
|
|
36
|
+
*/
|
|
37
|
+
fragment?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* A `<docinfo>` element, as an XML string, to place inside the synthesized
|
|
40
|
+
* <pretext> wrapper (before the <article>/<book>) when a fragment is
|
|
41
|
+
* rendered. Lets a lone fragment keep the project's LaTeX macros, custom
|
|
42
|
+
* settings, etc., that live in the real main file's docinfo. Only used in
|
|
43
|
+
* fragment mode; complete documents carry their own docinfo and ignore this.
|
|
44
|
+
* Takes precedence over `docinfoSourcePath`.
|
|
45
|
+
*/
|
|
46
|
+
docinfo?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Path to a complete PreTeXt source file (typically the project's main.ptx)
|
|
49
|
+
* to lift the `<docinfo>` from for fragment mode, when `docinfo` is not
|
|
50
|
+
* given. The docinfo is resolved through xi:includes — both a top-level
|
|
51
|
+
* `<xi:include href="docinfo.ptx"/>` and includes nested inside docinfo —
|
|
52
|
+
* which is how most projects factor it out. Only the docinfo is read, not
|
|
53
|
+
* the book's chapters. Only used in fragment mode.
|
|
54
|
+
*/
|
|
55
|
+
docinfoSourcePath?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Also compute a source map: one entry per element, in document order,
|
|
58
|
+
* mapping the element's @unique-id (its HTML id, when the page emits one)
|
|
59
|
+
* to the file/line it was authored in — through xi:includes. Powers
|
|
60
|
+
* editor/preview sync; the rendered page itself is unchanged. See
|
|
61
|
+
* sourcemap.ts for the id contract with pretext-assembly.xsl.
|
|
62
|
+
*/
|
|
63
|
+
sourceMap?: boolean;
|
|
64
|
+
}
|
|
65
|
+
export interface RenderResult {
|
|
66
|
+
/** Complete standalone HTML page (CDN-hosted css/js/MathJax). */
|
|
67
|
+
html: string;
|
|
68
|
+
/** Present when RenderOptions.sourceMap was set. */
|
|
69
|
+
sourceMap?: PtxSourceMap;
|
|
70
|
+
}
|
|
71
|
+
/** Vendored stylesheets shipped with this package. */
|
|
72
|
+
export declare function defaultXslDir(): string;
|
|
73
|
+
export declare function isJspiAvailable(): boolean;
|
|
74
|
+
/** Quote a string as an XPath 1.0 string literal. */
|
|
75
|
+
export declare function xpathStringLiteral(value: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* Render a PreTeXt document to a single standalone HTML page.
|
|
78
|
+
*
|
|
79
|
+
* Every render pays PreTeXt's fixed assembly cost (~15 full-tree passes) plus
|
|
80
|
+
* per-section rendering: roughly 100ms for a small article, a few seconds for
|
|
81
|
+
* a 150-section book. Generated assets (latex-image, sageplot, …) are not
|
|
82
|
+
* produced — those require the Python toolchain.
|
|
83
|
+
*/
|
|
84
|
+
export declare function renderHtml(options: RenderOptions): Promise<RenderResult>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Root } from 'xast';
|
|
2
|
+
/** One element of the rendered document, in document order. */
|
|
3
|
+
export interface SourceMapEntry {
|
|
4
|
+
/** The element's @unique-id — its HTML id when the page emits one. */
|
|
5
|
+
id: string;
|
|
6
|
+
/** Absolute path of the source file the element was authored in. */
|
|
7
|
+
file: string;
|
|
8
|
+
/** 1-based start line of the element in `file`. */
|
|
9
|
+
line: number;
|
|
10
|
+
/** 1-based start column of the element in `file`. */
|
|
11
|
+
column: number;
|
|
12
|
+
/** 1-based line of the element's closing tag in `file`. */
|
|
13
|
+
endLine: number;
|
|
14
|
+
/**
|
|
15
|
+
* Id of the nearest mapped ancestor (or the synthesized wrapper's id in
|
|
16
|
+
* fragment mode). Lets clients fall back outward when an id does not
|
|
17
|
+
* appear in the rendered page (not every element gets an HTML id).
|
|
18
|
+
*/
|
|
19
|
+
parent?: string;
|
|
20
|
+
}
|
|
21
|
+
/** All entries for one rendered document, in document order. */
|
|
22
|
+
export type PtxSourceMap = SourceMapEntry[];
|
|
23
|
+
/**
|
|
24
|
+
* Compute the source map for an xinclude-merged tree (see resolveXIncludesToTree,
|
|
25
|
+
* whose spliced subtrees are tagged with their origin file). `rootFile` is the
|
|
26
|
+
* file the root element was authored in. `parentId`/`position` seat the walk
|
|
27
|
+
* below a synthesized wrapper in fragment mode: a fragment wrapped as
|
|
28
|
+
* <pretext><article><title/>… has wrapper ids root-1 / root-1-1, so its content
|
|
29
|
+
* starts at parentId "root-1-1", position 2 (after the empty <title/>).
|
|
30
|
+
*/
|
|
31
|
+
export declare function computeSourceMap(tree: Root, rootFile: string, options?: {
|
|
32
|
+
parentId?: string;
|
|
33
|
+
position?: number;
|
|
34
|
+
}): PtxSourceMap;
|
|
35
|
+
/**
|
|
36
|
+
* The entry to sync to for a cursor at `line`, given the entries of ONE file
|
|
37
|
+
* in document order (start lines are non-decreasing within a file): the last
|
|
38
|
+
* element starting at or before the line — the deepest/nearest element above
|
|
39
|
+
* the cursor. Falls back to the file's first entry for a cursor in the prolog.
|
|
40
|
+
*/
|
|
41
|
+
export declare function findSourceMapEntry(entries: PtxSourceMap, line: number): SourceMapEntry | undefined;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Element, Root } from 'xast';
|
|
2
|
+
/**
|
|
3
|
+
* Return `sourceContent` with every xi:include replaced by the contents of
|
|
4
|
+
* the referenced files. `sourcePath` anchors relative hrefs; `projectDir`
|
|
5
|
+
* bounds which files may be included.
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveXIncludes(sourceContent: string, sourcePath: string, projectDir: string): Promise<string>;
|
|
8
|
+
/** Result of resolveXIncludesToTree. */
|
|
9
|
+
export interface ResolvedTree {
|
|
10
|
+
/**
|
|
11
|
+
* The merged xast tree. Every node keeps the line/column position of its
|
|
12
|
+
* OWN source file's parse, and the root element of each spliced-in subtree
|
|
13
|
+
* is tagged with that file (see includedFileOf) — together, enough to map
|
|
14
|
+
* any element back to a file and line (see computeSourceMap).
|
|
15
|
+
*/
|
|
16
|
+
tree: Root;
|
|
17
|
+
/** The merged document serialized, as resolveXIncludes would return it. */
|
|
18
|
+
content: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Like resolveXIncludes, but also return the merged tree with per-file
|
|
22
|
+
* position attribution, for source-map computation.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveXIncludesToTree(sourceContent: string, sourcePath: string, projectDir: string): Promise<ResolvedTree>;
|
|
25
|
+
/**
|
|
26
|
+
* File a spliced-in element was parsed from, tagged by expandInclude.
|
|
27
|
+
* Undefined for nodes of the file being resolved (callers track that file
|
|
28
|
+
* themselves). Stored on the unist `data` field, which serializers ignore.
|
|
29
|
+
*/
|
|
30
|
+
export declare function includedFileOf(element: Element): string | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Extract the `<docinfo>` element from a complete PreTeXt source file as an XML
|
|
33
|
+
* string, resolving xi:includes along the way. Handles the two shapes authors
|
|
34
|
+
* actually write: a literal `<docinfo>` (whose children may themselves be
|
|
35
|
+
* xi:included — e.g. a factored-out macros file), and a top-level
|
|
36
|
+
* `<xi:include href="docinfo.ptx"/>` standing in for the whole docinfo.
|
|
37
|
+
*
|
|
38
|
+
* Only the docinfo is resolved: scanning stops at the document element
|
|
39
|
+
* (<book>/<article>/…), which `<docinfo>` must precede, so the book's chapter
|
|
40
|
+
* includes are never read. Best-effort — returns undefined when there is no
|
|
41
|
+
* docinfo, or if resolution fails (a fragment preview without the project
|
|
42
|
+
* macros beats a failed render). `mainPath` anchors relative hrefs;
|
|
43
|
+
* `projectDir` bounds which files may be read.
|
|
44
|
+
*/
|
|
45
|
+
export declare function extractDocinfo(mainContent: string, mainPath: string, projectDir: string): Promise<string | undefined>;
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pretextbook/pretext-html",
|
|
3
|
+
"version": "0.1.0",
|
|
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
|
+
"author": "Oscar Levin",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/PreTeXtBook/pretext-tools.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/PreTeXtBook/pretext-tools/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/PreTeXtBook/pretext-tools/packages/pretext-html#readme",
|
|
15
|
+
"private": false,
|
|
16
|
+
"type": "module",
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"bin": {
|
|
20
|
+
"pretext-html": "./cli.mjs"
|
|
21
|
+
},
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./cli": "./dist/cli.js"
|
|
29
|
+
},
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"assets",
|
|
34
|
+
"cli.mjs"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "vite build",
|
|
38
|
+
"test": "vitest run",
|
|
39
|
+
"refresh-xsl": "node scripts/refresh-xsl.mjs"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@pretextbook/libxslt-wasm": "^0.1.1",
|
|
43
|
+
"xast-util-from-xml": "^4.0.0",
|
|
44
|
+
"xast-util-to-xml": "^4.0.0"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=22"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
}
|
|
52
|
+
}
|