-
Notifications
You must be signed in to change notification settings - Fork 2
/
notebook.xsl
309 lines (244 loc) · 9.29 KB
/
notebook.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE xsl:stylesheet>
<!--*
* Convert an XML web page into an HTML one
* for notebooks
*
* info/notebook contains the notebook page
*
*-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="http://exslt.org/common"
xmlns:extfuncs="http://hea-www.harvard.edu/~dburke/xsl/extfuncs"
extension-element-prefixes="exsl extfuncs">
<!--*
* Options specific to notebooks
* the contents of the header
* the notebook itself
*-->
<xsl:param name="notebook_header" select='""'/>
<xsl:param name="notebook_contents" select='""'/>
<!--* Change this if the filename changes *-->
<xsl:variable name="hack-import-page" select="extfuncs:register-import-dependency('notebook.xsl')"/>
<xsl:output method="text"/>
<!--* we place this here to see if it works (was in header.xsl and wasn't working
* - and it seems to
*-->
<!--* a template to output a new line (useful after a comment) *-->
<xsl:template name="newline">
<xsl:text>
</xsl:text>
</xsl:template>
<!--* load in the set of "global" parameters *-->
<xsl:include href="globalparams.xsl"/>
<!--* include the stylesheets AFTER defining the variables *-->
<xsl:include href="helper.xsl"/>
<xsl:include href="links.xsl"/>
<xsl:include href="myhtml.xsl"/>
<!--*
* top level: create
* index.html
*
*-->
<xsl:template match="/">
<!--* check the params are okay *-->
<xsl:call-template name="is-site-valid"/>
<xsl:call-template name="check-param-ends-in-a-slash">
<xsl:with-param name="pname" select="'install'"/>
<xsl:with-param name="pvalue" select="$install"/>
</xsl:call-template>
<xsl:call-template name="check-param-ends-in-a-slash">
<xsl:with-param name="pname" select="'canonicalbase'"/>
<xsl:with-param name="pvalue" select="$canonicalbase"/>
</xsl:call-template>
<!--* we only want the top-level notebook *-->
<xsl:apply-templates select="/notebook"/>
</xsl:template> <!--* match=/ *-->
<!--*
* create: <page>.html
*-->
<xsl:template match="/notebook">
<xsl:variable name="filename"><xsl:value-of select="$install"/><xsl:value-of select="$pagename"/>.html</xsl:variable>
<!--* output filename to stdout *-->
<xsl:value-of select="$filename"/><xsl:call-template name="newline"/>
<!--*
* create HTML5 document, see
* http://w3c.github.io/html/syntax.html#doctype-legacy-string
* http://www.microhowto.info/howto/generate_an_html5_doctype_using_xslt.html
* https://stackoverflow.com/a/19379446
*
* Not sure that version="5.0" is actually working properly
* (or maybe my libxslt is too old)
*-->
<xsl:document href="{$filename}" method="html" media-type="text/html"
doctype-system="about:legacy-compat"
version="5.0">
<!--* we start processing the XML file here *-->
<html lang="en-US">
<!--*
* make the HTML head node
* - this is a manual version of add-htmlhead[-standard]
*-->
<xsl:variable name="title"><xsl:choose>
<xsl:when test="boolean(//notebook/info/title/long)"><xsl:value-of select="info/title/long"/></xsl:when>
<xsl:when test="boolean(//notebook/info/title/short)"><xsl:value-of select="info/title/short"/></xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">
ERROR no info/title block
</xsl:message>
</xsl:otherwise>
</xsl:choose></xsl:variable>
<head>
<title><xsl:value-of select="$title"/></title>
<!--* any meta information to add ? *-->
<xsl:apply-templates select="info/metalist"/>
<!--* any scripts ? *-->
<xsl:apply-templates select="info/htmlscripts"/>
<xsl:variable name="nmath" select="count(//math) + count(//inlinemath)"/>
<xsl:if test="$use-mathjax = 1 and ($nmath != 0)">
<xsl:if test="$mathjaxpath = ''">
<xsl:message terminate="yes">
ERROR: use-mathjax=1 but mathjaxpath is unset and the page contains math tags!
</xsl:message>
</xsl:if>
<script src="{$mathjaxpath}" id="MathJax-script" async=""/>
</xsl:if>
<!--* add main stylesheets *-->
<xsl:choose>
<xsl:when test="$site='iris'">
<link rel="stylesheet" title="Stylesheet for Iris pages" href="{$cssfile}"/>
<link rel="stylesheet" title="Stylesheet for Iris pages" media="print" href="{$cssprintfile}"/>
</xsl:when>
<xsl:when test="$site='csc'">
<link rel="stylesheet" title="Stylesheet for CSC pages" href="{$cssfile}"/>
<link rel="stylesheet" title="Stylesheet for CSC pages" media="print" href="{$cssprintfile}"/>
</xsl:when>
<xsl:otherwise>
<link rel="stylesheet" title="Default stylesheet for CIAO-related pages" href="{$cssfile}"/>
<link rel="stylesheet" title="Default stylesheet for CIAO-related pages" media="print" href="{$cssprintfile}"/>
</xsl:otherwise>
</xsl:choose>
<xsl:variable name="canonicalurl"><xsl:choose>
<xsl:when test="$canonicalbase = ''">
<xsl:message terminate="no">
DEVELOPMENT WARNING: no canonicalbase parameter so falling back to url=<xsl:value-of select="$url"/>
(if you see this warning tell Doug!)
</xsl:message>
<xsl:choose>
<xsl:when test="$url != ''"><xsl:value-of select="$url"/></xsl:when>
<xsl:otherwise>
<xsl:message terminate="no">
WARNING: page has no canonical link (missing canonicalbase/url params)
</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$pagename != ''"><xsl:value-of select="concat($canonicalbase, $pagename, '.html')"/></xsl:when>
<xsl:otherwise>
<xsl:message terminate="no">
WARNING: page has no canonical link (missing page/pagename)
</xsl:message>
</xsl:otherwise>
</xsl:choose></xsl:variable>
<xsl:if test="$canonicalurl != ''">
<xsl:variable name="cpos" select="string-length($canonicalurl) - 10"/>
<xsl:if test="$cpos < 1">
<xsl:message terminate="yes">
ERROR: canonicalurl=<xsl:value-of select="$canonicalurl"/> is too short!
</xsl:message>
</xsl:if>
<xsl:choose>
<xsl:when test="substring($canonicalurl, $cpos) = '/index.html'">
<link rel="canonical" href="{substring($canonicalurl, 1, $cpos)}"/>
</xsl:when>
<xsl:otherwise>
<link rel="canonical" href="{$canonicalurl}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
<xsl:call-template name="add-sao-metadata">
<xsl:with-param name="title" select="normalize-space($title)"/>
</xsl:call-template>
<!-- add in navbar header contents -->
<xsl:value-of select="$notebook_header" disable-output-escaping="yes"/>
<!-- Add in CSS, *AFTER* the notebook rules
* special notebook rules
* any ones the user has set up
-->
<style type="text/css">
div.notebook p.notebook-link {
padding: 0.5em;
}
div.notebook p.notebook-link a.button {
padding: 10px;
border: none;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
color: rgba(0, 0, 0, 0.6);
background-color: #99CC66;
font-size: 1.2em;
text-decoration: none;
text-align: center;
cursor: pointer;
-webkit-box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.75);
box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.75);
set to a different font */
font-family: Sans;
}
div.notebook p.notebook-link a.button:hover {
color: rgba(0, 0, 0, 0.8);
-webkit-box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.75);
-moz-box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.75);
box-shadow: 0px 4px 8px 0px rgba(0, 0, 0, 0.75);
}
</style>
<xsl:apply-templates select="info/css" mode="header"/>
</head>
<!-- * create the page contents *-->
<xsl:apply-templates select="text"/>
</html>
</xsl:document>
</xsl:template> <!--* match=page *-->
<xsl:template match="text[boolean(//notebook/info/navbar)]">
<xsl:call-template name="add-body-withnavbar">
<xsl:with-param name="contents">
<xsl:apply-templates/>
</xsl:with-param>
<xsl:with-param name="navbar">
<xsl:call-template name="add-navbar">
<xsl:with-param name="name" select="//notebook/info/navbar"/>
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:template> <!-- text with navbar -->
<!-- no navbar -->
<xsl:template match="text">
<xsl:call-template name="add-body-nonavbar">
<xsl:with-param name="contents">
<xsl:apply-templates/>
</xsl:with-param>
</xsl:call-template>
</xsl:template> <!--* text without navbar *-->
<!--*
* Add the notebook as
* title CURRENTLY NOT IMPLEMENTED
* [link to notebook]
* notebook_contents
*-->
<xsl:template match="notebook">
<div class="notebook">
<p class="notebook-link">
Download the
<a class="button"><xsl:attribute name="href"><xsl:value-of select="//info/notebook"/></xsl:attribute>notebook</a>.
</p>
<xsl:value-of select="$notebook_contents" disable-output-escaping="yes"/>
<p class="notebook-link">
Download the
<a class="button"><xsl:attribute name="href"><xsl:value-of select="//info/notebook"/></xsl:attribute>notebook</a>.
</p>
</div>
</xsl:template>
</xsl:stylesheet>