@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,492 +1,492 @@
1
- <?xml version='1.0'?>
2
-
3
- <!-- http://pimpmyxslt.com/articles/entity-tricks-part2/ -->
4
- <!DOCTYPE xsl:stylesheet [
5
- <!ENTITY % entities SYSTEM "entities.ent">
6
- %entities;
7
- ]>
8
-
9
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
10
- xmlns:exsl="http://exslt.org/common"
11
- xmlns:date="http://exslt.org/dates-and-times"
12
- xmlns:math="http://exslt.org/math"
13
- extension-element-prefixes="exsl date math">
14
-
15
- <xsl:import href="./pretext-html.xsl" />
16
-
17
- <!-- Intend output for rendering by browsers-->
18
- <xsl:output method="html" indent="yes"/>
19
-
20
- <!-- Content as Knowls -->
21
- <!-- Turn off all knowls, as incompatible -->
22
- <xsl:param name="html.knowl.theorem" select="'no'" />
23
- <xsl:param name="html.knowl.proof" select="'no'" />
24
- <xsl:param name="html.knowl.definition" select="'no'" />
25
- <xsl:param name="html.knowl.example" select="'no'" />
26
- <xsl:param name="html.knowl.remark" select="'no'" />
27
- <xsl:param name="html.knowl.figure" select="'no'" />
28
- <xsl:param name="html.knowl.table" select="'no'" />
29
- <xsl:param name="html.knowl.exercise.inline" select="'no'" />
30
- <xsl:param name="html.knowl.exercise.sectional" select="'no'" />
31
-
32
- <!-- SageWS files as output -->
33
- <xsl:variable name="file-extension" select="'.sagews'" />
34
-
35
- <!-- Do not implement any cross-reference as a knowl -->
36
- <xsl:template match="*" mode="xref-as-knowl">
37
- <xsl:value-of select="false()" />
38
- </xsl:template>
39
-
40
- <!-- Deprecation warnings are universal analysis of source and parameters -->
41
- <xsl:template match="/">
42
- <xsl:apply-templates select="mathbook" mode="deprecation-warnings" />
43
- <xsl:apply-templates />
44
- </xsl:template>
45
-
46
- <!-- We process structural nodes via chunking routine in xsl/pretext-common.xsl -->
47
- <!-- This in turn calls specific modal templates defined elsewhere in this file -->
48
- <!-- Contrary to HTML production, we do not have a pass through to build the knowls -->
49
- <xsl:template match="mathbook">
50
- <xsl:apply-templates mode="chunking" />
51
- </xsl:template>
52
-
53
- <!-- File wrap -->
54
- <!-- Per file setup, CSS, LaTeX macros, crude nav bars top and bottom -->
55
- <xsl:template match="*" mode="file-wrap">
56
- <xsl:param name="content" />
57
- <xsl:variable name="url">
58
- <xsl:apply-templates select="." mode="url" />
59
- </xsl:variable>
60
- <exsl:document href="{$url}" method="html">
61
- <xsl:call-template name="sage-css-setup" />
62
- <xsl:call-template name="html-css-mathjax-setup" />
63
- <xsl:apply-templates select="." mode="crude-nav-bar" />
64
- <!-- the guts -->
65
- <xsl:copy-of select="$content" />
66
- <!-- A nav bar at the bottom too -->
67
- <xsl:apply-templates select="." mode="crude-nav-bar" />
68
- </exsl:document>
69
- </xsl:template>
70
-
71
- <!-- The abstract chunking routines expect a default -->
72
- <!-- template for a structural subdivision that is an -->
73
- <!-- entire chunk, so we define that here. We just -->
74
- <!-- ship out to the "smc-cell" modal templates -->
75
- <xsl:template match="&STRUCTURAL;">
76
- <xsl:apply-templates select="." mode="smc-cell" />
77
- </xsl:template>
78
-
79
- <!-- The abstract chunking routines expect a modal -->
80
- <!-- "summary" template for a subdivision that sits -->
81
- <!-- above the chunking level. We write a heading, -->
82
- <!-- process the remainder in document order, either -->
83
- <!-- as content (eg introduction) or as a pointer -->
84
- <!-- to a finer subdivision -->
85
- <!-- TODO: This is functional but the output will not win style points -->
86
- <xsl:template match="&STRUCTURAL;" mode="summary">
87
- <!-- Heading, div for subdivision that is this page -->
88
- <xsl:apply-templates select="." mode="smc-html-cell">
89
- <xsl:with-param name="content">
90
- <xsl:variable name="hid">
91
- <xsl:apply-templates select="." mode="html-id" />
92
- </xsl:variable>
93
- <section class="{local-name(.)}" id="{$hid}">
94
- <xsl:apply-templates select="." mode="section-heading" />
95
- </section>
96
- </xsl:with-param>
97
- </xsl:apply-templates>
98
- <!-- Take structural elements to links -->
99
- <!-- Introduction and conclusion, etc as cells -->
100
- <xsl:for-each select="*[not(&METADATA-FILTER;)]">
101
- <xsl:choose>
102
- <xsl:when test="&STRUCTURAL-FILTER;">
103
- <xsl:apply-templates select="." mode="smc-html-cell">
104
- <xsl:with-param name="content">
105
- <xsl:variable name="num"><xsl:apply-templates select="." mode="number" /></xsl:variable>
106
- <xsl:variable name="url"><xsl:apply-templates select="." mode="url" /></xsl:variable>
107
- <div style="font-size:150%; padding-bottom:1.5ex">
108
- <a href="{$url}">
109
- <!-- important not include codenumber span -->
110
- <xsl:if test="$num!=''">
111
- <span class="codenumber"><xsl:value-of select="$num" /></span>
112
- <xsl:text> </xsl:text>
113
- </xsl:if>
114
- <span class="title">
115
- <xsl:apply-templates select="." mode="title-simple" />
116
- </span>
117
- </a>
118
- </div>
119
- </xsl:with-param>
120
- </xsl:apply-templates>
121
- </xsl:when>
122
- <!-- objectives, introduction, conclusion are included on page -->
123
- <!-- as SMC cells as they are processed in document order -->
124
- <xsl:otherwise>
125
- <xsl:apply-templates select="." mode="smc-cell" />
126
- </xsl:otherwise>
127
- </xsl:choose>
128
- </xsl:for-each>
129
- </xsl:template>
130
-
131
- <!-- Subdivisions get a full heading in a cell, then -->
132
- <!-- children are dispatched for possible refinement -->
133
- <xsl:template match="&STRUCTURAL;" mode="smc-cell">
134
- <!-- Subdivision heading, as its own HTML cell -->
135
- <xsl:apply-templates select="." mode="smc-html-cell">
136
- <xsl:with-param name="content">
137
- <xsl:variable name="hid">
138
- <xsl:apply-templates select="." mode="html-id" />
139
- </xsl:variable>
140
- <section class="{local-name(.)}" id="{$hid}">
141
- <xsl:apply-templates select="." mode="section-heading" />
142
- </section>
143
- </xsl:with-param>
144
- </xsl:apply-templates>
145
- <!-- Direct, and interesting, children become cells -->
146
- <!-- Further subdivisions (not chunked) come through here again -->
147
- <xsl:apply-templates select="*[not(&METADATA-FILTER;)]" mode="smc-cell" />
148
- </xsl:template>
149
-
150
- <!-- Introductions and conclusions get a milder heading in a -->
151
- <!-- cell, then children are dispatched for possible refinement -->
152
- <!-- TODO: condition on no title, so no cell -->
153
- <xsl:template match="introduction|conclusion" mode="smc-cell">
154
- <xsl:apply-templates select="." mode="smc-html-cell">
155
- <xsl:with-param name="content">
156
- <xsl:variable name="hid">
157
- <xsl:apply-templates select="." mode="html-id" />
158
- </xsl:variable>
159
- <article class="{local-name(.)}" id="{$hid}">
160
- <h5 class="heading">
161
- <xsl:apply-templates select="." mode="title-full" />
162
- <span> </span>
163
- </h5>
164
- </article>
165
- </xsl:with-param>
166
- </xsl:apply-templates>
167
- <!-- Build cells for remaining children -->
168
- <xsl:apply-templates select="*[not(&METADATA-FILTER;)]" mode="smc-cell" />
169
- </xsl:template>
170
-
171
- <!-- Most children of a subdivision will be HTML cells, -->
172
- <!-- so wrap as such and then call their default templates -->
173
- <xsl:template match="*" mode="smc-cell">
174
- <xsl:apply-templates select="." mode="smc-html-cell">
175
- <xsl:with-param name="content">
176
- <xsl:apply-templates select="." />
177
- </xsl:with-param>
178
- </xsl:apply-templates>
179
- </xsl:template>
180
-
181
- <!-- Handle Sage code with a minimum of interference -->
182
- <!-- This comes second, so as to overide generic above -->
183
- <xsl:template match="sage" mode="smc-cell">
184
- <xsl:apply-templates select="." mode="smc-compute-cell">
185
- <xsl:with-param name="content">
186
- <xsl:apply-templates select="." />
187
- <!-- Sage input always ends with a newline -->
188
- </xsl:with-param>
189
- </xsl:apply-templates>
190
- </xsl:template>
191
-
192
- <!-- Most Sage options are implemented in xsl/pretext-common.xsl -->
193
- <!-- We just output the input code, with no XHTML protections -->
194
- <xsl:template match="sage" mode="sage-active-markup">
195
- <xsl:param name="in" />
196
- <xsl:value-of select="$in" disable-output-escaping="yes" />
197
- </xsl:template>
198
-
199
- <!-- TODO: sage-display-only abstract template needed (?) -->
200
- <!-- Or deprecate type="display" -->
201
-
202
-
203
- <!-- Mimics depth-first search, into its own HTML cell -->
204
- <!-- This is functional but will not win style points -->
205
- <xsl:template match="*" mode="crude-nav-bar">
206
- <xsl:variable name="prev">
207
- <xsl:apply-templates select="." mode="previous-linear-url" />
208
- </xsl:variable>
209
- <xsl:variable name="up">
210
- <xsl:apply-templates select="." mode="up-url" />
211
- </xsl:variable>
212
- <xsl:variable name="next">
213
- <xsl:apply-templates select="." mode="next-linear-url" />
214
- </xsl:variable>
215
- <!-- HTML cell begins here, holds a table element -->
216
- <xsl:apply-templates select="." mode="smc-html-cell">
217
- <xsl:with-param name="content">
218
- <table width="90%" style="font-size: 200%;">
219
- <tr>
220
- <xsl:if test="not($prev = '')">
221
- <td align="left">
222
- <xsl:element name="a">
223
- <xsl:attribute name="href">
224
- <xsl:value-of select="$prev" />
225
- </xsl:attribute>
226
- <xsl:text>Previous</xsl:text>
227
- </xsl:element>
228
- </td>
229
- </xsl:if>
230
- <xsl:if test="not($up = '')">
231
- <td align="center">
232
- <xsl:element name="a">
233
- <xsl:attribute name="href">
234
- <xsl:value-of select="$up" />
235
- </xsl:attribute>
236
- <xsl:text>Up</xsl:text>
237
- </xsl:element>
238
- </td>
239
- </xsl:if>
240
- <xsl:if test="not($next = '')">
241
- <td align="right">
242
- <xsl:element name="a">
243
- <xsl:attribute name="href">
244
- <xsl:value-of select="$next" />
245
- </xsl:attribute>
246
- <xsl:text>Next</xsl:text>
247
- </xsl:element>
248
- </td>
249
- </xsl:if>
250
- </tr>
251
- </table>
252
- </xsl:with-param>
253
- </xsl:apply-templates>
254
- </xsl:template>
255
-
256
- <!-- We bypass image creation and just let SMC -->
257
- <!-- do the job with an executable cell -->
258
- <xsl:template match="image[child::sageplot]">
259
- <xsl:apply-templates select="sageplot" />
260
- </xsl:template>
261
-
262
- <!-- TODO: Not fixed up yet 2016-10-02 -->
263
- <xsl:template match="sageplot">
264
- <!-- Drop out of HTML mode -->
265
- <xsl:apply-templates select="." mode="inputoutput" />
266
- <xsl:apply-templates select="." mode="outputend" />
267
- <!-- Create a complete Sage cell region -->
268
- <xsl:apply-templates select="." mode="inputbegin-execute" />
269
- <xsl:text>%hide&#xa;</xsl:text>
270
- <xsl:call-template name="sanitize-text">
271
- <xsl:with-param name="text" select="." />
272
- </xsl:call-template>
273
- <xsl:apply-templates select="." mode="inputoutput" />
274
- <xsl:apply-templates select="." mode="outputend" />
275
- <!-- Start back in HTML mode -->
276
- <xsl:apply-templates select="." mode="inputbegin-execute" />
277
- <xsl:text>%html&#xa;</xsl:text>
278
- </xsl:template>
279
-
280
- <!-- Override for SVG images -->
281
- <!-- SMC treates the object tag badly. We ignore -->
282
- <!-- any PNG fallback and so just use an img tag. -->
283
- <!-- A named template creates the infrastructure -->
284
- <!-- for an SVG image. Parameter lists (doc, code) -->
285
- <!-- are identical to those for HTML conversion -->
286
- <!-- Parameters -->
287
- <!-- svg-filename: required, full relative path -->
288
- <!-- png-fallback-filename: optional -->
289
- <!-- image-width: required -->
290
- <!-- image-description: optional -->
291
- <xsl:template name="svg-wrapper">
292
- <xsl:param name="svg-filename" />
293
- <xsl:param name="png-fallback-filename" select="''" />
294
- <xsl:param name="image-width" />
295
- <xsl:param name="image-description" select="''" />
296
- <xsl:element name="img">
297
- <xsl:attribute name="style">
298
- <xsl:text>width:</xsl:text>
299
- <xsl:value-of select="$image-width" />
300
- <xsl:text>; margin:0 auto;</xsl:text>
301
- </xsl:attribute>
302
- <xsl:attribute name="src">
303
- <xsl:value-of select="$svg-filename" />
304
- </xsl:attribute>
305
- <xsl:attribute name="alt">
306
- <xsl:value-of select="$image-description" />
307
- </xsl:attribute>
308
- </xsl:element>
309
- </xsl:template>
310
-
311
- <!-- ##################### -->
312
- <!-- Set-up, per-worksheet -->
313
- <!-- ##################### -->
314
-
315
- <!-- HTML code for CSS load -->
316
- <!-- Gets a div.mathbook-content wrapper -->
317
- <!-- which seems to only produce excess space -->
318
- <xsl:template name="sage-css-setup">
319
- <xsl:apply-templates select="." mode="smc-html-cell">
320
- <xsl:with-param name="content">
321
- <xsl:element name="link">
322
- <xsl:attribute name="rel">
323
- <xsl:text>stylesheet</xsl:text>
324
- </xsl:attribute>
325
- <xsl:attribute name="type">
326
- <xsl:text>text/css</xsl:text>
327
- </xsl:attribute>
328
- <xsl:attribute name="href">
329
- <xsl:text>http://buzzard.ups.edu/mathbook-content.css</xsl:text>
330
- </xsl:attribute>
331
- </xsl:element>
332
- <xsl:element name="link">
333
- <xsl:attribute name="rel">
334
- <xsl:text>stylesheet</xsl:text>
335
- </xsl:attribute>
336
- <xsl:attribute name="type">
337
- <xsl:text>text/css</xsl:text>
338
- </xsl:attribute>
339
- <xsl:attribute name="href">
340
- <xsl:text>https://aimath.org/mathbook/mathbook-add-on.css</xsl:text>
341
- </xsl:attribute>
342
- </xsl:element>
343
- </xsl:with-param>
344
- </xsl:apply-templates>
345
- </xsl:template>
346
-
347
- <!-- HTML code for MathJax macros -->
348
- <xsl:template name="html-css-mathjax-setup">
349
- <xsl:apply-templates select="." mode="smc-html-cell">
350
- <xsl:with-param name="content">
351
- <xsl:apply-templates select="." mode="latex-macros" />
352
- </xsl:with-param>
353
- </xsl:apply-templates>
354
- </xsl:template>
355
-
356
- <!-- ########################### -->
357
- <!-- SageMathCloud Cell Wrappers -->
358
- <!-- ########################### -->
359
-
360
- <!-- SMC HTML Cell -->
361
- <!-- Pass in HTML content, after templates applied -->
362
- <!-- USe SMC UUID markers on their own lines -->
363
- <!-- Wrap in custom CSS class, mathbook-content -->
364
- <xsl:template match="*" mode="smc-html-cell">
365
- <xsl:param name="content" />
366
- <xsl:apply-templates select="." mode="smc-input-marker" />
367
- <xsl:text>&#xa;</xsl:text>
368
- <xsl:text>%auto&#xa;</xsl:text>
369
- <xsl:text>%html(hide=True)&#xa;</xsl:text>
370
- <xsl:element name="div">
371
- <xsl:attribute name="class">
372
- <xsl:text>mathbook-content</xsl:text>
373
- </xsl:attribute>
374
- <xsl:copy-of select="$content" />
375
- </xsl:element>
376
- <!-- Be certain output marker is on own line -->
377
- <xsl:text>&#xa;</xsl:text>
378
- <xsl:apply-templates select="." mode="smc-output-marker" />
379
- <!-- We could parse HTML $content into a JSON-escaped string -->
380
- <!-- Belongs *immediately* after output marker (?) -->
381
- <!-- <xsl:text disable-output-escaping='yes'>{"done":true,"html":"&lt;p&gt;Execute cell above for proper output.&lt;/p&gt;"}&#xa;</xsl:text> -->
382
- <xsl:text>&#xa;</xsl:text>
383
- </xsl:template>
384
-
385
- <!-- SMC Compute Cell -->
386
- <!-- Pass in content, after templates applied -->
387
- <!-- USe SMC UUID markers on their own lines -->
388
- <!-- Wrap in custom CSS class, mathbook-content -->
389
- <xsl:template match="*" mode="smc-compute-cell">
390
- <xsl:param name="content" />
391
- <xsl:apply-templates select="." mode="smc-input-marker" />
392
- <xsl:text>&#xa;</xsl:text>
393
- <xsl:copy-of select="$content" />
394
- <!-- Be certain $content ends with newline -->
395
- <xsl:apply-templates select="." mode="smc-output-marker" />
396
- <xsl:text>&#xa;</xsl:text>
397
- </xsl:template>
398
-
399
-
400
- <!-- ########################## -->
401
- <!-- SageMathCloud Cell Markers -->
402
- <!-- ########################## -->
403
-
404
- <!-- SMC uses markers to denote the start of each cell, -->
405
- <!-- differentiating input from output. -->
406
- <!-- By default these are Sage compute cells, but -->
407
- <!-- decorators/magics can make them behave differently -->
408
-
409
- <!-- Pair of matched seldom-used Unicode, with a UUID -->
410
- <!-- 'COMBINING LIGATURE LEFT HALF' (U+FE20) -->
411
- <xsl:template match="*" mode="smc-input-marker">
412
- <xsl:text>&#xFE20;</xsl:text>
413
- <xsl:apply-templates select="." mode="uuid" />
414
- <xsl:text>&#xFE20;</xsl:text>
415
- </xsl:template>
416
-
417
- <!-- Pair of matched seldom-used Unicode, with a UUID -->
418
- <!-- 'COMBINING LIGATURE RIGHT HALF' (U+FE21) -->
419
- <xsl:template match="*" mode="smc-output-marker">
420
- <xsl:text>&#xFE21;</xsl:text>
421
- <xsl:apply-templates select="." mode="uuid" />
422
- <xsl:text>&#xFE21;</xsl:text>
423
- </xsl:template>
424
-
425
- <!-- Version 4 UUID -->
426
- <!-- Improvements: -->
427
- <!-- Use EXSLT random:random-sequence -->
428
- <!-- (1) Get a random number -->
429
- <!-- (2) Get content id of object -->
430
- <!-- (3) Mix to a new seed -->
431
- <!-- (4) Generate sequence and adorn -->
432
- <!-- idpXXXXXXXX (universal format?) -->
433
- <!-- <xsl:value-of select="substring(generate-id(.), 4, 8)" /> -->
434
- <xsl:template match="*" mode="uuid">
435
- <xsl:call-template name="random-hex-digit" /> <!-- 1 -->
436
- <xsl:call-template name="random-hex-digit" /> <!-- 2 -->
437
- <xsl:call-template name="random-hex-digit" /> <!-- 3 -->
438
- <xsl:call-template name="random-hex-digit" /> <!-- 4 -->
439
- <xsl:call-template name="random-hex-digit" /> <!-- 5 -->
440
- <xsl:call-template name="random-hex-digit" /> <!-- 6 -->
441
- <xsl:call-template name="random-hex-digit" /> <!-- 7 -->
442
- <xsl:call-template name="random-hex-digit" /> <!-- 8 -->
443
- <xsl:text>-</xsl:text>
444
- <xsl:call-template name="random-hex-digit" /> <!-- 1 -->
445
- <xsl:call-template name="random-hex-digit" /> <!-- 2 -->
446
- <xsl:call-template name="random-hex-digit" /> <!-- 3 -->
447
- <xsl:call-template name="random-hex-digit" /> <!-- 4 -->
448
- <xsl:text>-</xsl:text>
449
- <xsl:text>4</xsl:text> <!-- Version 4 -->
450
- <xsl:call-template name="random-hex-digit" /> <!-- 2 -->
451
- <xsl:call-template name="random-hex-digit" /> <!-- 3 -->
452
- <xsl:call-template name="random-hex-digit" /> <!-- 4 -->
453
- <xsl:text>-</xsl:text>
454
- <xsl:text>a</xsl:text> <!-- Variant: leading bits 10 -->
455
- <xsl:call-template name="random-hex-digit" /> <!-- 2 -->
456
- <xsl:call-template name="random-hex-digit" /> <!-- 3 -->
457
- <xsl:call-template name="random-hex-digit" /> <!-- 4 -->
458
- <xsl:text>-</xsl:text>
459
- <xsl:call-template name="random-hex-digit" /> <!-- 1 -->
460
- <xsl:call-template name="random-hex-digit" /> <!-- 2 -->
461
- <xsl:call-template name="random-hex-digit" /> <!-- 3 -->
462
- <xsl:call-template name="random-hex-digit" /> <!-- 4 -->
463
- <xsl:call-template name="random-hex-digit" /> <!-- 5 -->
464
- <xsl:call-template name="random-hex-digit" /> <!-- 6 -->
465
- <xsl:call-template name="random-hex-digit" /> <!-- 7 -->
466
- <xsl:call-template name="random-hex-digit" /> <!-- 8 -->
467
- <xsl:call-template name="random-hex-digit" /> <!-- 9 -->
468
- <xsl:call-template name="random-hex-digit" /> <!-- 0 -->
469
- <xsl:call-template name="random-hex-digit" /> <!-- 1 -->
470
- <xsl:call-template name="random-hex-digit" /> <!-- 2 -->
471
- </xsl:template>
472
-
473
- <xsl:template name="random-hex-digit">
474
- <xsl:variable name="digit" select="floor(16*math:random())" />
475
- <xsl:choose>
476
- <xsl:when test="10 > $digit">
477
- <xsl:value-of select="$digit" />
478
- </xsl:when>
479
- <xsl:otherwise>
480
- <xsl:choose>
481
- <xsl:when test="$digit = 10">a</xsl:when>
482
- <xsl:when test="$digit = 11">b</xsl:when>
483
- <xsl:when test="$digit = 12">c</xsl:when>
484
- <xsl:when test="$digit = 13">d</xsl:when>
485
- <xsl:when test="$digit = 14">e</xsl:when>
486
- <xsl:when test="$digit = 15">f</xsl:when>
487
- </xsl:choose>
488
- </xsl:otherwise>
489
- </xsl:choose>
490
- </xsl:template>
491
-
492
- </xsl:stylesheet>
1
+ <?xml version='1.0'?>
2
+
3
+ <!-- http://pimpmyxslt.com/articles/entity-tricks-part2/ -->
4
+ <!DOCTYPE xsl:stylesheet [
5
+ <!ENTITY % entities SYSTEM "entities.ent">
6
+ %entities;
7
+ ]>
8
+
9
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
10
+ xmlns:exsl="http://exslt.org/common"
11
+ xmlns:date="http://exslt.org/dates-and-times"
12
+ xmlns:math="http://exslt.org/math"
13
+ extension-element-prefixes="exsl date math">
14
+
15
+ <xsl:import href="./pretext-html.xsl" />
16
+
17
+ <!-- Intend output for rendering by browsers-->
18
+ <xsl:output method="html" indent="yes"/>
19
+
20
+ <!-- Content as Knowls -->
21
+ <!-- Turn off all knowls, as incompatible -->
22
+ <xsl:param name="html.knowl.theorem" select="'no'" />
23
+ <xsl:param name="html.knowl.proof" select="'no'" />
24
+ <xsl:param name="html.knowl.definition" select="'no'" />
25
+ <xsl:param name="html.knowl.example" select="'no'" />
26
+ <xsl:param name="html.knowl.remark" select="'no'" />
27
+ <xsl:param name="html.knowl.figure" select="'no'" />
28
+ <xsl:param name="html.knowl.table" select="'no'" />
29
+ <xsl:param name="html.knowl.exercise.inline" select="'no'" />
30
+ <xsl:param name="html.knowl.exercise.sectional" select="'no'" />
31
+
32
+ <!-- SageWS files as output -->
33
+ <xsl:variable name="file-extension" select="'.sagews'" />
34
+
35
+ <!-- Do not implement any cross-reference as a knowl -->
36
+ <xsl:template match="*" mode="xref-as-knowl">
37
+ <xsl:value-of select="false()" />
38
+ </xsl:template>
39
+
40
+ <!-- Deprecation warnings are universal analysis of source and parameters -->
41
+ <xsl:template match="/">
42
+ <xsl:apply-templates select="mathbook" mode="deprecation-warnings" />
43
+ <xsl:apply-templates />
44
+ </xsl:template>
45
+
46
+ <!-- We process structural nodes via chunking routine in xsl/pretext-common.xsl -->
47
+ <!-- This in turn calls specific modal templates defined elsewhere in this file -->
48
+ <!-- Contrary to HTML production, we do not have a pass through to build the knowls -->
49
+ <xsl:template match="mathbook">
50
+ <xsl:apply-templates mode="chunking" />
51
+ </xsl:template>
52
+
53
+ <!-- File wrap -->
54
+ <!-- Per file setup, CSS, LaTeX macros, crude nav bars top and bottom -->
55
+ <xsl:template match="*" mode="file-wrap">
56
+ <xsl:param name="content" />
57
+ <xsl:variable name="url">
58
+ <xsl:apply-templates select="." mode="url" />
59
+ </xsl:variable>
60
+ <exsl:document href="{$url}" method="html">
61
+ <xsl:call-template name="sage-css-setup" />
62
+ <xsl:call-template name="html-css-mathjax-setup" />
63
+ <xsl:apply-templates select="." mode="crude-nav-bar" />
64
+ <!-- the guts -->
65
+ <xsl:copy-of select="$content" />
66
+ <!-- A nav bar at the bottom too -->
67
+ <xsl:apply-templates select="." mode="crude-nav-bar" />
68
+ </exsl:document>
69
+ </xsl:template>
70
+
71
+ <!-- The abstract chunking routines expect a default -->
72
+ <!-- template for a structural subdivision that is an -->
73
+ <!-- entire chunk, so we define that here. We just -->
74
+ <!-- ship out to the "smc-cell" modal templates -->
75
+ <xsl:template match="&STRUCTURAL;">
76
+ <xsl:apply-templates select="." mode="smc-cell" />
77
+ </xsl:template>
78
+
79
+ <!-- The abstract chunking routines expect a modal -->
80
+ <!-- "summary" template for a subdivision that sits -->
81
+ <!-- above the chunking level. We write a heading, -->
82
+ <!-- process the remainder in document order, either -->
83
+ <!-- as content (eg introduction) or as a pointer -->
84
+ <!-- to a finer subdivision -->
85
+ <!-- TODO: This is functional but the output will not win style points -->
86
+ <xsl:template match="&STRUCTURAL;" mode="summary">
87
+ <!-- Heading, div for subdivision that is this page -->
88
+ <xsl:apply-templates select="." mode="smc-html-cell">
89
+ <xsl:with-param name="content">
90
+ <xsl:variable name="hid">
91
+ <xsl:apply-templates select="." mode="html-id" />
92
+ </xsl:variable>
93
+ <section class="{local-name(.)}" id="{$hid}">
94
+ <xsl:apply-templates select="." mode="section-heading" />
95
+ </section>
96
+ </xsl:with-param>
97
+ </xsl:apply-templates>
98
+ <!-- Take structural elements to links -->
99
+ <!-- Introduction and conclusion, etc as cells -->
100
+ <xsl:for-each select="*[not(&METADATA-FILTER;)]">
101
+ <xsl:choose>
102
+ <xsl:when test="&STRUCTURAL-FILTER;">
103
+ <xsl:apply-templates select="." mode="smc-html-cell">
104
+ <xsl:with-param name="content">
105
+ <xsl:variable name="num"><xsl:apply-templates select="." mode="number" /></xsl:variable>
106
+ <xsl:variable name="url"><xsl:apply-templates select="." mode="url" /></xsl:variable>
107
+ <div style="font-size:150%; padding-bottom:1.5ex">
108
+ <a href="{$url}">
109
+ <!-- important not include codenumber span -->
110
+ <xsl:if test="$num!=''">
111
+ <span class="codenumber"><xsl:value-of select="$num" /></span>
112
+ <xsl:text> </xsl:text>
113
+ </xsl:if>
114
+ <span class="title">
115
+ <xsl:apply-templates select="." mode="title-simple" />
116
+ </span>
117
+ </a>
118
+ </div>
119
+ </xsl:with-param>
120
+ </xsl:apply-templates>
121
+ </xsl:when>
122
+ <!-- objectives, introduction, conclusion are included on page -->
123
+ <!-- as SMC cells as they are processed in document order -->
124
+ <xsl:otherwise>
125
+ <xsl:apply-templates select="." mode="smc-cell" />
126
+ </xsl:otherwise>
127
+ </xsl:choose>
128
+ </xsl:for-each>
129
+ </xsl:template>
130
+
131
+ <!-- Subdivisions get a full heading in a cell, then -->
132
+ <!-- children are dispatched for possible refinement -->
133
+ <xsl:template match="&STRUCTURAL;" mode="smc-cell">
134
+ <!-- Subdivision heading, as its own HTML cell -->
135
+ <xsl:apply-templates select="." mode="smc-html-cell">
136
+ <xsl:with-param name="content">
137
+ <xsl:variable name="hid">
138
+ <xsl:apply-templates select="." mode="html-id" />
139
+ </xsl:variable>
140
+ <section class="{local-name(.)}" id="{$hid}">
141
+ <xsl:apply-templates select="." mode="section-heading" />
142
+ </section>
143
+ </xsl:with-param>
144
+ </xsl:apply-templates>
145
+ <!-- Direct, and interesting, children become cells -->
146
+ <!-- Further subdivisions (not chunked) come through here again -->
147
+ <xsl:apply-templates select="*[not(&METADATA-FILTER;)]" mode="smc-cell" />
148
+ </xsl:template>
149
+
150
+ <!-- Introductions and conclusions get a milder heading in a -->
151
+ <!-- cell, then children are dispatched for possible refinement -->
152
+ <!-- TODO: condition on no title, so no cell -->
153
+ <xsl:template match="introduction|conclusion" mode="smc-cell">
154
+ <xsl:apply-templates select="." mode="smc-html-cell">
155
+ <xsl:with-param name="content">
156
+ <xsl:variable name="hid">
157
+ <xsl:apply-templates select="." mode="html-id" />
158
+ </xsl:variable>
159
+ <article class="{local-name(.)}" id="{$hid}">
160
+ <h5 class="heading">
161
+ <xsl:apply-templates select="." mode="title-full" />
162
+ <span> </span>
163
+ </h5>
164
+ </article>
165
+ </xsl:with-param>
166
+ </xsl:apply-templates>
167
+ <!-- Build cells for remaining children -->
168
+ <xsl:apply-templates select="*[not(&METADATA-FILTER;)]" mode="smc-cell" />
169
+ </xsl:template>
170
+
171
+ <!-- Most children of a subdivision will be HTML cells, -->
172
+ <!-- so wrap as such and then call their default templates -->
173
+ <xsl:template match="*" mode="smc-cell">
174
+ <xsl:apply-templates select="." mode="smc-html-cell">
175
+ <xsl:with-param name="content">
176
+ <xsl:apply-templates select="." />
177
+ </xsl:with-param>
178
+ </xsl:apply-templates>
179
+ </xsl:template>
180
+
181
+ <!-- Handle Sage code with a minimum of interference -->
182
+ <!-- This comes second, so as to overide generic above -->
183
+ <xsl:template match="sage" mode="smc-cell">
184
+ <xsl:apply-templates select="." mode="smc-compute-cell">
185
+ <xsl:with-param name="content">
186
+ <xsl:apply-templates select="." />
187
+ <!-- Sage input always ends with a newline -->
188
+ </xsl:with-param>
189
+ </xsl:apply-templates>
190
+ </xsl:template>
191
+
192
+ <!-- Most Sage options are implemented in xsl/pretext-common.xsl -->
193
+ <!-- We just output the input code, with no XHTML protections -->
194
+ <xsl:template match="sage" mode="sage-active-markup">
195
+ <xsl:param name="in" />
196
+ <xsl:value-of select="$in" disable-output-escaping="yes" />
197
+ </xsl:template>
198
+
199
+ <!-- TODO: sage-display-only abstract template needed (?) -->
200
+ <!-- Or deprecate type="display" -->
201
+
202
+
203
+ <!-- Mimics depth-first search, into its own HTML cell -->
204
+ <!-- This is functional but will not win style points -->
205
+ <xsl:template match="*" mode="crude-nav-bar">
206
+ <xsl:variable name="prev">
207
+ <xsl:apply-templates select="." mode="previous-linear-url" />
208
+ </xsl:variable>
209
+ <xsl:variable name="up">
210
+ <xsl:apply-templates select="." mode="up-url" />
211
+ </xsl:variable>
212
+ <xsl:variable name="next">
213
+ <xsl:apply-templates select="." mode="next-linear-url" />
214
+ </xsl:variable>
215
+ <!-- HTML cell begins here, holds a table element -->
216
+ <xsl:apply-templates select="." mode="smc-html-cell">
217
+ <xsl:with-param name="content">
218
+ <table width="90%" style="font-size: 200%;">
219
+ <tr>
220
+ <xsl:if test="not($prev = '')">
221
+ <td align="left">
222
+ <xsl:element name="a">
223
+ <xsl:attribute name="href">
224
+ <xsl:value-of select="$prev" />
225
+ </xsl:attribute>
226
+ <xsl:text>Previous</xsl:text>
227
+ </xsl:element>
228
+ </td>
229
+ </xsl:if>
230
+ <xsl:if test="not($up = '')">
231
+ <td align="center">
232
+ <xsl:element name="a">
233
+ <xsl:attribute name="href">
234
+ <xsl:value-of select="$up" />
235
+ </xsl:attribute>
236
+ <xsl:text>Up</xsl:text>
237
+ </xsl:element>
238
+ </td>
239
+ </xsl:if>
240
+ <xsl:if test="not($next = '')">
241
+ <td align="right">
242
+ <xsl:element name="a">
243
+ <xsl:attribute name="href">
244
+ <xsl:value-of select="$next" />
245
+ </xsl:attribute>
246
+ <xsl:text>Next</xsl:text>
247
+ </xsl:element>
248
+ </td>
249
+ </xsl:if>
250
+ </tr>
251
+ </table>
252
+ </xsl:with-param>
253
+ </xsl:apply-templates>
254
+ </xsl:template>
255
+
256
+ <!-- We bypass image creation and just let SMC -->
257
+ <!-- do the job with an executable cell -->
258
+ <xsl:template match="image[child::sageplot]">
259
+ <xsl:apply-templates select="sageplot" />
260
+ </xsl:template>
261
+
262
+ <!-- TODO: Not fixed up yet 2016-10-02 -->
263
+ <xsl:template match="sageplot">
264
+ <!-- Drop out of HTML mode -->
265
+ <xsl:apply-templates select="." mode="inputoutput" />
266
+ <xsl:apply-templates select="." mode="outputend" />
267
+ <!-- Create a complete Sage cell region -->
268
+ <xsl:apply-templates select="." mode="inputbegin-execute" />
269
+ <xsl:text>%hide&#xa;</xsl:text>
270
+ <xsl:call-template name="sanitize-text">
271
+ <xsl:with-param name="text" select="." />
272
+ </xsl:call-template>
273
+ <xsl:apply-templates select="." mode="inputoutput" />
274
+ <xsl:apply-templates select="." mode="outputend" />
275
+ <!-- Start back in HTML mode -->
276
+ <xsl:apply-templates select="." mode="inputbegin-execute" />
277
+ <xsl:text>%html&#xa;</xsl:text>
278
+ </xsl:template>
279
+
280
+ <!-- Override for SVG images -->
281
+ <!-- SMC treates the object tag badly. We ignore -->
282
+ <!-- any PNG fallback and so just use an img tag. -->
283
+ <!-- A named template creates the infrastructure -->
284
+ <!-- for an SVG image. Parameter lists (doc, code) -->
285
+ <!-- are identical to those for HTML conversion -->
286
+ <!-- Parameters -->
287
+ <!-- svg-filename: required, full relative path -->
288
+ <!-- png-fallback-filename: optional -->
289
+ <!-- image-width: required -->
290
+ <!-- image-description: optional -->
291
+ <xsl:template name="svg-wrapper">
292
+ <xsl:param name="svg-filename" />
293
+ <xsl:param name="png-fallback-filename" select="''" />
294
+ <xsl:param name="image-width" />
295
+ <xsl:param name="image-description" select="''" />
296
+ <xsl:element name="img">
297
+ <xsl:attribute name="style">
298
+ <xsl:text>width:</xsl:text>
299
+ <xsl:value-of select="$image-width" />
300
+ <xsl:text>; margin:0 auto;</xsl:text>
301
+ </xsl:attribute>
302
+ <xsl:attribute name="src">
303
+ <xsl:value-of select="$svg-filename" />
304
+ </xsl:attribute>
305
+ <xsl:attribute name="alt">
306
+ <xsl:value-of select="$image-description" />
307
+ </xsl:attribute>
308
+ </xsl:element>
309
+ </xsl:template>
310
+
311
+ <!-- ##################### -->
312
+ <!-- Set-up, per-worksheet -->
313
+ <!-- ##################### -->
314
+
315
+ <!-- HTML code for CSS load -->
316
+ <!-- Gets a div.mathbook-content wrapper -->
317
+ <!-- which seems to only produce excess space -->
318
+ <xsl:template name="sage-css-setup">
319
+ <xsl:apply-templates select="." mode="smc-html-cell">
320
+ <xsl:with-param name="content">
321
+ <xsl:element name="link">
322
+ <xsl:attribute name="rel">
323
+ <xsl:text>stylesheet</xsl:text>
324
+ </xsl:attribute>
325
+ <xsl:attribute name="type">
326
+ <xsl:text>text/css</xsl:text>
327
+ </xsl:attribute>
328
+ <xsl:attribute name="href">
329
+ <xsl:text>http://buzzard.ups.edu/mathbook-content.css</xsl:text>
330
+ </xsl:attribute>
331
+ </xsl:element>
332
+ <xsl:element name="link">
333
+ <xsl:attribute name="rel">
334
+ <xsl:text>stylesheet</xsl:text>
335
+ </xsl:attribute>
336
+ <xsl:attribute name="type">
337
+ <xsl:text>text/css</xsl:text>
338
+ </xsl:attribute>
339
+ <xsl:attribute name="href">
340
+ <xsl:text>https://aimath.org/mathbook/mathbook-add-on.css</xsl:text>
341
+ </xsl:attribute>
342
+ </xsl:element>
343
+ </xsl:with-param>
344
+ </xsl:apply-templates>
345
+ </xsl:template>
346
+
347
+ <!-- HTML code for MathJax macros -->
348
+ <xsl:template name="html-css-mathjax-setup">
349
+ <xsl:apply-templates select="." mode="smc-html-cell">
350
+ <xsl:with-param name="content">
351
+ <xsl:apply-templates select="." mode="latex-macros" />
352
+ </xsl:with-param>
353
+ </xsl:apply-templates>
354
+ </xsl:template>
355
+
356
+ <!-- ########################### -->
357
+ <!-- SageMathCloud Cell Wrappers -->
358
+ <!-- ########################### -->
359
+
360
+ <!-- SMC HTML Cell -->
361
+ <!-- Pass in HTML content, after templates applied -->
362
+ <!-- USe SMC UUID markers on their own lines -->
363
+ <!-- Wrap in custom CSS class, mathbook-content -->
364
+ <xsl:template match="*" mode="smc-html-cell">
365
+ <xsl:param name="content" />
366
+ <xsl:apply-templates select="." mode="smc-input-marker" />
367
+ <xsl:text>&#xa;</xsl:text>
368
+ <xsl:text>%auto&#xa;</xsl:text>
369
+ <xsl:text>%html(hide=True)&#xa;</xsl:text>
370
+ <xsl:element name="div">
371
+ <xsl:attribute name="class">
372
+ <xsl:text>mathbook-content</xsl:text>
373
+ </xsl:attribute>
374
+ <xsl:copy-of select="$content" />
375
+ </xsl:element>
376
+ <!-- Be certain output marker is on own line -->
377
+ <xsl:text>&#xa;</xsl:text>
378
+ <xsl:apply-templates select="." mode="smc-output-marker" />
379
+ <!-- We could parse HTML $content into a JSON-escaped string -->
380
+ <!-- Belongs *immediately* after output marker (?) -->
381
+ <!-- <xsl:text disable-output-escaping='yes'>{"done":true,"html":"&lt;p&gt;Execute cell above for proper output.&lt;/p&gt;"}&#xa;</xsl:text> -->
382
+ <xsl:text>&#xa;</xsl:text>
383
+ </xsl:template>
384
+
385
+ <!-- SMC Compute Cell -->
386
+ <!-- Pass in content, after templates applied -->
387
+ <!-- USe SMC UUID markers on their own lines -->
388
+ <!-- Wrap in custom CSS class, mathbook-content -->
389
+ <xsl:template match="*" mode="smc-compute-cell">
390
+ <xsl:param name="content" />
391
+ <xsl:apply-templates select="." mode="smc-input-marker" />
392
+ <xsl:text>&#xa;</xsl:text>
393
+ <xsl:copy-of select="$content" />
394
+ <!-- Be certain $content ends with newline -->
395
+ <xsl:apply-templates select="." mode="smc-output-marker" />
396
+ <xsl:text>&#xa;</xsl:text>
397
+ </xsl:template>
398
+
399
+
400
+ <!-- ########################## -->
401
+ <!-- SageMathCloud Cell Markers -->
402
+ <!-- ########################## -->
403
+
404
+ <!-- SMC uses markers to denote the start of each cell, -->
405
+ <!-- differentiating input from output. -->
406
+ <!-- By default these are Sage compute cells, but -->
407
+ <!-- decorators/magics can make them behave differently -->
408
+
409
+ <!-- Pair of matched seldom-used Unicode, with a UUID -->
410
+ <!-- 'COMBINING LIGATURE LEFT HALF' (U+FE20) -->
411
+ <xsl:template match="*" mode="smc-input-marker">
412
+ <xsl:text>&#xFE20;</xsl:text>
413
+ <xsl:apply-templates select="." mode="uuid" />
414
+ <xsl:text>&#xFE20;</xsl:text>
415
+ </xsl:template>
416
+
417
+ <!-- Pair of matched seldom-used Unicode, with a UUID -->
418
+ <!-- 'COMBINING LIGATURE RIGHT HALF' (U+FE21) -->
419
+ <xsl:template match="*" mode="smc-output-marker">
420
+ <xsl:text>&#xFE21;</xsl:text>
421
+ <xsl:apply-templates select="." mode="uuid" />
422
+ <xsl:text>&#xFE21;</xsl:text>
423
+ </xsl:template>
424
+
425
+ <!-- Version 4 UUID -->
426
+ <!-- Improvements: -->
427
+ <!-- Use EXSLT random:random-sequence -->
428
+ <!-- (1) Get a random number -->
429
+ <!-- (2) Get content id of object -->
430
+ <!-- (3) Mix to a new seed -->
431
+ <!-- (4) Generate sequence and adorn -->
432
+ <!-- idpXXXXXXXX (universal format?) -->
433
+ <!-- <xsl:value-of select="substring(generate-id(.), 4, 8)" /> -->
434
+ <xsl:template match="*" mode="uuid">
435
+ <xsl:call-template name="random-hex-digit" /> <!-- 1 -->
436
+ <xsl:call-template name="random-hex-digit" /> <!-- 2 -->
437
+ <xsl:call-template name="random-hex-digit" /> <!-- 3 -->
438
+ <xsl:call-template name="random-hex-digit" /> <!-- 4 -->
439
+ <xsl:call-template name="random-hex-digit" /> <!-- 5 -->
440
+ <xsl:call-template name="random-hex-digit" /> <!-- 6 -->
441
+ <xsl:call-template name="random-hex-digit" /> <!-- 7 -->
442
+ <xsl:call-template name="random-hex-digit" /> <!-- 8 -->
443
+ <xsl:text>-</xsl:text>
444
+ <xsl:call-template name="random-hex-digit" /> <!-- 1 -->
445
+ <xsl:call-template name="random-hex-digit" /> <!-- 2 -->
446
+ <xsl:call-template name="random-hex-digit" /> <!-- 3 -->
447
+ <xsl:call-template name="random-hex-digit" /> <!-- 4 -->
448
+ <xsl:text>-</xsl:text>
449
+ <xsl:text>4</xsl:text> <!-- Version 4 -->
450
+ <xsl:call-template name="random-hex-digit" /> <!-- 2 -->
451
+ <xsl:call-template name="random-hex-digit" /> <!-- 3 -->
452
+ <xsl:call-template name="random-hex-digit" /> <!-- 4 -->
453
+ <xsl:text>-</xsl:text>
454
+ <xsl:text>a</xsl:text> <!-- Variant: leading bits 10 -->
455
+ <xsl:call-template name="random-hex-digit" /> <!-- 2 -->
456
+ <xsl:call-template name="random-hex-digit" /> <!-- 3 -->
457
+ <xsl:call-template name="random-hex-digit" /> <!-- 4 -->
458
+ <xsl:text>-</xsl:text>
459
+ <xsl:call-template name="random-hex-digit" /> <!-- 1 -->
460
+ <xsl:call-template name="random-hex-digit" /> <!-- 2 -->
461
+ <xsl:call-template name="random-hex-digit" /> <!-- 3 -->
462
+ <xsl:call-template name="random-hex-digit" /> <!-- 4 -->
463
+ <xsl:call-template name="random-hex-digit" /> <!-- 5 -->
464
+ <xsl:call-template name="random-hex-digit" /> <!-- 6 -->
465
+ <xsl:call-template name="random-hex-digit" /> <!-- 7 -->
466
+ <xsl:call-template name="random-hex-digit" /> <!-- 8 -->
467
+ <xsl:call-template name="random-hex-digit" /> <!-- 9 -->
468
+ <xsl:call-template name="random-hex-digit" /> <!-- 0 -->
469
+ <xsl:call-template name="random-hex-digit" /> <!-- 1 -->
470
+ <xsl:call-template name="random-hex-digit" /> <!-- 2 -->
471
+ </xsl:template>
472
+
473
+ <xsl:template name="random-hex-digit">
474
+ <xsl:variable name="digit" select="floor(16*math:random())" />
475
+ <xsl:choose>
476
+ <xsl:when test="10 > $digit">
477
+ <xsl:value-of select="$digit" />
478
+ </xsl:when>
479
+ <xsl:otherwise>
480
+ <xsl:choose>
481
+ <xsl:when test="$digit = 10">a</xsl:when>
482
+ <xsl:when test="$digit = 11">b</xsl:when>
483
+ <xsl:when test="$digit = 12">c</xsl:when>
484
+ <xsl:when test="$digit = 13">d</xsl:when>
485
+ <xsl:when test="$digit = 14">e</xsl:when>
486
+ <xsl:when test="$digit = 15">f</xsl:when>
487
+ </xsl:choose>
488
+ </xsl:otherwise>
489
+ </xsl:choose>
490
+ </xsl:template>
491
+
492
+ </xsl:stylesheet>