@pretextbook/pretext-html 0.18.0 → 0.18.1

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "source": {
3
3
  "repository": "PreTeXtBook/pretext",
4
- "ref": "ee0a7e135e3346f0b0c6192822d6942424cb4af0"
4
+ "ref": "da193419f0746242287b2358094a496029ca9671"
5
5
  },
6
- "refreshed": "2026-10-01T06:28:22.049Z"
6
+ "refreshed": "2026-10-24T03:13:47.656Z"
7
7
  }
@@ -0,0 +1,34 @@
1
+ <!--********************************************************************
2
+ Copyright (C) 2026 Robert A. Beezer
3
+
4
+ This file is part of PreTeXt.
5
+
6
+ PreTeXt is free software: you can redistribute it and/or modify
7
+ it under the terms of the GNU General Public License as published by
8
+ the Free Software Foundation, either version 2 or version 3 of the
9
+ License (at your option).
10
+
11
+ PreTeXt is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU General Public License for more details.
15
+
16
+ You should have received a copy of the GNU General Public License
17
+ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
18
+ *****************************************************************-->
19
+
20
+ # Stylesheets
21
+
22
+ - Use Extensible Stylesheet Language Transformations (XSLT) 1.0 with Extensions to XSLT (EXSLT) only. Declare each EXSLT namespace you use, and list its prefix in `extension-element-prefixes` whether you use its extension elements, such as `exsl:document`, or only its functions: a prefix that is declared but not listed is copied onto literal result elements as a namespace declaration (`pretext-common.xsl` declares and lists `exsl`, `date`, `str`, and `dyn`). libxslt is the reference processor, through `lxml` in `pretext/pretext`.
23
+ - PreTeXt entry stylesheets load `entities.ent` as an external parameter entity in a `DOCTYPE` (document type declaration). Add shared `-LIKE` and `-FILTER` unions there; its comments identify lists that mirror the schema or require a Guide update.
24
+ - Project stylesheets import one format entry point, and every entry point reaches `pretext-common.xsl` through its imports. `pretext-html.xsl` directly imports `publisher-variables.xsl`, `pretext-assembly.xsl`, and `pretext-common.xsl`; publisher variables and assembly are designed to travel together. Treat `-common` stylesheets as libraries rather than entry points.
25
+ - Obtain the identification value of an element by applying `mode="unique-id"` to it, never by reading the attribute that holds it; the template in `pretext-common.xsl` is the one place that knows how the value is stored. `mode="assembly-id"` yields a different value, which belongs to `pretext-assembly.xsl` and the `extract-*.xsl` stylesheets that feed it. A conversion never reads that one: the two values agree for most elements but not for all.
26
+ - Do not put a `priority` attribute on a template when a more specific match pattern, a mode, or import precedence will settle which template applies. Where nothing else will, a comment beside the template gives the reason.
27
+ - Prefix internal logic defects with `PTX:BUG:`. Use `PTX:WARNING:`, `PTX:ERROR:`, and `PTX:FATAL:` according to the [coding chapter](../doc/guide/developer/coding.xml).
28
+ - A message that an author will read describes the outcome and does not name the `pretext/pretext` script, since the PreTeXt command-line interface (CLI) can do the same work. A comment may name the script freely.
29
+ - Write a comment of several lines as single-line comments, one `<!-- ... -->` per line, with every closing `-->` in the same column.
30
+ - A publisher option change pairs the implementing stylesheet with `../schema/publication-schema.xml`, regenerated schemas, a Guide entry, and an example. A theme option also updates `html-theme-option-list` in `publisher-variables.xsl`.
31
+ - Follow the [localization contract](localizations/README.md): add new string identifiers to `en-US.xml`, and register each new language file in `localizations.xml`. Verify localization changes manually.
32
+ - Follow the [support-file procedure](support/README.md) when updating Runestone Services versions.
33
+ - Copy the copyright header from a sibling onto every new `.xsl` file.
34
+ - Run `(cd tests && xsltproc pretext-text-utilities-test.xsl null.xml)`. Add tests there for new low-level text utilities.
@@ -183,9 +183,11 @@
183
183
  <!ENTITY SOLUTION-LIKE "hint|answer|solution">
