@pretextbook/pretext-html 0.1.0 → 0.1.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.
Files changed (111) hide show
  1. package/README.md +42 -3
  2. package/assets/preview-html.xsl +230 -230
  3. package/assets/upstream.json +7 -7
  4. package/assets/xsl/README.md +0 -0
  5. package/assets/xsl/entities.ent +154 -154
  6. package/assets/xsl/extract-asymptote.xsl +68 -68
  7. package/assets/xsl/extract-biblio-csl.xsl +327 -327
  8. package/assets/xsl/extract-datafile.xsl +71 -71
  9. package/assets/xsl/extract-dynamic.xsl +139 -139
  10. package/assets/xsl/extract-identity.xsl +136 -136
  11. package/assets/xsl/extract-interactive.xsl +81 -81
  12. package/assets/xsl/extract-latex-image.xsl +118 -118
  13. package/assets/xsl/extract-mermaid.xsl +58 -58
  14. package/assets/xsl/extract-mom.xsl +63 -63
  15. package/assets/xsl/extract-pg.xsl +2897 -2897
  16. package/assets/xsl/extract-prefigure.xsl +157 -157
  17. package/assets/xsl/extract-qrcode.xsl +100 -100
  18. package/assets/xsl/extract-runestone-page-template.xsl +139 -139
  19. package/assets/xsl/extract-sageplot.xsl +166 -166
  20. package/assets/xsl/extract-stack.xsl +56 -56
  21. package/assets/xsl/extract-trace.xsl +134 -134
  22. package/assets/xsl/extract-youtube.xsl +63 -63
  23. package/assets/xsl/html-symbols.xsl +3344 -3344
  24. package/assets/xsl/latex/pretext-latex-AIM.xsl +56 -56
  25. package/assets/xsl/latex/pretext-latex-CLP.xsl +148 -148
  26. package/assets/xsl/latex/pretext-latex-chaos.xsl +317 -317
  27. package/assets/xsl/latex/pretext-latex-dyslexic-font.xsl +76 -76
  28. package/assets/xsl/latex/pretext-latex-guide.xsl +104 -104
  29. package/assets/xsl/latex/pretext-latex-texstyle.xsl +862 -862
  30. package/assets/xsl/localizations/README.md +0 -0
  31. package/assets/xsl/localizations/af-ZA.xml +276 -276
  32. package/assets/xsl/localizations/bg-BG.xml +276 -276
  33. package/assets/xsl/localizations/ca-ES.xml +285 -285
  34. package/assets/xsl/localizations/cs-CZ.xml +280 -280
  35. package/assets/xsl/localizations/de-DE.xml +281 -281
  36. package/assets/xsl/localizations/en-US.xml +427 -427
  37. package/assets/xsl/localizations/es-ES.xml +287 -287
  38. package/assets/xsl/localizations/fi-FI.xml +275 -275
  39. package/assets/xsl/localizations/fr-CA.xml +276 -276
  40. package/assets/xsl/localizations/fr-FR.xml +280 -280
  41. package/assets/xsl/localizations/hu-HU.xml +280 -280
  42. package/assets/xsl/localizations/it-IT.xml +276 -276
  43. package/assets/xsl/localizations/ku-CKB.xml +275 -275
  44. package/assets/xsl/localizations/localizations.xml +48 -48
  45. package/assets/xsl/localizations/nl-NL.xml +275 -275
  46. package/assets/xsl/localizations/pt-BR.xml +288 -288
  47. package/assets/xsl/localizations/pt-PT.xml +292 -292
  48. package/assets/xsl/localizations/zh-HANS.xml +269 -269
  49. package/assets/xsl/pretext-assembly.xsl +4795 -4795
  50. package/assets/xsl/pretext-basic-html.xsl +86 -86
  51. package/assets/xsl/pretext-beamer.xsl +662 -662
  52. package/assets/xsl/pretext-braille-preprint.xsl +2249 -2249
  53. package/assets/xsl/pretext-common.xsl +12018 -12018
  54. package/assets/xsl/pretext-dynamic.xsl +65 -65
  55. package/assets/xsl/pretext-epub.xsl +1483 -1483
  56. package/assets/xsl/pretext-fo.xsl +4593 -4593
  57. package/assets/xsl/pretext-html.xsl +14791 -14791
  58. package/assets/xsl/pretext-json-manifest.xsl +150 -150
  59. package/assets/xsl/pretext-jupyter.xsl +868 -868
  60. package/assets/xsl/pretext-latex-classic.xsl +952 -952
  61. package/assets/xsl/pretext-latex-common.xsl +11563 -11563
  62. package/assets/xsl/pretext-latex.xsl +47 -47
  63. package/assets/xsl/pretext-litprog.xsl +105 -105
  64. package/assets/xsl/pretext-merge.xsl +41 -41
  65. package/assets/xsl/pretext-numbers.xsl +875 -875
  66. package/assets/xsl/pretext-revealjs.xsl +522 -522
  67. package/assets/xsl/pretext-runestone-fitb.xsl +1233 -1233
  68. package/assets/xsl/pretext-runestone-static.xsl +1438 -1438
  69. package/assets/xsl/pretext-runestone.xsl +3083 -3083
  70. package/assets/xsl/pretext-sage-doctest.xsl +289 -289
  71. package/assets/xsl/pretext-smc.xsl +492 -492
  72. package/assets/xsl/pretext-solution-manual-latex.xsl +323 -323
  73. package/assets/xsl/pretext-text-utilities.xsl +1217 -1217
  74. package/assets/xsl/pretext-text.xsl +392 -392
  75. package/assets/xsl/pretext-units.xsl +195 -195
  76. package/assets/xsl/pretext-view-source.xsl +157 -157
  77. package/assets/xsl/pretext-ww-problem-sets.xsl +391 -391
  78. package/assets/xsl/publisher-variables.xsl +4756 -4756
  79. package/assets/xsl/support/README.md +0 -0
  80. package/assets/xsl/support/extract-math.xsl +256 -256
  81. package/assets/xsl/support/package-math.xsl +141 -141
  82. package/assets/xsl/support/play-button/README.md +0 -0
  83. package/assets/xsl/support/play-button/play-button.png +0 -0
  84. package/assets/xsl/support/play-button/play-button.svg +3 -3
  85. package/assets/xsl/support/pretext-pg-macros.xsl +110 -110
  86. package/assets/xsl/support/webpack_static_imports.xml +14 -14
  87. package/assets/xsl/tests/README.md +0 -0
  88. package/assets/xsl/tests/null.xml +3 -3
  89. package/assets/xsl/tests/pretext-text-utilities-test.xsl +333 -333
  90. package/assets/xsl/utilities/README.md +0 -0
  91. package/assets/xsl/utilities/author-report.xsl +107 -107
  92. package/assets/xsl/utilities/deprecate-autoname.sed +18 -18
  93. package/assets/xsl/utilities/deprecate-index.sed +33 -33
  94. package/assets/xsl/utilities/fix-deprecations.xsl +663 -663
  95. package/assets/xsl/utilities/pretext-enhanced-source.xsl +112 -112
  96. package/assets/xsl/utilities/report-publisher-variables.xsl +162 -162
  97. package/assets/xsl/xml-to-json.xsl +326 -326
  98. package/assets/xsl/xml-to-string.xsl +328 -328
  99. package/dist/{cli-C6tfAVvi.js → cli-BQizBK0N.js} +74 -72
  100. package/dist/cli.d.ts +0 -0
  101. package/dist/cli.js +1 -1
  102. package/dist/index.d.ts +2 -0
  103. package/dist/index.js +12 -6
  104. package/dist/mounts.d.ts +0 -0
  105. package/dist/publication.d.ts +0 -0
  106. package/dist/renderer.d.ts +10 -0
  107. package/dist/sourcemap.d.ts +0 -0
  108. package/dist/theme.d.ts +68 -0
  109. package/dist/theme.js +93 -0
  110. package/dist/xinclude.d.ts +0 -0
  111. package/package.json +14 -2
