@pretextbook/pretext-html 0.16.1 → 0.17.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 +77 -3
- package/assets/preview-html.xsl +56 -0
- package/dist/cli-C0JwLhuv.js +1456 -0
- package/dist/cli.js +3 -3
- package/dist/index.browser.d.ts +9 -4
- package/dist/index.browser.js +1148 -838
- package/dist/index.d.ts +9 -3
- package/dist/index.js +50 -46
- package/dist/publication.d.ts +21 -0
- package/dist/renderer.d.ts +134 -13
- package/dist/skeleton.d.ts +68 -7
- package/dist/source-cache.d.ts +36 -0
- package/dist/sourcemap.d.ts +11 -1
- package/dist/subtree.d.ts +79 -0
- package/dist/xinclude.d.ts +40 -3
- package/package.json +1 -1
- package/dist/cli-DzlCZymu.js +0 -1145
package/README.md
CHANGED
|
@@ -91,6 +91,77 @@ const { html } = await renderHtml({
|
|
|
91
91
|
alone. Pass `openKnowls: false` (`--no-open-knowls` on the CLI) for the
|
|
92
92
|
collapsed reading experience of a real `pretext build`.
|
|
93
93
|
|
|
94
|
+
### Previewing one division of a large document
|
|
95
|
+
|
|
96
|
+
A render costs what PreTeXt's assembly costs, and that tracks the number of
|
|
97
|
+
elements in the document: a few hundred milliseconds for a chapter, tens of
|
|
98
|
+
seconds for a whole book. A live preview of a large document therefore should
|
|
99
|
+
not render the whole document, and need not: the `subtree` option renders one
|
|
100
|
+
division of it, numbered and cross-referenced exactly as the whole document
|
|
101
|
+
would number it, by pruning the rest to a skeleton (see `src/skeleton.ts`).
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
const { html, size, subtree } = await renderHtml({
|
|
105
|
+
sourcePath: "source/main.ptx",
|
|
106
|
+
subtree: {
|
|
107
|
+
line: cursorLine, // the division around the author's cursor...
|
|
108
|
+
file: cursorFile, // ...in this file (defaults to sourcePath)
|
|
109
|
+
level: 2, // chunk level: sections of a book are pages of their own
|
|
110
|
+
wholeDocumentUpTo: 3000, // but a small document previews whole
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
- `line`/`file` select the innermost division containing a source line; `id`
|
|
116
|
+
selects by `xml:id` instead (an element inside a division selects that
|
|
117
|
+
division). The division need not carry an `xml:id` of its own — the one
|
|
118
|
+
PreTeXt would stamp on it is injected, so the page's HTML ids are unchanged.
|
|
119
|
+
- A division that contains divisions is previewed as a **summary page**: its
|
|
120
|
+
own content (introduction, conclusion, loose paragraphs) rendered in place,
|
|
121
|
+
then links to the divisions inside it, as the chapter page of a chunked
|
|
122
|
+
build summarizes its sections. Only leaf divisions render in full, so a
|
|
123
|
+
cursor at the top of a book shows the book's front matter and a table of
|
|
124
|
+
its chapters, never the book. The summary links are inert on a one-page
|
|
125
|
+
preview but carry `data-ptx-division` (and `data-ptx-id` for a link to an
|
|
126
|
+
element), so a host can make them re-render with `subtree: { id }`.
|
|
127
|
+
- `level` has PreTeXt's chunk-level meaning, for a host that wants whole
|
|
128
|
+
pages at some depth: the preview is the page that would hold the selection
|
|
129
|
+
in a build chunked at that level. A selection deeper than `level` previews
|
|
130
|
+
its ancestor at `level`, whole; one at `level` is shown whole; one shallower
|
|
131
|
+
is the summary page above. Omit it to treat every division as a page of its
|
|
132
|
+
own.
|
|
133
|
+
- `wholeDocumentUpTo` renders the whole document instead when it has no more
|
|
134
|
+
than that many elements — a small document previews whole as fast as any
|
|
135
|
+
division of it would.
|
|
136
|
+
- Every result carries `size` (`elements`, `bytes`, and the `files` the
|
|
137
|
+
document spans, to watch for changes), and `subtree` (`id`, `level`,
|
|
138
|
+
`collapsed`) when one division was emitted rather than the whole document.
|
|
139
|
+
`measureDocument(options)` reports the same `size` without rendering, for a
|
|
140
|
+
host deciding how much to preview before each render.
|
|
141
|
+
- With `fragment: true` and a context document, `subtree` narrows the preview
|
|
142
|
+
within the placed fragment — a cursor line in a chapter file previews the
|
|
143
|
+
section it is in.
|
|
144
|
+
|
|
145
|
+
What a division preview still has to do on every render is read and parse the
|
|
146
|
+
whole document, to prune it. Two options keep that cheap:
|
|
147
|
+
|
|
148
|
+
- `readSource(path)` (or `files`, a map from absolute path to content) supplies
|
|
149
|
+
the document's files from memory — the xi:include targets, the context
|
|
150
|
+
document, the publication file — for a host that already holds its project
|
|
151
|
+
in memory (a browser editor) or has unsaved buffers (an editor). A reader
|
|
152
|
+
that returns `undefined` for a path falls through to the platform's own read.
|
|
153
|
+
- A per-file parse cache, on by default, reuses the parse of every file whose
|
|
154
|
+
content has not changed since the last render. It is keyed by file, not by
|
|
155
|
+
the assembled document, so it does not matter how the project is split into
|
|
156
|
+
files: a keystroke re-parses the file being edited and nothing else. Pass a
|
|
157
|
+
`SourceCache` of your own as `cache` to scope it (and `invalidate()` it), or
|
|
158
|
+
`cache: false` to parse afresh each time.
|
|
159
|
+
|
|
160
|
+
On a synthetic 12-chapter book of 28,000 elements split into 157 files, a
|
|
161
|
+
section or subsection preview takes well under a second warm (0.3–0.8s
|
|
162
|
+
measured, most of it the division itself), and a chapter's summary page about
|
|
163
|
+
the same, against 20–40 seconds for the whole book.
|
|
164
|
+
|
|
94
165
|
### API (browser)
|
|
95
166
|
|
|
96
167
|
The same renderer runs in a browser — no server, no Python. Bundlers pick it up
|
|
@@ -117,9 +188,12 @@ filesystem:
|
|
|
117
188
|
|
|
118
189
|
- **`sourceContent` is required.** `sourcePath` still anchors relative
|
|
119
190
|
`xi:include`s and the output's URLs, but nothing is read from it.
|
|
120
|
-
- **`xi:include`s are not resolved from disk.**
|
|
121
|
-
|
|
122
|
-
|
|
191
|
+
- **`xi:include`s are not resolved from disk.** Supply the project's files
|
|
192
|
+
through `readSource` or `files` (see above) and they are resolved from
|
|
193
|
+
there, with the per-file parse cache working as it does under Node; or
|
|
194
|
+
pre-merge them and pass the merged document as `sourceContent`. An
|
|
195
|
+
unresolvable include uses its `<xi:fallback>` if it has one, and otherwise
|
|
196
|
+
throws.
|
|
123
197
|
- **`publicationPath` / `docinfoSourcePath` need absolute URLs**, since those
|
|
124
198
|
are the only readable locations. Prefer `docinfo` (a string) over
|
|
125
199
|
`docinfoSourcePath`.
|
package/assets/preview-html.xsl
CHANGED
|
@@ -226,6 +226,62 @@
|
|
|
226
226
|
</xsl:choose>
|
|
227
227
|
</xsl:variable>
|
|
228
228
|
|
|
229
|
+
<!-- A subtree root one level above the chunk level is a summary page: its own -->
|
|
230
|
+
<!-- content, then links to the divisions inside it. Only that page is emitted; -->
|
|
231
|
+
<!-- the chunker is kept from also producing a page per child division. -->
|
|
232
|
+
<!-- See SUMMARY_PAGE_OVERRIDE in refresh-xsl.mjs. -->
|
|
233
|
+
<xsl:template match="*" mode="chunking">
|
|
234
|
+
<xsl:choose>
|
|
235
|
+
<xsl:when test="$b-subsetting and not(generate-id(.) = generate-id(id($subtree)))"/>
|
|
236
|
+
<xsl:otherwise>
|
|
237
|
+
<xsl:apply-imports/>
|
|
238
|
+
</xsl:otherwise>
|
|
239
|
+
</xsl:choose>
|
|
240
|
+
</xsl:template>
|
|
241
|
+
|
|
242
|
+
<xsl:template match="*" mode="intermediate">
|
|
243
|
+
<xsl:apply-templates select="." mode="file-wrap">
|
|
244
|
+
<xsl:with-param name="content">
|
|
245
|
+
<xsl:apply-templates select="." mode="debug-location"/>
|
|
246
|
+
<section class="{local-name(.)}">
|
|
247
|
+
<xsl:apply-templates select="." mode="html-id-attribute"/>
|
|
248
|
+
<xsl:apply-templates select="." mode="section-heading">
|
|
249
|
+
<xsl:with-param name="heading-level" select="$chunk-heading-level"/>
|
|
250
|
+
</xsl:apply-templates>
|
|
251
|
+
<xsl:apply-templates select="." mode="author-byline"/>
|
|
252
|
+
<xsl:if test="self::frontmatter[not(titlepage)]">
|
|
253
|
+
<xsl:call-template name="frontmatter-title"/>
|
|
254
|
+
</xsl:if>
|
|
255
|
+
<!-- The division's own content, in place -->
|
|
256
|
+
<xsl:for-each select="*">
|
|
257
|
+
<xsl:variable name="structural">
|
|
258
|
+
<xsl:apply-templates select="." mode="is-structural"/>
|
|
259
|
+
</xsl:variable>
|
|
260
|
+
<xsl:if test="not($structural = 'true')">
|
|
261
|
+
<xsl:apply-templates select=".">
|
|
262
|
+
<xsl:with-param name="heading-level" select="$chunk-heading-level + 1"/>
|
|
263
|
+
</xsl:apply-templates>
|
|
264
|
+
</xsl:if>
|
|
265
|
+
</xsl:for-each>
|
|
266
|
+
<!-- Then the divisions inside it, as upstream's summary links -->
|
|
267
|
+
<nav class="summary-links">
|
|
268
|
+
<ul>
|
|
269
|
+
<xsl:for-each select="*">
|
|
270
|
+
<xsl:variable name="structural">
|
|
271
|
+
<xsl:apply-templates select="." mode="is-structural"/>
|
|
272
|
+
</xsl:variable>
|
|
273
|
+
<xsl:if test="$structural = 'true'">
|
|
274
|
+
<xsl:apply-templates select="." mode="summary-nav"/>
|
|
275
|
+
</xsl:if>
|
|
276
|
+
</xsl:for-each>
|
|
277
|
+
</ul>
|
|
278
|
+
</nav>
|
|
279
|
+
<xsl:apply-templates select="." mode="permalink"/>
|
|
280
|
+
</section>
|
|
281
|
+
</xsl:with-param>
|
|
282
|
+
</xsl:apply-templates>
|
|
283
|
+
</xsl:template>
|
|
284
|
+
|
|
229
285
|
<!-- Show the print-preview button on printouts, but inert: the page it would -->
|
|
230
286
|
<!-- reload with "?printpreview=<id>" does not exist for an in-memory render, -->
|
|
231
287
|
<!-- and a host that resolves that query against its own URL sends the reader -->
|