184
184
  <!ENTITY SOLUTION-FILTER "self::hint or self::answer or self::solution">
185
185
 
186
- <!-- appendages of OPENPROBLEM-LIKE -->
187
- <!ENTITY DISCUSSION-LIKE "context|discussion|opinion|status|suggestion">
188
- <!ENTITY DISCUSSION-FILTER "self::context or self::discussion or self::opinion or self::status or self::suggestion">
186
+ <!-- appendages of OPENPROBLEM-LIKE -->
187
+ <!-- A "status" is also a field of a bibliographic entry, so this one -->
188
+ <!-- is recognized by its parent: an OPENPROBLEM-LIKE, or one's "task" -->
189
+ <!ENTITY DISCUSSION-LIKE "context|discussion|opinion|status[parent::*[&OPENPROBLEM-FILTER;] or parent::task]|suggestion">
190
+ <!ENTITY DISCUSSION-FILTER "self::context or self::discussion or self::opinion or (self::status and (parent::*[&OPENPROBLEM-FILTER;] or parent::task)) or self::suggestion">
189
191
 
190
192
  <!-- Elements the schema gives text-only content: no PreTeXt markup is -->
191
193
  <!-- permitted inside them, whether because they are verbatim (code, a -->
@@ -19,15 +19,17 @@ You should have received a copy of the GNU General Public License
19
19
  along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
20
20
  *********************************************************************-->
21
21
 
22
- <!-- This stylesheet locates video/@youtube elements and -->
23
- <!-- prepares a Python dictionary necessary to extract a -->
24
- <!-- thumbnail for each video from the YouTube servers -->
22
+ <!-- This stylesheet locates the "biblio" of a back matter -->
23
+ <!-- "references", and the "xref" that cite them, and writes -->
24
+ <!-- the first as CSL-JSON and the second as lists of targets, -->
25
+ <!-- which a CSL processor needs to format both -->
25
26
 
26
27
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
27
28
  xmlns:xml="http://www.w3.org/XML/1998/namespace"
28
29
  xmlns:pi="http://pretextbook.org/2020/pretext/internal"
30
+ xmlns:exsl="http://exslt.org/common"
29
31
  xmlns:str="http://exslt.org/strings"
30
- exclude-result-prefixes="str"
32
+ exclude-result-prefixes="exsl str"
31
33
  >
32
34
  <!-- exclude-result-prefixes="pi" -->
33
35
 
@@ -103,12 +105,9 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
103
105
  <xsl:message>PTX:BUG: PreTeXt "biblio" markup using a "<xsl:value-of select="local-name()"/>" element is not implemented</xsl:message>
104
106
  </xsl:template>
105
107
 
106
- <!-- Gross JSON array structure, duplicate an ID for the division -->
108
+ <!-- Gross JSON array structure -->
107
109
  <xsl:template match="backmatter/references" mode="biblio-to-json">
108
110
  <xsl:element name="biblio-csl" namespace="http://pretextbook.org/2020/pretext/internal">
109
- <xsl:attribute name="biblio-id">
110
- <xsl:apply-templates select="." mode="assembly-id"/>
111
- </xsl:attribute>
112
111
  <xsl:text>[&#xa;</xsl:text>
113
112
  <xsl:apply-templates select="biblio" mode="biblio-to-json"/>
114
113
  <xsl:text>&#xa;]</xsl:text>
@@ -119,9 +118,11 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
119
118
  <!-- TODO: refine "select" to only match to-level possibilities -->
120
119
  <xsl:template match="biblio" mode="biblio-to-json">
121
120
  <xsl:text>{&#xa;</xsl:text>
122
- <xsl:apply-templates select="@xml:id|@type" mode="biblio-to-json"/>
123
- <xsl:apply-templates select="*" mode="biblio-to-json"/>
124
- <xsl:text>&#xa;}</xsl:text>
121
+ <xsl:call-template name="json-members">
122
+ <xsl:with-param name="nodes" select="@xml:id|@type|*"/>
123
+ <xsl:with-param name="separator" select="',&#xa;'"/>
124
+ </xsl:call-template>
125
+ <xsl:text>&#xa;}</xsl:text>
125
126
  <xsl:if test="following-sibling::biblio">
126
127
  <xsl:text>,&#xa;</xsl:text>
127
128
  <!-- intra-biblio visual formatting help -->
@@ -129,6 +130,37 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
129
130
  </xsl:if>
130
131
  </xsl:template>
131
132
 
133
+ <!-- The members of a JSON object are the conversions of "nodes", with -->
134
+ <!-- "separator" between one member and the next. A node that converts -->
135
+ <!-- to nothing (markup not implemented, caught above) is no member, so -->
136
+ <!-- the separators are right whichever nodes those are. Each template -->
137
+ <!-- for a member writes the member alone, and nothing after it. -->
138
+ <!-- TODO: "xml-to-json.xsl" converts a description of JSON, made of -->
139
+ <!-- elements, and supplies the separators and the quoting; built on -->
140
+ <!-- it, this template and the quoting in each template could go. -->
141
+ <xsl:template name="json-members">
142
+ <xsl:param name="nodes"/>
143
+ <xsl:param name="separator"/>
144
+ <xsl:variable name="members-rtf">
145
+ <xsl:for-each select="$nodes">
146
+ <xsl:variable name="json">
147
+ <xsl:apply-templates select="." mode="biblio-to-json"/>
148
+ </xsl:variable>
149
+ <xsl:if test="not($json = '')">
150
+ <member>
151
+ <xsl:value-of select="$json"/>
152
+ </member>
153
+ </xsl:if>
154
+ </xsl:for-each>
155
+ </xsl:variable>
156
+ <xsl:for-each select="exsl:node-set($members-rtf)/member">
157
+ <xsl:value-of select="."/>
158
+ <xsl:if test="not(position() = last())">
159
+ <xsl:value-of select="$separator"/>
160
+ </xsl:if>
161
+ </xsl:for-each>
162
+ </xsl:template>
163
+
132
164
  <!-- Attributes -->
133
165
  <!-- Happy accident that local-name(@xml:id) is JSON "id" key for CSL -->
134
166
 
@@ -151,15 +183,14 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
151
183
  <xsl:value-of select="."/>
152
184
  </xsl:with-param>
153
185
  </xsl:call-template>
154
- <xsl:text>",&#xa;</xsl:text>
186
+ <xsl:text>"</xsl:text>
155
187
  </xsl:template>
156
188
 
157
- <!-- Simple string fields to key/value pair -->
158
- <!-- NB: in the order presented in CSL-JSON schema, except as noted. -->
159
- <!-- NB: simple fields for parts of a name are later, and grouped together. -->
160
- <!-- NB: simple fields for alternate date model are at the end, and grouped together. -->
161
- <!-- TODO: many more, from "abstract" to "year-suffix", plus for names and dates. -->
162
- <xsl:template match="publisher|publisher-place|page|volume|title|collection-title|page-first|number-of-pages|URL|name/family|name/given|name/static-ordering|season|circa" mode="biblio-to-json">
189
+ <!-- Simple string fields to key/value pair -->
190
+ <!-- NB: in the order presented in CSL-JSON schema, except as noted. -->
191
+ <!-- NB: simple fields for parts of a name are later, and grouped together. -->
192
+ <!-- TODO: many more, from "abstract" to "year-suffix", plus for names and dates. -->
193
+ <xsl:template match="archive|archive_location|chapter-number|collection-number|collection-title|container-title|container-title-short|DOI|edition|event|genre|ISBN|ISSN|issue|number|number-of-pages|number-of-volumes|page|page-first|publisher|publisher-place|status|title|URL|version|volume|name/family|name/given|name/dropping-particle|name/non-dropping-particle|name/suffix|name/static-ordering|name/literal" mode="biblio-to-json">
163
194
  <xsl:text>"</xsl:text>
164
195
  <xsl:value-of select="local-name()"/>
165
196
  <xsl:text>"</xsl:text>
@@ -175,18 +206,6 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
175
206
  </xsl:with-param>
176
207
  </xsl:call-template>
177
208
  <xsl:text>"</xsl:text>
178
- <xsl:if test="following-sibling::*">
179
- <xsl:text>,</xsl:text>
180
- <xsl:choose>
181
- <!-- top-label get a newline, else a space -->
182
- <xsl:when test="parent::biblio">
183
- <xsl:text>&#xa;</xsl:text>
184
- </xsl:when>
185
- <xsl:otherwise>
186
- <xsl:text> </xsl:text>
187
- </xsl:otherwise>
188
- </xsl:choose>
189
- </xsl:if>
190
209
  </xsl:template>
191
210
 
192
211
  <!-- ############### -->
@@ -196,7 +215,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
196
215
  <!-- Structured name variables. -->
197
216
  <!-- TODO: see "$ref": "#/definitions/name-variable" in CSL-JSON -->
198
217
  <!-- schema to identify many more. "author" through "translator". -->
199
- <xsl:template match="biblio/author|biblio/editor" mode="biblio-to-json">
218
+ <xsl:template match="biblio/author|biblio/editor|biblio/translator" mode="biblio-to-json">
200
219
  <xsl:text>"</xsl:text>
201
220
  <xsl:value-of select="local-name()"/>
202
221
  <xsl:text>"</xsl:text>
@@ -204,9 +223,6 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
204
223
  <xsl:text>[</xsl:text>
205
224
  <xsl:apply-templates select="name" mode="biblio-to-json"/>
206
225
  <xsl:text>]</xsl:text>
207
- <xsl:if test="following-sibling::*">
208
- <xsl:text>,&#xa;</xsl:text>
209
- </xsl:if>
210
226
  </xsl:template>
211
227
 
212
228
  <!-- Name structure -->
@@ -216,7 +232,10 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
216
232
  <!-- family, given, suffix, etc. -->
217
233
  <!-- They will use the simple template above, where -->
218
234
  <!-- fields are qualified with the "name" parent -->
219
- <xsl:apply-templates select="*" mode="biblio-to-json"/>
235
+ <xsl:call-template name="json-members">
236
+ <xsl:with-param name="nodes" select="*"/>
237
+ <xsl:with-param name="separator" select="', '"/>
238
+ </xsl:call-template>
220
239
  <xsl:text>}</xsl:text>
221
240
  <xsl:if test="following-sibling::name">
222
241
  <xsl:text>, </xsl:text>
@@ -230,7 +249,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
230
249
  <!-- Structured date variables. -->
231
250
  <!-- TODO: see "$ref": "#/definitions/date-variable" in CSL-JSON -->
232
251
  <!-- schema to identify many more. "accessed" through "submitted". -->
233
- <xsl:template match="submitted|issued" mode="biblio-to-json">
252
+ <xsl:template match="accessed|issued" mode="biblio-to-json">
234
253
  <xsl:text>"</xsl:text>
235
254
  <xsl:value-of select="local-name()"/>
236
255
  <xsl:text>"</xsl:text>
@@ -244,18 +263,6 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
244
263
  <xsl:text>]</xsl:text>
245
264
  </xsl:if>
246
265
  <xsl:text>&#xa;}</xsl:text>
247
- <xsl:if test="following-sibling::*">
248
- <xsl:text>,</xsl:text>
249
- <xsl:choose>
250
- <!-- likely always first test? -->
251
- <xsl:when test="parent::biblio">
252
- <xsl:text>&#xa;</xsl:text>
253
- </xsl:when>
254
- <xsl:otherwise>
255
- <xsl:text> </xsl:text>
256
- </xsl:otherwise>
257
- </xsl:choose>
258
- </xsl:if>
259
266
  </xsl:template>
260
267
 
261
268
  <!-- An array of length 1 to 3, with spaces after commas -->