@@ -1,327 +1,327 @@
1
- <?xml version='1.0'?>
2
-
3
- <!--********************************************************************
4
- Copyright 2014-2025 Robert A. Beezer
5
-
6
- This file is part of PreTeXt.
7
-
8
- PreTeXt is free software: you can redistribute it and/or modify
9
- it under the terms of the GNU General Public License as published by
10
- the Free Software Foundation, either version 2 or version 3 of the
11
- License (at your option).
12
-
13
- PreTeXt is distributed in the hope that it will be useful,
14
- but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
- GNU General Public License for more details.
17
-
18
- You should have received a copy of the GNU General Public License
19
- along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
20
- *********************************************************************-->
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 -->
25
-
26
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
27
- xmlns:xml="http://www.w3.org/XML/1998/namespace"
28
- xmlns:pi="http://pretextbook.org/2020/pretext/internal"
29
- xmlns:str="http://exslt.org/strings"
30
- exclude-result-prefixes="str"
31
- >
32
- <!-- exclude-result-prefixes="pi" -->
33
-
34
-
35
- <!-- Get internal ID's for filenames, etc -->
36
- <!-- Standard conversion groundwork -->
37
- <!-- Includes "escape-json-string" -->
38
- <xsl:import href="./publisher-variables.xsl"/>
39
- <xsl:import href="./pretext-assembly.xsl"/>
40
- <xsl:import href="./pretext-common.xsl"/>
41
-
42
- <!-- Get a "subtree" xml:id value -->
43
- <!-- Then walk the XML source tree -->
44
- <!-- applying specializations below -->
45
- <xsl:import href="./extract-identity.xsl" />
46
-
47
- <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
48
-
49
- <!-- In "normal" circumstances, this variable is -->
50
- <!-- set to "false()", but when employing this -->
51
- <!-- specialized stylesheet, we override to "true" -->
52
- <xsl:variable name="b-extracting-biblio" select="true()"/>
53
-
54
- <!-- We create a structured file of bibliographic and citation -->
55
- <!-- information from the document. Following is an outline of -->
56
- <!-- this structure, likely all in the "pi" (PreTeXt Internal) -->
57
- <!-- namespace. This is all subject to change, which may just -->
58
- <!-- be cosmetic changes. -->
59
- <!-- -->
60
- <!-- <pretext-biblio-csl> -->
61
- <!-- <biblio-csl> -->
62
- <!-- [JSON in CSL-JSON format, per "references"] -->
63
- <!-- </biblio-csl> -->
64
- <!-- <xref-csl> -->
65
- <!-- [list of ref pointing to biblio, per xref] -->
66
- <!-- </xref-csl> -->
67
- <!-- </pretext-biblio-csl> -->
68
-
69
- <xsl:template match="/">
70
- <!-- overall root container for this file -->
71
- <xsl:element name="pretext-biblio-csl" namespace="http://pretextbook.org/2020/pretext/internal">
72
- <!-- multiple "references" divisions, each with their own element -->
73
- <!-- only considering backmatter references now -->
74
- <xsl:apply-templates select="$document-root//backmatter/references" mode="biblio-to-json"/>
75
- <!-- Examine every "xref" looking for citations; -->
76
- <!-- a pointer, or pointers to "biblio". Record. -->
77
- <xsl:apply-templates select="$document-root//xref" mode="citations"/>
78
- </xsl:element>
79
- </xsl:template>
80
-
81
-
82
-
83
- <!-- The "biblio-to-json" template will convert a single "references" division (just the -->
84
- <!-- "backmatter" instance right now) into a single JSON structure in CSL-JSON/citeproc-JSON -->
85
- <!-- format. (Seems both names are in use, we will use the first.) -->
86
- <!-- Note that the names of PreTeXt elements will mimic the names of JSON fields, so we can -->
87
- <!-- use the "local-name()" function to have a single template cover multiple possibilities. -->
88
- <!-- -->
89
- <!-- Overview: -->
90
- <!-- https://citeproc-js.readthedocs.io/en/latest/csl-json/markup.html -->
91
- <!-- -->
92
- <!-- CSL-JSON/citeproc-JSON: -->
93
- <!-- https://github.com/citation-style-language/schema?tab=readme-ov-file#csl-json-schema -->
94
- <!-- https://github.com/citation-style-language/schema/blob/master/schemas/input/csl-data.json -->
95
- <!-- https://github.com/citation-style-language/schema/blob/master/schemas/input/csl-citation.json -->
96
-
97
- <!-- TODO: expand to multiple "references" divisions -->
98
-
99
- <!-- First, a catch-all version of the template to intercept un-implemented markup -->
100
- <!-- TODO: perhaps report content also, as a better assist, or the self/parent/ancestor biblio id -->
101
- <!-- TODO: refine to include un-implemented bits of "citeproc-py" (e/g static-ordering) -->
102
- <xsl:template match="*" mode="biblio-to-json">
103
- <xsl:message>BUG: PreTeXt "biblio" markup using a "<xsl:value-of select="local-name()"/>" element is not implemented</xsl:message>
104
- </xsl:template>
105
-
106
- <!-- Gross JSON array structure, duplicate an ID for the division -->
107
- <xsl:template match="backmatter/references" mode="biblio-to-json">
108
- <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
- <xsl:text>[&#xa;</xsl:text>
113
- <xsl:apply-templates select="biblio" mode="biblio-to-json"/>
114
- <xsl:text>&#xa;]</xsl:text>
115
- </xsl:element>
116
- </xsl:template>
117
-
118
- <!-- Convert each "biblio" to an object, assume PreTeXt markup is 100% structured. -->
119
- <!-- TODO: refine "select" to only match to-level possibilities -->
120
- <xsl:template match="biblio" mode="biblio-to-json">
121
- <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>
125
- <xsl:if test="following-sibling::biblio">
126
- <xsl:text>,&#xa;</xsl:text>
127
- <!-- intra-biblio visual formatting help -->
128
- <xsl:text>&#xa;</xsl:text>
129
- </xsl:if>
130
- </xsl:template>
131
-
132
- <!-- Attributes -->
133
- <!-- Happy accident that local-name(@xml:id) is JSON "id" key for CSL -->
134
-
135
- <!-- TODO: are the following attributes in PreTeXt markup? -->
136
- <!-- citation-key -->
137
- <!-- categories (an array. of?) -->
138
- <!-- language -->
139
- <!-- journalAbbreviation -->
140
- <!-- shortTitle -->
141
-
142
- <xsl:template match="@xml:id|@type" mode="biblio-to-json">
143
- <xsl:text>"</xsl:text>
144
- <xsl:value-of select="local-name()"/>
145
- <xsl:text>"</xsl:text>
146
- <xsl:text>: </xsl:text>
147
- <xsl:text>"</xsl:text>
148
- <!-- attribute value content -->
149
- <xsl:call-template name="escape-json-string">
150
- <xsl:with-param name="text">
151
- <xsl:value-of select="."/>
152
- </xsl:with-param>
153
- </xsl:call-template>
154
- <xsl:text>",&#xa;</xsl:text>
155
- </xsl:template>
156
-
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">
163
- <xsl:text>"</xsl:text>
164
- <xsl:value-of select="local-name()"/>
165
- <xsl:text>"</xsl:text>
166
- <!-- separator w/ space -->
167
- <xsl:text>: </xsl:text>
168
- <xsl:text>"</xsl:text>
169
- <!-- plain text content -->
170
- <!-- apply-templates for math in titles??? -->
171
- <xsl:call-template name="escape-json-string">
172
- <xsl:with-param name="text">
173
- <!-- convert to a textual representation -->
174
- <xsl:apply-templates select="node()" mode="xml-to-string"/>
175
- </xsl:with-param>
176
- </xsl:call-template>
177
- <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
- </xsl:template>
191
-
192
- <!-- ############### -->
193
- <!-- Name structures -->
194
- <!-- ############### -->
195
-
196
- <!-- Structured name variables. -->
197
- <!-- TODO: see "$ref": "#/definitions/name-variable" in CSL-JSON -->
198
- <!-- schema to identify many more. "author" through "translator". -->
199
- <xsl:template match="biblio/author|biblio/editor" mode="biblio-to-json">
200
- <xsl:text>"</xsl:text>
201
- <xsl:value-of select="local-name()"/>
202
- <xsl:text>"</xsl:text>
203
- <xsl:text>: </xsl:text>
204
- <xsl:text>[</xsl:text>
205
- <xsl:apply-templates select="name" mode="biblio-to-json"/>
206
- <xsl:text>]</xsl:text>
207
- <xsl:if test="following-sibling::*">
208
- <xsl:text>,&#xa;</xsl:text>
209
- </xsl:if>
210
- </xsl:template>
211
-
212
- <!-- Name structure -->
213
- <xsl:template match="biblio/*/name" mode="biblio-to-json">
214
- <xsl:text>{</xsl:text>
215
- <!-- Name content model includes simple fields like -->
216
- <!-- family, given, suffix, etc. -->
217
- <!-- They will use the simple template above, where -->
218
- <!-- fields are qualified with the "name" parent -->
219
- <xsl:apply-templates select="*" mode="biblio-to-json"/>
220
- <xsl:text>}</xsl:text>
221
- <xsl:if test="following-sibling::name">
222
- <xsl:text>, </xsl:text>
223
- </xsl:if>
224
- </xsl:template>
225
-
226
- <!-- ############### -->
227
- <!-- Date structures -->
228
- <!-- ############### -->
229
-
230
- <!-- Structured date variables. -->
231
- <!-- TODO: see "$ref": "#/definitions/date-variable" in CSL-JSON -->
232
- <!-- schema to identify many more. "accessed" through "submitted". -->
233
- <xsl:template match="submitted|issued" mode="biblio-to-json">
234
- <xsl:text>"</xsl:text>
235
- <xsl:value-of select="local-name()"/>
236
- <xsl:text>"</xsl:text>
237
- <xsl:text>: </xsl:text>
238
- <xsl:text>{&#xa;</xsl:text>
239
- <xsl:if test="date">
240
- <!-- Outer array structure, even if singleton -->
241
- <xsl:text>"date-parts": </xsl:text>
242
- <xsl:text>[</xsl:text>
243
- <xsl:apply-templates select="date" mode="biblio-to-json"/>
244
- <xsl:text>]</xsl:text>
245
- </xsl:if>
246
- <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
- </xsl:template>
260
-
261
- <!-- An array of length 1 to 3, with spaces after commas -->
262
- <xsl:template match="date" mode="biblio-to-json">
263
- <xsl:text>[</xsl:text>
264
- <xsl:if test="@year">
265
- <xsl:value-of select="@year"/>
266
- </xsl:if>
267
- <xsl:if test="@month">
268
- <xsl:text>, </xsl:text>
269
- <xsl:value-of select="@month"/>
270
- </xsl:if>
271
- <xsl:if test="@day">
272
- <xsl:text>, </xsl:text>
273
- <xsl:value-of select="@day"/>
274
- </xsl:if>
275
- <xsl:text>]</xsl:text>
276
- <xsl:if test="following-sibling::date">
277
- <xsl:text>, </xsl:text>
278
- </xsl:if>
279
- </xsl:template>
280
-
281
-
282
- <!-- ######### -->
283
- <!-- Citations -->
284
- <!-- ######### -->
285
-
286
- <xsl:template match="xref" mode="citations">
287
- <!-- xref/@ref may point to a (backmatter) "biblio" -->
288
- <!-- Or it may point to *several* "biblio" -->
289
- <!-- Allow commas or spaces for separators -->
290
- <!-- tokenize() has no root; a sequence of "token" -->
291
- <xsl:variable name="tokenized-biblio-ref" select="str:tokenize(@ref, ' ,')"/>
292
- <!-- list of @ref values that have been vetted -->
293
- <!-- preliminary, may be null, may have trailing space -->
294
- <xsl:variable name="citation-item-list-prelim">
295
- <xsl:for-each select="$tokenized-biblio-ref">
296
- <xsl:variable name="the-ref">
297
- <xsl:value-of select="."/>
298
- </xsl:variable>
299
- <!-- context switch so id() function works -->
300
- <xsl:for-each select="$original">
301
- <xsl:variable name="target" select="id($the-ref)"/>
302
- <!-- vet each @ref value, only backmatter is considered -->
303
- <xsl:if test="$target/self::biblio/parent::references/parent::backmatter">
304
- <xsl:value-of select="$the-ref"/>
305
- <xsl:text> </xsl:text>
306
- </xsl:if>
307
- </xsl:for-each>
308
- </xsl:for-each>
309
- </xsl:variable>
310
- <!-- normalizing will scrub final space, if non-empty -->
311
- <xsl:variable name="citation-item-list"
312
- select="normalize-space($citation-item-list-prelim)"/>
313
- <!-- the "xref" might be some other cross-reference -->
314
- <xsl:if test="not($citation-item-list = '')">
315
- <!-- only visual, for debugging, etc. -->
316
- <xsl:text>&#xa;</xsl:text>
317
- <xsl:element name="xref-csl" namespace="http://pretextbook.org/2020/pretext/internal">
318
- <!-- namespacing the attribute is sort of ugly -->
319
- <xsl:attribute name="id">
320
- <xsl:value-of select="@assembly-id"/>
321
- </xsl:attribute>
322
- <xsl:value-of select="$citation-item-list"/>
323
- </xsl:element>
324
- </xsl:if>
325
- </xsl:template>
326
-
327
- </xsl:stylesheet>
1
+ <?xml version='1.0'?>
2
+
3
+ <!--********************************************************************
4
+ Copyright 2014-2025 Robert A. Beezer
5
+
6
+ This file is part of PreTeXt.
7
+
8
+ PreTeXt is free software: you can redistribute it and/or modify
9
+ it under the terms of the GNU General Public License as published by
10
+ the Free Software Foundation, either version 2 or version 3 of the
11
+ License (at your option).
12
+
13
+ PreTeXt is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
20
+ *********************************************************************-->
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 -->
25
+
26
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
27
+ xmlns:xml="http://www.w3.org/XML/1998/namespace"
28
+ xmlns:pi="http://pretextbook.org/2020/pretext/internal"
29
+ xmlns:str="http://exslt.org/strings"
30
+ exclude-result-prefixes="str"
31
+ >
32
+ <!-- exclude-result-prefixes="pi" -->
33
+
34
+
35
+ <!-- Get internal ID's for filenames, etc -->
36
+ <!-- Standard conversion groundwork -->
37
+ <!-- Includes "escape-json-string" -->
38
+ <xsl:import href="./publisher-variables.xsl"/>
39
+ <xsl:import href="./pretext-assembly.xsl"/>
40
+ <xsl:import href="./pretext-common.xsl"/>
41
+
42
+ <!-- Get a "subtree" xml:id value -->
43
+ <!-- Then walk the XML source tree -->
44
+ <!-- applying specializations below -->
45
+ <xsl:import href="./extract-identity.xsl" />
46
+
47
+ <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
48
+
49
+ <!-- In "normal" circumstances, this variable is -->
50
+ <!-- set to "false()", but when employing this -->
51
+ <!-- specialized stylesheet, we override to "true" -->
52
+ <xsl:variable name="b-extracting-biblio" select="true()"/>
53
+
54
+ <!-- We create a structured file of bibliographic and citation -->
55
+ <!-- information from the document. Following is an outline of -->
56
+ <!-- this structure, likely all in the "pi" (PreTeXt Internal) -->
57
+ <!-- namespace. This is all subject to change, which may just -->
58
+ <!-- be cosmetic changes. -->
59
+ <!-- -->
60
+ <!-- <pretext-biblio-csl> -->
61
+ <!-- <biblio-csl> -->
62
+ <!-- [JSON in CSL-JSON format, per "references"] -->
63
+ <!-- </biblio-csl> -->
64
+ <!-- <xref-csl> -->
65
+ <!-- [list of ref pointing to biblio, per xref] -->
66
+ <!-- </xref-csl> -->
67
+ <!-- </pretext-biblio-csl> -->
68
+
69
+ <xsl:template match="/">
70
+ <!-- overall root container for this file -->
71
+ <xsl:element name="pretext-biblio-csl" namespace="http://pretextbook.org/2020/pretext/internal">
72
+ <!-- multiple "references" divisions, each with their own element -->
73
+ <!-- only considering backmatter references now -->
74
+ <xsl:apply-templates select="$document-root//backmatter/references" mode="biblio-to-json"/>
75
+ <!-- Examine every "xref" looking for citations; -->
76
+ <!-- a pointer, or pointers to "biblio". Record. -->
77
+ <xsl:apply-templates select="$document-root//xref" mode="citations"/>
78
+ </xsl:element>
79
+ </xsl:template>
80
+
81
+
82
+
83
+ <!-- The "biblio-to-json" template will convert a single "references" division (just the -->
84
+ <!-- "backmatter" instance right now) into a single JSON structure in CSL-JSON/citeproc-JSON -->
85
+ <!-- format. (Seems both names are in use, we will use the first.) -->
86
+ <!-- Note that the names of PreTeXt elements will mimic the names of JSON fields, so we can -->
87
+ <!-- use the "local-name()" function to have a single template cover multiple possibilities. -->
88
+ <!-- -->
89
+ <!-- Overview: -->
90
+ <!-- https://citeproc-js.readthedocs.io/en/latest/csl-json/markup.html -->
91
+ <!-- -->
92
+ <!-- CSL-JSON/citeproc-JSON: -->
93
+ <!-- https://github.com/citation-style-language/schema?tab=readme-ov-file#csl-json-schema -->
94
+ <!-- https://github.com/citation-style-language/schema/blob/master/schemas/input/csl-data.json -->
95
+ <!-- https://github.com/citation-style-language/schema/blob/master/schemas/input/csl-citation.json -->
96
+
97
+ <!-- TODO: expand to multiple "references" divisions -->
98
+
99
+ <!-- First, a catch-all version of the template to intercept un-implemented markup -->
100
+ <!-- TODO: perhaps report content also, as a better assist, or the self/parent/ancestor biblio id -->
101
+ <!-- TODO: refine to include un-implemented bits of "citeproc-py" (e/g static-ordering) -->
102
+ <xsl:template match="*" mode="biblio-to-json">
103
+ <xsl:message>BUG: PreTeXt "biblio" markup using a "<xsl:value-of select="local-name()"/>" element is not implemented</xsl:message>
104
+ </xsl:template>
105
+
106
+ <!-- Gross JSON array structure, duplicate an ID for the division -->
107
+ <xsl:template match="backmatter/references" mode="biblio-to-json">
108
+ <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
+ <xsl:text>[&#xa;</xsl:text>
113
+ <xsl:apply-templates select="biblio" mode="biblio-to-json"/>
114
+ <xsl:text>&#xa;]</xsl:text>
115
+ </xsl:element>
116
+ </xsl:template>
117
+
118
+ <!-- Convert each "biblio" to an object, assume PreTeXt markup is 100% structured. -->
119
+ <!-- TODO: refine "select" to only match to-level possibilities -->
120
+ <xsl:template match="biblio" mode="biblio-to-json">
121
+ <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>
125
+ <xsl:if test="following-sibling::biblio">
126
+ <xsl:text>,&#xa;</xsl:text>
127
+ <!-- intra-biblio visual formatting help -->
128
+ <xsl:text>&#xa;</xsl:text>
129
+ </xsl:if>
130
+ </xsl:template>
131
+
132
+ <!-- Attributes -->
133
+ <!-- Happy accident that local-name(@xml:id) is JSON "id" key for CSL -->
134
+
135
+ <!-- TODO: are the following attributes in PreTeXt markup? -->
136
+ <!-- citation-key -->
137
+ <!-- categories (an array. of?) -->
138
+ <!-- language -->
139
+ <!-- journalAbbreviation -->
140
+ <!-- shortTitle -->
141
+
142
+ <xsl:template match="@xml:id|@type" mode="biblio-to-json">
143
+ <xsl:text>"</xsl:text>
144
+ <xsl:value-of select="local-name()"/>
145
+ <xsl:text>"</xsl:text>
146
+ <xsl:text>: </xsl:text>
147
+ <xsl:text>"</xsl:text>
148
+ <!-- attribute value content -->
149
+ <xsl:call-template name="escape-json-string">
150
+ <xsl:with-param name="text">
151
+ <xsl:value-of select="."/>
152
+ </xsl:with-param>
153
+ </xsl:call-template>
154
+ <xsl:text>",&#xa;</xsl:text>
155
+ </xsl:template>
156
+
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">
163
+ <xsl:text>"</xsl:text>
164
+ <xsl:value-of select="local-name()"/>
165
+ <xsl:text>"</xsl:text>
166
+ <!-- separator w/ space -->
167
+ <xsl:text>: </xsl:text>
168
+ <xsl:text>"</xsl:text>
169
+ <!-- plain text content -->
170
+ <!-- apply-templates for math in titles??? -->
171
+ <xsl:call-template name="escape-json-string">
172
+ <xsl:with-param name="text">
173
+ <!-- convert to a textual representation -->
174
+ <xsl:apply-templates select="node()" mode="xml-to-string"/>
175
+ </xsl:with-param>
176
+ </xsl:call-template>
177
+ <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
+ </xsl:template>
191
+
192
+ <!-- ############### -->
193
+ <!-- Name structures -->
194
+ <!-- ############### -->
195
+
196
+ <!-- Structured name variables. -->
197
+ <!-- TODO: see "$ref": "#/definitions/name-variable" in CSL-JSON -->
198
+ <!-- schema to identify many more. "author" through "translator". -->
199
+ <xsl:template match="biblio/author|biblio/editor" mode="biblio-to-json">
200
+ <xsl:text>"</xsl:text>
201
+ <xsl:value-of select="local-name()"/>
202
+ <xsl:text>"</xsl:text>
203
+ <xsl:text>: </xsl:text>
204
+ <xsl:text>[</xsl:text>
205
+ <xsl:apply-templates select="name" mode="biblio-to-json"/>
206
+ <xsl:text>]</xsl:text>
207
+ <xsl:if test="following-sibling::*">
208
+ <xsl:text>,&#xa;</xsl:text>
209
+ </xsl:if>
210
+ </xsl:template>
211
+
212
+ <!-- Name structure -->
213
+ <xsl:template match="biblio/*/name" mode="biblio-to-json">
214
+ <xsl:text>{</xsl:text>
215
+ <!-- Name content model includes simple fields like -->
216
+ <!-- family, given, suffix, etc. -->
217
+ <!-- They will use the simple template above, where -->
218
+ <!-- fields are qualified with the "name" parent -->
219
+ <xsl:apply-templates select="*" mode="biblio-to-json"/>
220
+ <xsl:text>}</xsl:text>
221
+ <xsl:if test="following-sibling::name">
222
+ <xsl:text>, </xsl:text>
223
+ </xsl:if>
224
+ </xsl:template>
225
+
226
+ <!-- ############### -->
227
+ <!-- Date structures -->
228
+ <!-- ############### -->
229
+
230
+ <!-- Structured date variables. -->
231
+ <!-- TODO: see "$ref": "#/definitions/date-variable" in CSL-JSON -->
232
+ <!-- schema to identify many more. "accessed" through "submitted". -->
233
+ <xsl:template match="submitted|issued" mode="biblio-to-json">
234
+ <xsl:text>"</xsl:text>
235
+ <xsl:value-of select="local-name()"/>
236
+ <xsl:text>"</xsl:text>
237
+ <xsl:text>: </xsl:text>
238
+ <xsl:text>{&#xa;</xsl:text>
239
+ <xsl:if test="date">
240
+ <!-- Outer array structure, even if singleton -->
241
+ <xsl:text>"date-parts": </xsl:text>
242
+ <xsl:text>[</xsl:text>
243
+ <xsl:apply-templates select="date" mode="biblio-to-json"/>
244
+ <xsl:text>]</xsl:text>
245
+ </xsl:if>
246
+ <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
+ </xsl:template>
260
+
261
+ <!-- An array of length 1 to 3, with spaces after commas -->
262
+ <xsl:template match="date" mode="biblio-to-json">
263
+ <xsl:text>[</xsl:text>
264
+ <xsl:if test="@year">
265
+ <xsl:value-of select="@year"/>
266
+ </xsl:if>
267
+ <xsl:if test="@month">
268
+ <xsl:text>, </xsl:text>
269
+ <xsl:value-of select="@month"/>
270
+ </xsl:if>
271
+ <xsl:if test="@day">
272
+ <xsl:text>, </xsl:text>
273
+ <xsl:value-of select="@day"/>
274
+ </xsl:if>
275
+ <xsl:text>]</xsl:text>
276
+ <xsl:if test="following-sibling::date">
277
+ <xsl:text>, </xsl:text>
278
+ </xsl:if>
279
+ </xsl:template>
280
+
281
+
282
+ <!-- ######### -->
283
+ <!-- Citations -->
284
+ <!-- ######### -->
285
+
286
+ <xsl:template match="xref" mode="citations">
287
+ <!-- xref/@ref may point to a (backmatter) "biblio" -->
288
+ <!-- Or it may point to *several* "biblio" -->
289
+ <!-- Allow commas or spaces for separators -->
290
+ <!-- tokenize() has no root; a sequence of "token" -->
291
+ <xsl:variable name="tokenized-biblio-ref" select="str:tokenize(@ref, ' ,')"/>
292
+ <!-- list of @ref values that have been vetted -->
293
+ <!-- preliminary, may be null, may have trailing space -->
294
+ <xsl:variable name="citation-item-list-prelim">
295
+ <xsl:for-each select="$tokenized-biblio-ref">
296
+ <xsl:variable name="the-ref">
297
+ <xsl:value-of select="."/>
298
+ </xsl:variable>
299
+ <!-- context switch so id() function works -->
300
+ <xsl:for-each select="$original">
301
+ <xsl:variable name="target" select="id($the-ref)"/>
302
+ <!-- vet each @ref value, only backmatter is considered -->
303
+ <xsl:if test="$target/self::biblio/parent::references/parent::backmatter">
304
+ <xsl:value-of select="$the-ref"/>
305
+ <xsl:text> </xsl:text>
306
+ </xsl:if>
307
+ </xsl:for-each>
308
+ </xsl:for-each>
309
+ </xsl:variable>
310
+ <!-- normalizing will scrub final space, if non-empty -->
311
+ <xsl:variable name="citation-item-list"
312
+ select="normalize-space($citation-item-list-prelim)"/>
313
+ <!-- the "xref" might be some other cross-reference -->
314
+ <xsl:if test="not($citation-item-list = '')">
315
+ <!-- only visual, for debugging, etc. -->
316
+ <xsl:text>&#xa;</xsl:text>
317
+ <xsl:element name="xref-csl" namespace="http://pretextbook.org/2020/pretext/internal">
318
+ <!-- namespacing the attribute is sort of ugly -->
319
+ <xsl:attribute name="id">
320
+ <xsl:value-of select="@assembly-id"/>
321
+ </xsl:attribute>
322
+ <xsl:value-of select="$citation-item-list"/>
323
+ </xsl:element>
324
+ </xsl:if>
325
+ </xsl:template>
326
+
327
+ </xsl:stylesheet>