Debian Codegraph @

xslt/common/html.xsl

raw
1 <?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
2 <!--
3 This program is free software; you can redistribute it and/or modify it under
4 the terms of the GNU Lesser General Public License as published by the Free
5 Software Foundation; either version 2 of the License, or (at your option) any
6 later version.
7
8 This program is distributed in the hope that it will be useful, but WITHOUT
9 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 details.
12
13 You should have received a copy of the GNU Lesser General Public License
14 along with this program; see the file COPYING.LGPL. If not, see <http://www.gnu.org/licenses/>.
15 -->
16
17 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
18 xmlns:html="http://www.w3.org/1999/xhtml"
19 xmlns:mml="http://www.w3.org/1998/Math/MathML"
20 xmlns:exsl="http://exslt.org/common"
21 xmlns:set="http://exslt.org/sets"
22 xmlns:str="http://exslt.org/strings"
23 xmlns:its="http://www.w3.org/2005/11/its"
24 xmlns="http://www.w3.org/1999/xhtml"
25 exclude-result-prefixes="html mml set str its"
26 extension-element-prefixes="exsl"
27 version="1.0">
28
29 <!--!!==========================================================================
30 HTML Output
31 Common utilities and CSS for transformations to HTML.
32 @revision[version=1.0 date=2010-05-26 status=final]
33
34 This stylesheet contains common templates for creating HTML output. The
35 {html.output} template creates an output file for a node in the source XML
36 document, calling {html.page} to create the actual output. Output files can
37 be either XHTML or HTML, depending on the {html.xhtml} parameter.
38
39 This stylesheet matches `/` and calls {html.output} on the root XML element.
40 This works for most input formats. If you need to do something different, you
41 should override the match for `/`.
42 -->
43 <xsl:template match="/">
44 <xsl:call-template name="html.output">
45 <xsl:with-param name="node" select="*"/>
46 </xsl:call-template>
47 </xsl:template>
48
49
50 <!--@@==========================================================================
51 html.basename
52 The base filename of the primary output file.
53 @revision[version=1.0 date=2010-05-25 status=final]
54
55 This parameter specifies the base filename of the primary output file, without
56 the filename extension. This is used by {html.output} to determine the output
57 filename, and may be used by format-specific linking code. By default, it uses
58 the value of an `id` or `xml:id` attribute, if present. Otherwise, it uses
59 the static string `index`.
60 -->
61 <xsl:param name="html.basename">
62 <xsl:choose>
63 <xsl:when test="/*/@xml:id">
64 <xsl:value-of select="/*/@xml:id"/>
65 </xsl:when>
66 <xsl:when test="/*/@id">
67 <xsl:value-of select="/*/@id"/>
68 </xsl:when>
69 <xsl:otherwise>
70 <xsl:text>index</xsl:text>
71 </xsl:otherwise>
72 </xsl:choose>
73 </xsl:param>
74
75
76 <!--@@==========================================================================
77 html.xhtml
78 Whether to output XHTML.
79 @revision[version=1.0 date=2010-05-25 status=final]
80
81 If this parameter is set to true, this stylesheet will output XHTML. Otherwise,
82 the output is assumed to be HTML. Note that for HTML output, the importing
83 stylesheet still needs to call `xsl:namespace-alias` to map the XHTML namespace
84 to `#default`. The {html.namespace} parameter will be set automatically based
85 on this parameter. Stylesheets can use this parameter to check the output type,
86 for example when using `xsl:element`.
87 -->
88 <xsl:param name="html.xhtml" select="true()"/>
89
90
91 <!--@@==========================================================================
92 html.namespace
93 The XML namespace for the output document.
94 @revision[version=1.0 date=2010-05-25 status=final]
95
96 This parameter specifies the XML namespace of all output documents. It will be
97 set automatically based on the {html.xhtml} parameter, either to the XHTML
98 namespace, or to the empty namespace. Stylesheets can use this parameter when
99 using `xsl:element`.
100 -->
101 <xsl:param name="html.namespace">
102 <xsl:choose>
103 <xsl:when test="$html.xhtml">
104 <xsl:value-of select="'http://www.w3.org/1999/xhtml'"/>
105 </xsl:when>
106 <xsl:otherwise>
107 <xsl:text></xsl:text>
108 </xsl:otherwise>
109 </xsl:choose>
110 </xsl:param>
111
112
113 <!--@@==========================================================================
114 html.mathml.namespace
115 The XML namespace for MathML in the output document.
116 @revision[version=3.18 date=2015-05-04 status=final]
117
118 This parameter specifies the XML namespace for MathML in output documents. It
119 will be set automatically based on the {html.xhtml} parameter, either to the
120 MathML namespace namespace, or to the empty namespace. Stylesheets can use this
121 parameter when using `xsl:element`.
122 -->
123 <xsl:param name="html.mathml.namespace">
124 <xsl:choose>
125 <xsl:when test="$html.xhtml">
126 <xsl:value-of select="'http://www.w3.org/1998/Math/MathML'"/>
127 </xsl:when>
128 <xsl:otherwise>
129 <xsl:text></xsl:text>
130 </xsl:otherwise>
131 </xsl:choose>
132 </xsl:param>
133
134
135 <!--@@==========================================================================
136 html.svg.namespace
137 The XML namespace for SVG in the output document.
138 @revision[version=3.18 date=2015-05-04 status=final]
139
140 This parameter specifies the XML namespace for SVG in output documents. It
141 will be set automatically based on the {html.xhtml} parameter, either to the
142 SVG namespace namespace, or to the empty namespace. Stylesheets can use this
143 parameter when using `xsl:element`.
144 -->
145 <xsl:param name="html.svg.namespace">
146 <xsl:choose>
147 <xsl:when test="$html.xhtml">
148 <xsl:value-of select="'http://www.w3.org/2000/svg'"/>
149 </xsl:when>
150 <xsl:otherwise>
151 <xsl:text></xsl:text>
152 </xsl:otherwise>
153 </xsl:choose>
154 </xsl:param>
155
156
157 <!--@@==========================================================================
158 html.extension
159 The filename extension for all output files.
160 @revision[version=1.0 date=2010-05-25 status=final]
161
162 This parameter specifies a filename extension for all HTML output files. It
163 should include the leading dot. By default, `.xhtml` will be used if
164 {html.xhtml} is true; otherwise, `.html` will be used.
165 -->
166 <xsl:param name="html.extension">
167 <xsl:choose>
168 <xsl:when test="$html.xhtml">
169 <xsl:text>.xhtml</xsl:text>
170 </xsl:when>
171 <xsl:otherwise>
172 <xsl:text>.html</xsl:text>
173 </xsl:otherwise>
174 </xsl:choose>
175 </xsl:param>
176
177
178 <!--@@==========================================================================
179 html.grid.size
180 The width of the page for grid layouts.
181 @revision[version=40 date=2021-01-09 status=final]
182
183 This parameter sets the width of the main page content, including padding, but
184 excluding any sidebars. These stylesheets frequently use flexible grids for
185 layouts, and columnds are based on this parameter. This parameter should be a
186 multiple of 12 for best results. Common grid sizes are 1200, 1080, and 960.
187 -->
188 <xsl:param name="html.grid.size" select="1080"/>
189 <xsl:variable name="html.grid.col1" select="$html.grid.size - 20"/>
190 <xsl:variable name="html.grid.col2" select="$html.grid.size div 2 - 20"/>
191 <xsl:variable name="html.grid.col3" select="$html.grid.size div 3 - 20"/>
192 <xsl:variable name="html.grid.col4" select="$html.grid.size div 4 - 20"/>
193
194
195 <!--@@==========================================================================
196 html.css.root
197 The URI root for external CSS files.
198 @revision[version=1.0 date=2010-12-06 status=final]
199
200 This parameter provides a root URI for any external CSS files that are
201 referenced from the output HTML file. If non-empty, it must end with
202 a trailing slash character.
203 -->
204 <xsl:param name="html.css.root" select="''"/>
205
206
207 <!--@@==========================================================================
208 html.js.root
209 The URI root for external JavaScript files.
210 @revision[version=1.0 date=2010-12-06 status=final]
211
212 This parameter provides a root URI for any external JavaScript files that are
213 referenced from the output HTML file. If non-empty, it must end with
214 a trailing slash character.
215 -->
216 <xsl:param name="html.js.root" select="''"/>
217
218
219 <!--@@==========================================================================
220 html.syntax.highlight
221 Whether to include syntax highlighting support for code blocks.
222 @revision[version=1.0 date=2010-12-06 status=final]
223
224 This parameter specifies whether syntax highlighting should be enabled for
225 code blocks in the output HTML. Syntax highlighting is done at document load
226 time by JavaScript.
227 -->
228 <xsl:param name="html.syntax.highlight" select="true()"/>
229
230
231 <!--@@==========================================================================
232 html.output.prefix
233 An optional path prefix for files output with {html.output}.
234 @revision[version=3.28 date=2017-05-24 status=final]
235
236 This parameter allows you to specify an prefix to place before the output path
237 used by {html.output} when creating files. You can use this to override the
238 output directory. Make sure you include a trailing slash, unless you want to
239 prefix the base file name itself.
240 -->
241 <xsl:param name="html.output.prefix" select="''"/>
242
243
244 <!--@@==========================================================================
245 html.sidebar.left
246 List of components to add to the left sidebar.
247 @revision[version=3.30 date=2018-06-10 status=candidate]
248
249 This parameter takes a space-separated list of tokens that specify which
250 components to add to the stock left sidebar. These stylesheets recognize
251 certain tokens, and you can add your own with {html.sidebar.mode}. See
252 {html.sidebar} for further details.
253 -->
254 <xsl:param name="html.sidebar.left" select="''"/>
255
256
257 <!--@@==========================================================================
258 html.sidebar.right
259 List of components to add to the right sidebar.
260 @revision[version=3.30 date=2018-06-10 status=candidate]
261
262 This parameter takes a space-separated list of tokens that specify which
263 components to add to the stock right sidebar. These stylesheets recognize
264 certain tokens, and you can add your own with {html.sidebar.mode}. See
265 {html.sidebar} for further details.
266 -->
267 <xsl:param name="html.sidebar.right" select="''"/>
268
269 <!--@@==========================================================================
270 html.csp.nonce
271 An optional CSP nonce string to allow the execution of scripts and styles.
272 @revision[version=42.2 date=2025-02-22 status=final]
273
274 This parameter takes a string value that will be added to the 'nonce' attribute
275 of all 'style' and 'script' tags in the generated HTML output. This paramter is used
276 to whitelist script and style tags that are allowed to be executed.
277 -->
278 <xsl:param name="html.csp.nonce" select="false()"/>
279
280 <!--**==========================================================================
281 html.output
282 Create an HTML output file.
283 @revision[version=1.0 date=2010-05-26 status=final]
284
285 [xsl:params]
286 $node: The node to create an output file for.
287 $href: The output filename.
288
289 This template creates an HTML output file for the source element $node. It
290 uses `exsl:document` to output the file, and calls {html.page} with the
291 $node parameter to output the actual HTML contents.
292
293 If $href is not provided, this template will attempt to generate a base
294 filename and append {html.extension} to it. The base filename is generated
295 as follows:
296
297 * If an `xml:id` attribute is present, it is used.
298 * Otherwise, if an `id` attribute is present, it is used.
299 * Otherwise, if $node is the root element, {html.basename} is used.
300 * Otherwise, `generate-id()` is called.
301
302 This template prepends {html.output.prefix} to the value of $href when
303 it calls `exsl:document`, regardless of whether $href was passed in or
304 generated automatically.
305
306 After calling `exsl:document`, this template calls the {html.output.after.mode}
307 mode on $node. Importing stylesheets that create multiple output files can
308 use this to process output files without blocking earlier output.
309 -->
310 <xsl:template name="html.output">
311 <xsl:param name="node" select="."/>
312 <xsl:param name="href">
313 <xsl:choose>
314 <xsl:when test="$node/@xml:id">
315 <xsl:value-of select="concat($node/@xml:id, $html.extension)"/>
316 </xsl:when>
317 <xsl:when test="$node/@id">
318 <xsl:value-of select="concat($node/@id, $html.extension)"/>
319 </xsl:when>
320 <xsl:when test="set:has-same-node($node, /*)">
321 <xsl:value-of select="concat($html.basename, $html.extension)"/>
322 </xsl:when>
323 <xsl:otherwise>
324 <xsl:value-of select="concat(generate-id(), $html.extension)"/>
325 </xsl:otherwise>
326 </xsl:choose>
327 </xsl:param>
328 <xsl:choose>
329 <xsl:when test="$html.xhtml">
330 <exsl:document href="{$html.output.prefix}{$href}">
331 <xsl:call-template name="html.page">
332 <xsl:with-param name="node" select="$node"/>
333 </xsl:call-template>
334 </exsl:document>
335 </xsl:when>
336 <xsl:otherwise>
337 <exsl:document href="{$html.output.prefix}{$href}" method="html"
338 doctype-system="about:legacy-compat">
339 <xsl:call-template name="html.page">
340 <xsl:with-param name="node" select="$node"/>
341 </xsl:call-template>
342 </exsl:document>
343 </xsl:otherwise>
344 </xsl:choose>
345 <xsl:apply-templates mode="html.output.after.mode" select="$node"/>
346 </xsl:template>
347
348
349
350 <!--%%==========================================================================
351 html.output.after.mode
352 Process an element after its content are output.
353 @revision[version=1.0 date=2010-05-26 status=final]
354
355 This mode is called by {html.output} after `exsl:document` has finished. It
356 can be used to create further output files without blocking the output of
357 parent elements.
358 -->
359 <xsl:template mode="html.output.after.mode" match="*"/>
360
361
362 <!--**==========================================================================
363 html.page
364 Create an HTML document.
365 @revision[version=3.28 date=2017-08-04 status=final]
366
367 [xsl:params]
368 $node: The node to create HTML for.
369
370 This template creates the actual HTML output for $node. It outputs top-level
371 elements and container divs, and calls various templates and modes to output
372 the inner content. Importing stylesheets should implement at least
373 {html.title.mode} and {html.body.mode} for any elements that could be passed
374 as $node to this template. Importing stylesheets should also implement
375 {html.header.mode} to output link trails and {html.footer.mode} to output
376 credits and other page information.
377
378 This template outputs the HTML `body` element, which takes its attributes
379 from two sources. First, it calls {html.lang.attrs}, which automatically
380 outputs correct `lang`, `xml:lang`, and `dir` attributes. It then calls
381 {html.body.attr.mode} on $node for additional attributes.
382
383 This template also calls a number of stub templates that can be overridden
384 by extension stylesheets.
385
386 * Override the {html.head.custom} template to put custom content at the end
387 of the HTML `head` element.
388
389 * Override the {html.head.top.custom} template to put custom content at the
390 beginning of the HTML `head` element.
391
392 * Override the {html.top.custom} and {html.bottom.custom} templates to add
393 site-specific content at the top and bottom of the page.
394
395 * Override the {html.header.custom} and {html.footer.custom} templates to
396 provide additional content directoy above and below the main content.
397
398 * Use the {html.sidebar.left} and {html.sidebar.right} parameters to create
399 stock sidebars, or override {html.sidebar.custom} to create your own.
400
401 This template also calls {html.css} and {html.js} to output CSS and JavaScript
402 elements. See those templates for further extension points.
403 -->
404 <xsl:template name="html.page">
405 <xsl:param name="node" select="."/>
406 <html>
407 <head>
408 <xsl:call-template name="html.head.top.custom">
409 <xsl:with-param name="node" select="$node"/>
410 </xsl:call-template>
411 <xsl:if test="$html.csp.nonce != ''">
412 <meta http-equiv="Content-Security-Policy" content="script-src 'nonce-{$html.csp.nonce}';"/>
413 </xsl:if>
414 <meta name="viewport"
415 content="width=device-width, initial-scale=1.0, user-scalable=yes"/>
416 <title>
417 <xsl:apply-templates mode="html.title.mode" select="$node"/>
418 </title>
419 <xsl:call-template name="html.css">
420 <xsl:with-param name="node" select="$node"/>
421 </xsl:call-template>
422 <xsl:call-template name="html.js">
423 <xsl:with-param name="node" select="$node"/>
424 </xsl:call-template>
425 <xsl:call-template name="html.head.custom">
426 <xsl:with-param name="node" select="$node"/>
427 </xsl:call-template>
428 </head>
429 <body>
430 <xsl:call-template name="html.lang.attrs">
431 <xsl:with-param name="node" select="$node"/>
432 </xsl:call-template>
433 <xsl:apply-templates mode="html.body.attr.mode" select="$node"/>
434 <xsl:call-template name="html.top.custom">
435 <xsl:with-param name="node" select="$node"/>
436 </xsl:call-template>
437 <main>
438 <xsl:call-template name="html.sidebar">
439 <xsl:with-param name="node" select="$node"/>
440 </xsl:call-template>
441 <xsl:call-template name="html.sidebar.custom">
442 <xsl:with-param name="node" select="$node"/>
443 </xsl:call-template>
444 <div class="page">
445 <header>
446 <div class="inner pagewide">
447 <xsl:call-template name="html.header.custom">
448 <xsl:with-param name="node" select="$node"/>
449 </xsl:call-template>
450 <xsl:apply-templates mode="html.header.mode" select="$node"/>
451 </div>
452 </header>
453 <article>
454 <xsl:apply-templates mode="html.body.mode" select="$node"/>
455 </article>
456 <footer>
457 <div class="inner pagewide">
458 <xsl:apply-templates mode="html.footer.mode" select="$node"/>
459 <xsl:call-template name="html.footer.custom">
460 <xsl:with-param name="node" select="$node"/>
461 </xsl:call-template>
462 </div>
463 </footer>
464 </div>
465 </main>
466 <xsl:call-template name="html.bottom.custom">
467 <xsl:with-param name="node" select="$node"/>
468 </xsl:call-template>
469 </body>
470 </html>
471 </xsl:template>
472
473
474 <!--%%==========================================================================
475 html.title.mode
476 Output the title of an element.
477 @revision[version=1.0 date=2010-05-26 status=final]
478
479 This mode is called by {html.page} to output the contents of the HTML `title`
480 element inside the `head` element. Importing stylesheets should implement this
481 mode for any element that will be passed to {html.page}. Because this is used
482 in the `head`, the output should be text-only.
483 -->
484 <xsl:template mode="html.title.mode" match="*"/>
485
486
487 <!--%%==========================================================================
488 html.body.attr.mode
489 Output attributes for the HTML `body` element.
490 @revision[version=1.0 date=2010-06-08 status=final]
491
492 This mode is called by {html.page} to output attributes on the HTML `body`
493 element. No attributes are output by default. Importing stylesheets may
494 implement this node to add attributes for styling, data, or other purposes.
495 -->
496 <xsl:template mode="html.body.attr.mode" match="*"/>
497
498
499 <!--**==========================================================================
500 html.top.custom
501 Stub to output HTML at the top of the page.
502 @xsl:stub
503 @revision[version=3.28 date=2017-05-24 status=final]
504
505 [xsl:params]
506 $node: The node a page is being created for.
507
508 This template is a stub, called by {html.page}. It is called before the
509 `main` element. Override this template to provide site-specific HTML
510 at the top of the page.
511 -->
512 <xsl:template name="html.top.custom">
513 <xsl:param name="node" select="."/>
514 </xsl:template>
515
516
517 <!--**==========================================================================
518 html.bottom.custom
519 Stub to output HTML at the bottom of the page.
520 @xsl:stub
521 @revision[version=3.28 date=2017-05-24 status=final]
522
523 [xsl:params]
524 $node: The node a page is being created for.
525
526 This template is a stub, called by {html.page}. It is called after the
527 `main` element. Override this template to provide site-specific HTML
528 at the bottom of the page.
529 -->
530 <xsl:template name="html.bottom.custom">
531 <xsl:param name="node" select="."/>
532 </xsl:template>
533
534
535 <!--**==========================================================================
536 html.sidebar
537 Output stock sidebars.
538 @revision[version=3.30 date=2018-06-10 status=candidate]
539
540 [xsl:params]
541 $node: The node a sidebar is being created for.
542
543 This templates outputs left and right sidebars according to the components
544 listed in {html.sidebar.left} and {html.sidebar.right}. It only outputs each
545 sidebar if the corresponding parameters is not empty or the string `none`.
546
547 This template is called inside the `main` element, before the `div.page`
548 element, and before {html.sidebar.custom}. Note that even the right sidebar
549 is placed before the `div.page` element. It is placed on the right using
550 flexbox item reordering.
551
552 To actually output the sidebar components, this template splits each parameter
553 on whitespace using the EXSLT `str:split` function. It then applies the mode
554 {html.sidebar.mode} to each token, passing $node and the sidebar side as
555 parameters. Extension stylesheets can add their own sidebar components by
556 implementing that mode and matching a pattern like
557
558 [code]
559 token[. = 'name-of-token']
560
561 You will then be able to use `name-of-token` in {html.sidebar.left} or
562 {html.sidebar.right}.
563
564 This stylesheet recognizes four tokens: `contents` and `sections`, and the
565 special tokens `none` and `blank`.
566
567 * The `contents` token provides a table of contents for the entire document.
568 It is handled by the {html.sidebar.contents} template, which uses the
569 {html.sidebar.contents.mode} mode to allow different input formats to
570 implement it.
571
572 * The `sections` token lists sections on the current page. It is handled by the
573 html.sidebar.section} template, which uses the {html.sidebar.sections.mode}
574 mode to allow different input formats to implement it.
575
576 * Use the `none` token on its own, instead of the empty string, to completely
577 turn off either sidebar.
578
579 * Use the `blank` token to output a sidebar without adding any components to
580 it. This is useful, for example, to keep consistent margins. If an empty
581 sidebar is output from the `blank` token, it will also have the CSS class
582 `sidebar-blank` so you can style it differently.
583 -->
584 <xsl:template name="html.sidebar">
585 <xsl:param name="node" select="."/>
586 <xsl:if test="$html.sidebar.left != '' and $html.sidebar.left != 'none'">
587 <xsl:call-template name="_html.sidebar.sidebar">
588 <xsl:with-param name="node" select="$node"/>
589 <xsl:with-param name="side" select="'left'"/>
590 <xsl:with-param name="bars" select="$html.sidebar.left"/>
591 </xsl:call-template>
592 </xsl:if>
593 <xsl:if test="$html.sidebar.right != '' and $html.sidebar.right != 'none'">
594 <xsl:call-template name="_html.sidebar.sidebar">
595 <xsl:with-param name="node" select="$node"/>
596 <xsl:with-param name="side" select="'right'"/>
597 <xsl:with-param name="bars" select="$html.sidebar.right"/>
598 </xsl:call-template>
599 </xsl:if>
600 </xsl:template>
601
602 <xsl:template name="_html.sidebar.sidebar">
603 <xsl:param name="node"/>
604 <xsl:param name="side"/>
605 <xsl:param name="bars"/>
606 <xsl:variable name="class">
607 <xsl:text>sidebar sidebar-</xsl:text>
608 <xsl:value-of select="$side"/>
609 <xsl:if test="$bars = 'blank'">
610 <xsl:text> sidebar-blank</xsl:text>
611 </xsl:if>
612 </xsl:variable>
613 <aside class="{$class}">
614 <xsl:apply-templates mode="html.sidebar.mode" select="str:split($bars)">
615 <xsl:with-param name="node" select="$node"/>
616 <xsl:with-param name="side" select="$side"/>
617 </xsl:apply-templates>
618 </aside>
619 </xsl:template>
620
621
622 <!--%%==========================================================================
623 html.sidebar.mode
624 Output a sidebar compenent for a token.
625 @revision[version=3.30 date=2018-06-10 status=candidate]
626
627 [xsl:params]
628 $node: The node a sidebar is being created for.
629 $side: Which sidebar, either `left` or `right`.
630
631 This mode is called by {html.sidebar} for each sidebar compenent in each of
632 {html.sidebar.left} and {html.sidebar.right}. See {html.sidebar} for full
633 details.
634 -->
635 <xsl:template mode="html.sidebar.mode" match="token[. = 'blank']"/>
636 <xsl:template mode="html.sidebar.mode" match="*">
637 <xsl:message>
638 <xsl:text>Unmatched sidebar: </xsl:text>
639 <xsl:value-of select="."/>
640 </xsl:message>
641 </xsl:template>
642
643
644 <!--**==========================================================================
645 html.sidebar.contents
646 Output a table of contents for a sidebar.
647 @revision[version=3.30 date=2018-06-10 status=candidate]
648
649 [xsl:params]
650 $node: The node a sidebar is being created for.
651 $side: Which sidebar, either `left` or `right`.
652
653 This template creates a table of contents for a sidebar. It applies
654 {html.sidebar.contents.mode} to $node, passing $side as a parameter, to
655 allow individual input formats to implement tables of contents.
656
657 This named template also implements {html.sidebar.mode} on the `contents`
658 token. See {html.sidebar} for more information on how sidebars are created.
659 -->
660 <xsl:template name="html.sidebar.contents"
661 mode="html.sidebar.mode" match="token[. = 'contents']">
662 <xsl:param name="node"/>
663 <xsl:param name="side"/>
664 <xsl:apply-templates mode="html.sidebar.contents.mode" select="$node">
665 <xsl:with-param name="side" select="$side"/>
666 </xsl:apply-templates>
667 </xsl:template>
668
669
670 <!--%%==========================================================================
671 html.sidebar.contents.mode
672 Output a table of contents for a sidebar.
673 @revision[version=3.30 date=2018-06-10 status=candidate]
674
675 [xsl:params]
676 $side: Which sidebar, either `left` or `right`.
677
678 This mode is called by {html.sidebar.contents} to allow different input
679 formats to implement a table of contents for a sidebar.
680 -->
681 <xsl:template mode="html.sidebar.contents.mode" match="*">
682 <xsl:param name="side"/>
683 <xsl:message>
684 <xsl:text>Unmatched contents sidebar: </xsl:text>
685 <xsl:value-of select="local-name(.)"/>
686 </xsl:message>
687 </xsl:template>
688
689
690 <!--**==========================================================================
691 html.sidebar.sections
692 Output a list of sections for a sidebar.
693 @revision[version=3.30 date=2018-06-10 status=candidate]
694
695 [xsl:params]
696 $node: The node a sidebar is being created for.
697 $side: Which sidebar, either `left` or `right`.
698
699 This template creates a list of sections on the current page for a sidebar.
700 It applies {html.sidebar.sections.mode} to $node, passing $side as a
701 parameter, to allow individual input formats to implement sections lists.
702
703 This named template also implements {html.sidebar.mode} on the `sections`
704 token. See {html.sidebar} for more information on how sidebars are created.
705 -->
706 <xsl:template name="html.sidebar.sections"
707 mode="html.sidebar.mode" match="token[. = 'sections']">
708 <xsl:param name="node"/>
709 <xsl:param name="side"/>
710 <xsl:apply-templates mode="html.sidebar.sections.mode" select="$node">
711 <xsl:with-param name="side" select="$side"/>
712 </xsl:apply-templates>
713 </xsl:template>
714
715
716 <!--%%==========================================================================
717 html.sidebar.sections.mode
718 Output a list of sections for a sidebar.
719 @revision[version=3.30 date=2018-06-10 status=candidate]
720
721 [xsl:params]
722 $side: Which sidebar, either `left` or `right`.
723
724 This mode is called by {html.sidebar.sections} to allow different input
725 formats to implement a sections list for a sidebar.
726 -->
727 <xsl:template mode="html.sidebar.sections.mode" match="*">
728 <xsl:param name="side"/>
729 <xsl:message>
730 <xsl:text>Unmatched sections sidebar: </xsl:text>
731 <xsl:value-of select="local-name(.)"/>
732 </xsl:message>
733 </xsl:template>
734
735
736 <!--**==========================================================================
737 html.sidebar.custom
738 Stub to output custom sidebar content.
739 @xsl:stub
740 @revision[version=3.28 date=2017-05-24 status=final]
741
742 [xsl:params]
743 $node: The node a page is being created for.
744
745 This template is a stub, called by {html.page}. It is called inside the `main`
746 element, before the `div.page` element. The `main` element uses a horizontal
747 flexbox by default. You can override this template to provide sidebar content.
748 Note that there is only one extension point for sidebar content, and it is
749 always placed before the main content in document order. To create a sidebar
750 on the right, output the element here, then adjust the `order` CSS property
751 for that element to display it after the `main` element.
752
753 This template is intended for completely custom sidebars. You can also use
754 {html.sidebar} to output sidebars with stock components.
755 -->
756 <xsl:template name="html.sidebar.custom">
757 <xsl:param name="node" select="."/>
758 </xsl:template>
759
760
761 <!--**==========================================================================
762 html.header.custom
763 Stub to output custom header content.
764 @xsl:stub
765 @revision[version=3.28 date=2017-05-24 status=final]
766
767 [xsl:params]
768 $node: The node a page is being created for.
769
770 This template is a stub, called by {html.page}. It is called inside the
771 `header` element, before {html.header.mode} is applied to `node`. You can
772 override this template to provide additional content above the main content.
773 -->
774 <xsl:template name="html.header.custom">
775 <xsl:param name="node" select="."/>
776 </xsl:template>
777
778
779 <!--%%==========================================================================
780 html.header.mode
781 Output the header content for an element.
782 @revision[version=3.28 date=2017-05-24 status=final]
783
784 This mode is called by {html.page} to output the contents of the `header`
785 element above the main content. Importing stylesheets may implement this mode
786 for any element that will be passed to {html.page}. If they do not, the
787 `header` element will be empty by default.
788 -->
789 <xsl:template mode="html.header.mode" match="*"/>
790
791
792 <!--**==========================================================================
793 html.footer.custom
794 Stub to output custom footer content.
795 @xsl:stub
796 @revision[version=3.28 date=2017-05-24 status=final]
797
798 [xsl:params]
799 $node: The node a page is being created for.
800
801 This template is a stub, called by {html.page}. It is called inside the
802 `footer` element, after {html.footer.mode} is applied to $node. You can
803 override this template to provide additional content below the main content.
804 -->
805 <xsl:template name="html.footer.custom">
806 <xsl:param name="node" select="."/>
807 </xsl:template>
808
809
810 <!--%%==========================================================================
811 html.footer.mode
812 Output the footer content for an element.
813 @revision[version=3.28 date=2017-05-24 status=final]
814
815 This mode is called by {html.page} to output the contents of the `footer`
816 element below the main content. Importing stylesheets may implement this mode
817 for any element that will be passed to {html.page}. If they do not, the
818 `footer` element will be empty by default.
819 -->
820 <xsl:template mode="html.footer.mode" match="*"/>
821
822
823 <!--%%==========================================================================
824 html.body.mode
825 Output the main contents for an element.
826 @revision[version=1.0 date=2010-05-26 status=final]
827
828 This mode is called by {html.page} to output the main contents of an HTML
829 page, below the header content and above the footer content. Titles, block
830 content, and sections should be output in this mode.
831 -->
832 <xsl:template mode="html.body.mode" match="*"/>
833
834
835 <!--**==========================================================================
836 html.head.top.custom
837 Stub to output custom content at the beginning of the HTML `head` element.
838 @xsl:stub
839 @revision[version=3.28 date=2017-08-04 status=final]
840
841 [xsl:params]
842 $node: The node a page is being created for.
843
844 This template is a stub, called by {html.page}. You can override this template
845 to provide additional elements at the beginning of the HTML `head` element of
846 output files. This template is called before all other head content.
847 -->
848 <xsl:template name="html.head.top.custom">
849 <xsl:param name="node" select="."/>
850 </xsl:template>
851
852
853 <!--**==========================================================================
854 html.head.custom
855 Stub to output custom content at the end of the HTML `head` element.
856 @xsl:stub
857 @revision[version=3.28 date=2017-08-04 status=final]
858
859 [xsl:params]
860 $node: The node a page is being created for.
861
862 This template is a stub, called by {html.page}. You can override this template
863 to provide additional elements in the HTML `head` element of output files.
864 This template is called after all other head content.
865 -->
866 <xsl:template name="html.head.custom">
867 <xsl:param name="node" select="."/>
868 </xsl:template>
869
870
871 <!--**==========================================================================
872 html.linktrails.empty
873 Stub to output something when no link trails are present.
874 @xsl:stub
875 @revision[version=3.28 date=2017-05-24 status=final]
876
877 [xsl:params]
878 $node: The source element a page is bring created for.
879
880 This template is a stub. It is called by templates that output link trails when
881 there are no link trails to output. Some customizations prepend extra site links
882 to link trails. This template allows them to output those links even when no link
883 trails would otherwise be present.
884 -->
885 <xsl:template name="html.linktrails.empty">
886 <xsl:param name="node" select="."/>
887 </xsl:template>
888
889
890 <!--**==========================================================================
891 html.linktrails.prefix
892 Stub to output extra content before a link trail.
893 @xsl:stub
894 @revision[version=42 date=2021-10-30 status=final]
895
896 [xsl:params]
897 $page: The source element for which an output page is being made.
898 $node: A source-specific element providing information about the link trail.
899
900 This template is a stub. It is called by templates that output link trails
901 before the normal links are output. This template is useful for adding extra
902 site links at the beginning of each link trail.
903
904 [note .plain]
905 The $page parameter was added in version 42.
906 -->
907 <xsl:template name="html.linktrails.prefix">
908 <xsl:param name="page" select="."/>
909 <xsl:param name="node" select="."/>
910 </xsl:template>
911
912
913 <!--**==========================================================================
914 html.class.attr
915 Output a `class` attribute for an HTML element.
916 @revision[version=3.10 date=2013-07-10 status=final]
917
918 [xsl:params]
919 $node: The source node for which an HTML element is being output.
920 $class: The value of the `class` attribute provided by the calling template.
921
922 This template is called by templates that output an HTML element corresponding
923 to a source element. This template applies {html.class.attr.mode} to $node
924 to gather a value from extensions stylesheets. It combines this value with the
925 value passed in the $class parameter and, if the result is non-empty, outputs
926 a `class` attribute.
927 -->
928 <xsl:template name="html.class.attr">
929 <xsl:param name="node" select="."/>
930 <xsl:param name="class"/>
931 <xsl:variable name="fclass">
932 <xsl:value-of select="$class"/>
933 <xsl:text> </xsl:text>
934 <xsl:apply-templates mode="html.class.attr.mode" select="$node"/>
935 </xsl:variable>
936 <xsl:variable name="nclass" select="normalize-space($fclass)"/>
937 <xsl:if test="$nclass != ''">
938 <xsl:attribute name="class">
939 <xsl:value-of select="normalize-space($nclass)"/>
940 </xsl:attribute>
941 </xsl:if>
942 </xsl:template>
943
944
945 <!--%%==========================================================================
946 html.class.attr.mode
947 Output additional values for an HTML `class` attribute.
948 @revision[version=3.10 date=2013-07-10 status=final]
949
950 This mode is called by {html.class.attr} on a source element. This mode is
951 intended for extensions to have an easy way to add additional HTML class values
952 for styling.
953
954 Note that these stylesheets use CSS classes extensively for styling and for
955 certain JavaScript functionality. Extensions should be careful to output class
956 values that do not conflict with those used in these stylesheets.
957 -->
958 <xsl:template mode="html.class.attr.mode" match="*"/>
959
960
961 <!--**==========================================================================
962 html.content.pre
963 Output content before the content of a page or section.
964 @revision[version=3.28 date=2016-06-21 status=final]
965
966 [xsl:params]
967 $node: The node a page or section is being created for.
968 $page: Whether the content is for a page.
969
970 This template is called by importing stylesheets before any content of a page
971 or section, but after the title. It calls {html.content.pre.custom}, then
972 applies {html.content.pre.mode} to $node. If the $page parameter is true,
973 then this template is being called on an output page. Otherwise, it is being
974 called on a section within a page.
975 -->
976 <xsl:template name="html.content.pre">
977 <xsl:param name="node" select="."/>
978 <xsl:param name="page" select="true()"/>
979 <xsl:call-template name="html.content.pre.custom">
980 <xsl:with-param name="node" select="$node"/>
981 <xsl:with-param name="page" select="$page"/>
982 </xsl:call-template>
983 <xsl:apply-templates mode="html.content.pre.mode" select="$node">
984 <xsl:with-param name="page" select="$page"/>
985 </xsl:apply-templates>
986 </xsl:template>
987
988
989 <!--**==========================================================================
990 html.content.pre.custom
991 Stub to output content before the content of a page or section.
992 @xsl:stub
993 @revision[version=3.28 date=2016-06-21 status=final]
994
995 [xsl:params]
996 $node: The node a page or section is being created for.
997 $page: Whether the content is for a page.
998
999 This template is a stub, called by {html.content.pre.custom}. It is called
1000 before {html.content.pre.mode} is applied. Override this template to provide
1001 site-specific HTML before the content of a page or section. If the $page
1002 parameter is true, then this template is being called on an output page.
1003 Otherwise, it is being called on a section within a page.
1004 -->
1005 <xsl:template name="html.content.pre.custom">
1006 <xsl:param name="node" select="."/>
1007 <xsl:param name="page" select="true()"/>
1008 </xsl:template>
1009
1010
1011 <!--%%==========================================================================
1012 html.content.pre.mode
1013 Output content before the content of a page or section.
1014 @revision[version=3.28 date=2016-06-21 status=final]
1015
1016 [xsl:params]
1017 $page: Whether the content is for a page.
1018
1019 This mode is applied by {html.content.pre} after calling
1020 {html.content.pre.custom}. Importing stylesheets can use this to add
1021 additional content for specific types of input elements before the content
1022 of a page or section. If the $page parameter is true, then this template
1023 is being called on an output page. Otherwise, it is being called on a section
1024 within a page.
1025 -->
1026 <xsl:template mode="html.content.pre.mode" match="*">
1027 <xsl:param name="page" select="true()"/>
1028 </xsl:template>
1029
1030
1031 <!--**==========================================================================
1032 html.content.post
1033 Output content after the content of a page or section, before subsections.
1034 @revision[version=3.28 date=2016-06-21 status=final]
1035
1036 [xsl:params]
1037 $node: The node a page or section is being created for.
1038 $page: Whether the content is for a page.
1039
1040 This template is called by importing stylesheets after any content of a page
1041 or section, but before any subsections. It applies {html.content.post.mode}
1042 to $node, then calls {html.content.post.custom}. If the $page parameter
1043 is true, then this template is being called on an output page. Otherwise, it
1044 is being called on a section within a page.
1045 -->
1046 <xsl:template name="html.content.post">
1047 <xsl:param name="node" select="."/>
1048 <xsl:param name="page" select="true()"/>
1049 <xsl:apply-templates mode="html.content.post.mode" select="$node">
1050 <xsl:with-param name="page" select="$page"/>
1051 </xsl:apply-templates>
1052 <xsl:call-template name="html.content.post.custom">
1053 <xsl:with-param name="node" select="$node"/>
1054 <xsl:with-param name="page" select="$page"/>
1055 </xsl:call-template>
1056 </xsl:template>
1057
1058
1059 <!--**==========================================================================
1060 html.content.post.custom
1061 Stub to output content after the content of a page or section, before subsections.
1062 @xsl:stub
1063 @revision[version=3.28 date=2016-06-21 status=final]
1064
1065 [xsl:params]
1066 $node: The node a page or section is being created for.
1067 $page: Whether the content is for a page.
1068
1069 This template is a stub, called by {html.content.post.custom}. It is called
1070 after {html.content.pre.mode} is applied. Override this template to provide
1071 site-specific HTML after the content of a page or section, but before any
1072 subsections. If the $page parameter is true, then this template is being
1073 called on an output page. Otherwise, it is being called on a section within
1074 a page.
1075 -->
1076 <xsl:template name="html.content.post.custom">
1077 <xsl:param name="node" select="."/>
1078 <xsl:param name="page" select="true()"/>
1079 </xsl:template>
1080
1081
1082 <!--%%==========================================================================
1083 html.content.post.mode
1084 Output content after the content of a page or section, before subsections.
1085 @revision[version=3.28 date=2016-06-21 status=final]
1086
1087 [xsl:params]
1088 $page: Whether the content is for a page.
1089
1090 This mode is applied by {html.content.post} before calling
1091 {html.content.post.custom}. Importing stylesheets can use this to add
1092 additional content for specific types of input elements after the content
1093 of a page or section, but before any subsections. If the $page parameter
1094 is true, then this template is being called on an output page. Otherwise,
1095 it is being called on a section within a page.
1096 -->
1097 <xsl:template mode="html.content.post.mode" match="*">
1098 <xsl:param name="page" select="true()"/>
1099 </xsl:template>
1100
1101
1102 <!--**==========================================================================
1103 html.css
1104 Output all CSS for an HTML output page.
1105 @revision[version=1.0 date=2010-12-23 status=final]
1106
1107 [xsl:params]
1108 $node: The node to create CSS for.
1109 $direction: The directionality of the text, either `ltr` or `rtl`.
1110 $left: The starting alignment, either `left` or `right`.
1111 $right: The ending alignment, either `left` or `right`.
1112
1113 This template creates the CSS for an HTML output page, including the enclosing
1114 HTML `style` element. It calls the templates {html.css.content} to output the
1115 actual CSS contents.
1116
1117 The $direction parameter specifies the directionality of the text for the
1118 language of the document. The $left and $right parameters are based on
1119 $direction, and can be used to set beginning and ending margins or other
1120 dimensions. All parameters can be automatically computed if not provided.
1121 -->
1122 <xsl:template name="html.css">
1123 <xsl:param name="node" select="."/>
1124 <xsl:param name="direction">
1125 <xsl:call-template name="l10n.direction">
1126 <xsl:with-param name="node" select="$node"/>
1127 </xsl:call-template>
1128 </xsl:param>
1129 <xsl:param name="left">
1130 <xsl:call-template name="l10n.align.start">
1131 <xsl:with-param name="direction" select="$direction"/>
1132 </xsl:call-template>
1133 </xsl:param>
1134 <xsl:param name="right">
1135 <xsl:call-template name="l10n.align.end">
1136 <xsl:with-param name="direction" select="$direction"/>
1137 </xsl:call-template>
1138 </xsl:param>
1139 <style type="text/css">
1140 <xsl:if test="$html.csp.nonce">
1141 <xsl:attribute name="nonce">
1142 <xsl:value-of select="$html.csp.nonce" />
1143 </xsl:attribute>
1144 </xsl:if>
1145 <xsl:call-template name="html.css.content">
1146 <xsl:with-param name="node" select="$node"/>
1147 <xsl:with-param name="direction" select="$direction"/>
1148 <xsl:with-param name="left" select="$left"/>
1149 <xsl:with-param name="right" select="$right"/>
1150 </xsl:call-template>
1151 </style>
1152 </xsl:template>
1153
1154
1155 <!--**==========================================================================
1156 html.css.content
1157 Output actual CSS content for an HTML output page.
1158 @revision[version=1.0 date=2010-12-23 status=final]
1159
1160 [xsl:params]
1161 $node: The node to create CSS for.
1162 $direction: The directionality of the text, either `ltr` or `rtl`.
1163 $left: The starting alignment, either `left` or `right`.
1164 $right: The ending alignment, either `left` or `right`.
1165
1166 This template creates the CSS content for an HTML output page. It is called by
1167 {html.css}. It calls the templates {html.css.core}, {html.css.elements}, and
1168 {html.css.syntax}. It then calls the mode {html.css.mode} on $node and
1169 calls the template {html.css.custom}.
1170 -->
1171 <xsl:template name="html.css.content">
1172 <xsl:param name="node" select="."/>
1173 <xsl:param name="direction">
1174 <xsl:call-template name="l10n.direction">
1175 <xsl:with-param name="node" select="$node"/>
1176 </xsl:call-template>
1177 </xsl:param>
1178 <xsl:param name="left">
1179 <xsl:call-template name="l10n.align.start">
1180 <xsl:with-param name="direction" select="$direction"/>
1181 </xsl:call-template>
1182 </xsl:param>
1183 <xsl:param name="right">
1184 <xsl:call-template name="l10n.align.end">
1185 <xsl:with-param name="direction" select="$direction"/>
1186 </xsl:call-template>
1187 </xsl:param>
1188 <xsl:call-template name="html.css.core">
1189 <xsl:with-param name="node" select="$node"/>
1190 <xsl:with-param name="direction" select="$direction"/>
1191 <xsl:with-param name="left" select="$left"/>
1192 <xsl:with-param name="right" select="$right"/>
1193 </xsl:call-template>
1194 <xsl:call-template name="html.css.elements">
1195 <xsl:with-param name="node" select="$node"/>
1196 <xsl:with-param name="direction" select="$direction"/>
1197 <xsl:with-param name="left" select="$left"/>
1198 <xsl:with-param name="right" select="$right"/>
1199 </xsl:call-template>
1200 <xsl:call-template name="html.css.syntax">
1201 <xsl:with-param name="node" select="$node"/>
1202 <xsl:with-param name="direction" select="$direction"/>
1203 <xsl:with-param name="left" select="$left"/>
1204 <xsl:with-param name="right" select="$right"/>
1205 </xsl:call-template>
1206 <xsl:apply-templates mode="html.css.mode" select="$node">
1207 <xsl:with-param name="direction" select="$direction"/>
1208 <xsl:with-param name="left" select="$left"/>
1209 <xsl:with-param name="right" select="$right"/>
1210 </xsl:apply-templates>
1211 <xsl:call-template name="html.css.custom">
1212 <xsl:with-param name="node" select="$node"/>
1213 <xsl:with-param name="direction" select="$direction"/>
1214 <xsl:with-param name="left" select="$left"/>
1215 <xsl:with-param name="right" select="$right"/>
1216 </xsl:call-template>
1217 </xsl:template>
1218
1219
1220 <!--%%==========================================================================
1221 html.css.mode
1222 Output CSS specific to the input format.
1223 @revision[version=1.0 date=2010-05-26 status=final]
1224
1225 [xsl:params]
1226 $direction: The directionality of the text, either `ltr` or `rtl`.
1227 $left: The starting alignment, either `left` or `right`.
1228 $right: The ending alignment, either `left` or `right`.
1229
1230 This template is called by {html.css.content} to output CSS specific to the
1231 input format. Importing stylesheets may implement this for any element that
1232 will be passed to {html.page}. If they do not, the output HTML will only have
1233 the common CSS.
1234 -->
1235 <xsl:template mode="html.css.mode" match="*">
1236 <xsl:param name="direction">
1237 <xsl:call-template name="l10n.direction"/>
1238 </xsl:param>
1239 <xsl:param name="left">
1240 <xsl:call-template name="l10n.align.start">
1241 <xsl:with-param name="direction" select="$direction"/>
1242 </xsl:call-template>
1243 </xsl:param>
1244 <xsl:param name="right">
1245 <xsl:call-template name="l10n.align.end">
1246 <xsl:with-param name="direction" select="$direction"/>
1247 </xsl:call-template>
1248 </xsl:param>
1249 </xsl:template>
1250
1251
1252 <!--**==========================================================================
1253 html.css.core
1254 Output CSS that does not reference source elements.
1255 @revision[version=1.0 date=2010-05-25 status=final]
1256
1257 [xsl:params]
1258 $node: The node to create CSS for.
1259 $direction: The directionality of the text, either `ltr` or `rtl`.
1260 $left: The starting alignment, either `left` or `right`.
1261 $right: The ending alignment, either `left` or `right`.
1262
1263 This template outputs CSS that can be used in any HTML. It does not reference
1264 elements from DocBook, Mallard, or other source languages. It provides the
1265 common spacings for block-level elements like paragraphs and lists, defines
1266 styles for links, and defines four common wrapper divs: `header`, `side`,
1267 `body`, and `footer`.
1268
1269 This template uses text templates to keep the actual CSS content in a
1270 separate file, `css/core.css.tmpl`, and do simple param substitutions.
1271 This makes it easier to update the CSS without working with XSLT.
1272
1273 All parameters can be automatically computed if not provided.
1274 -->
1275 <xsl:template name="html.css.core">
1276 <xsl:param name="node" select="."/>
1277 <xsl:param name="direction">
1278 <xsl:call-template name="l10n.direction">
1279 <xsl:with-param name="node" select="$node"/>
1280 </xsl:call-template>
1281 </xsl:param>
1282 <xsl:param name="left">
1283 <xsl:call-template name="l10n.align.start">
1284 <xsl:with-param name="direction" select="$direction"/>
1285 </xsl:call-template>
1286 </xsl:param>
1287 <xsl:param name="right">
1288 <xsl:call-template name="l10n.align.end">
1289 <xsl:with-param name="direction" select="$direction"/>
1290 </xsl:call-template>
1291 </xsl:param>
1292 <xsl:call-template name="tmpl.file">
1293 <xsl:with-param name="file" select="'css/core.css.tmpl'"/>
1294 <xsl:with-param name="node" select="$node"/>
1295 <xsl:with-param name="direction" select="$direction"/>
1296 <xsl:with-param name="left" select="$left"/>
1297 <xsl:with-param name="right" select="$right"/>
1298 </xsl:call-template>
1299 </xsl:template>
1300
1301
1302 <!--**==========================================================================
1303 html.css.elements
1304 Output CSS for common elements from source formats.
1305 @revision[version=1.0 date=2010-05-25 status=final]
1306
1307 [xsl:params]
1308 $node: The node to create CSS for.
1309 $direction: The directionality of the text, either `ltr` or `rtl`.
1310 $left: The starting alignment, either `left` or `right`.
1311 $right: The ending alignment, either `left` or `right`.
1312
1313 This template outputs CSS for elements from source languages like DocBook and
1314 Mallard. It defines them using common class names. The common names are often
1315 the simpler element names from Mallard, although there some class names which
1316 are not taken from Mallard. Stylesheets which convert to HTML should use the
1317 appropriate common classes.
1318
1319 This template uses text templates to keep the actual CSS content in a
1320 separate file, `css/elements.css.tmpl`, and do simple param substitutions.
1321 This makes it easier to update the CSS without working with XSLT.
1322
1323 All parameters can be automatically computed if not provided.
1324 -->
1325 <xsl:template name="html.css.elements">
1326 <xsl:param name="node" select="."/>
1327 <xsl:param name="direction">
1328 <xsl:call-template name="l10n.direction">
1329 <xsl:with-param name="node" select="$node"/>
1330 </xsl:call-template>
1331 </xsl:param>
1332 <xsl:param name="left">
1333 <xsl:call-template name="l10n.align.start">
1334 <xsl:with-param name="direction" select="$direction"/>
1335 </xsl:call-template>
1336 </xsl:param>
1337 <xsl:param name="right">
1338 <xsl:call-template name="l10n.align.end">
1339 <xsl:with-param name="direction" select="$direction"/>
1340 </xsl:call-template>
1341 </xsl:param>
1342 <!-- Almost everything is in the text template file, except there's
1343 these two bits that aren't because XPath alone can't handle
1344 them. We could precompute and pass params, but I'm hesitant
1345 to add special-purpose params, which are API. -->
1346 <xsl:call-template name="tmpl.file">
1347 <xsl:with-param name="file" select="'css/elements.css.tmpl'"/>
1348 <xsl:with-param name="node" select="$node"/>
1349 <xsl:with-param name="direction" select="$direction"/>
1350 <xsl:with-param name="left" select="$left"/>
1351 <xsl:with-param name="right" select="$right"/>
1352 </xsl:call-template>
1353 <!-- FIXME: I don't like this at all. We use a character as the
1354 blockquote icon, which requires a whole font, and which random
1355 internet users might not have. Let's make SVGs and use the same
1356 icon embedding we use for notes. -->
1357 <xsl:variable name="quote">
1358 <xsl:for-each select="$node[1]">
1359 <xsl:call-template name="l10n.gettext">
1360 <xsl:with-param name="msgid" select="'quote.format'"/>
1361 <xsl:with-param name="node" select="$node"/>
1362 </xsl:call-template>
1363 </xsl:for-each>
1364 </xsl:variable>
1365 <xsl:variable name="quotc" select="substring(concat($quote, '“'), 1, 1)"/>
1366 <xsl:text>div.quote > div.inner:before { float: </xsl:text>
1367 <xsl:value-of select="$left"/>
1368 <xsl:text>content: '</xsl:text>
1369 <xsl:choose>
1370 <xsl:when test="contains('«‹', $quotc)">
1371 <xsl:text>«</xsl:text>
1372 </xsl:when>
1373 <xsl:when test="contains('»›', $quotc)">
1374 <xsl:text>»</xsl:text>
1375 </xsl:when>
1376 <xsl:when test="contains('”„’‚', $quotc)">
1377 <xsl:text>”</xsl:text>
1378 </xsl:when>
1379 <xsl:otherwise>
1380 <xsl:text>“</xsl:text>
1381 </xsl:otherwise>
1382 </xsl:choose>
1383 <xsl:text>';
1384 font-family: "Century Schoolbook L";
1385 font-size: {{$icons.size.quote}}px;
1386 font-weight: bold;
1387 line-height: </xsl:text>
1388 <xsl:choose>
1389 <xsl:when test="contains('«»‹›', $quotc)">
1390 <xsl:text>0.5</xsl:text>
1391 </xsl:when>
1392 <xsl:otherwise>
1393 <xsl:text>1</xsl:text>
1394 </xsl:otherwise>
1395 </xsl:choose><xsl:text>em;
1396 margin: 0; padding: 0;
1397 height: {{$icons.size.quote}}px;
1398 width: {{$icons.size.quote}}px;
1399 text-align: center;
1400 color: {{$color.bg.dark}};
1401 }</xsl:text>
1402 <!-- Surely we should be able to figure out a way to conditionalize
1403 the rotation direction in the text templates, or handle this a
1404 different way. -->
1405 <xsl:text>.ui-expander-e > div.inner > div.title span.title:before, </xsl:text>
1406 <xsl:text>.ui-expander-e > div.inner > div.hgroup span.title:before {</xsl:text>
1407 <xsl:choose>
1408 <xsl:when test="$direction = 'rtl'">
1409 <xsl:text>transform: translateY(0.2em) rotate(-180deg);</xsl:text>
1410 </xsl:when>
1411 <xsl:otherwise>
1412 <xsl:text>transform: translateY(0.2em) rotate(180deg);</xsl:text>
1413 </xsl:otherwise>
1414 </xsl:choose>
1415 <xsl:text>}</xsl:text>
1416 </xsl:template>
1417
1418
1419 <!--**==========================================================================
1420 html.css.syntax
1421 Output CSS for syntax highlighting.
1422 @revision[version=1.0 date=2010-12-06 status=final]
1423
1424 [xsl:params]
1425 $node: The node to create CSS for.
1426 $direction: The directionality of the text, either `ltr` or `rtl`.
1427 $left: The starting alignment, either `left` or `right`.
1428 $right: The ending alignment, either `left` or `right`.
1429
1430 This template outputs CSS to support syntax highlighting of code blocks. Syntax
1431 highlighting is done at document load time with JavaScript. Text in code blocks
1432 is broken up into chunks and wrapped in HTML elements with particular classes.
1433 This template outputs CSS to match those elements and style them with the
1434 built-in themeable colors from {color}.
1435
1436 This template uses text templates to keep the actual CSS content in a
1437 separate file, `css/syntax.css.tmpl`, and do simple param substitutions.
1438 This makes it easier to update the CSS without working with XSLT.
1439
1440 All parameters can be automatically computed if not provided.
1441 -->
1442 <xsl:template name="html.css.syntax">
1443 <xsl:param name="node" select="."/>
1444 <xsl:param name="direction">
1445 <xsl:call-template name="l10n.direction">
1446 <xsl:with-param name="node" select="$node"/>
1447 </xsl:call-template>
1448 </xsl:param>
1449 <xsl:param name="left">
1450 <xsl:call-template name="l10n.align.start">
1451 <xsl:with-param name="direction" select="$direction"/>
1452 </xsl:call-template>
1453 </xsl:param>
1454 <xsl:param name="right">
1455 <xsl:call-template name="l10n.align.end">
1456 <xsl:with-param name="direction" select="$direction"/>
1457 </xsl:call-template>
1458 </xsl:param>
1459 <xsl:if test="$html.syntax.highlight">
1460 <xsl:call-template name="tmpl.file">
1461 <xsl:with-param name="file" select="'css/syntax.css.tmpl'"/>
1462 <xsl:with-param name="node" select="$node"/>
1463 <xsl:with-param name="direction" select="$direction"/>
1464 <xsl:with-param name="left" select="$left"/>
1465 <xsl:with-param name="right" select="$right"/>
1466 </xsl:call-template>
1467 </xsl:if>
1468 </xsl:template>
1469
1470
1471 <!--**==========================================================================
1472 html.css.custom
1473 Stub to output custom CSS common to all HTML transformations.
1474 @xsl:stub
1475 @revision[version=1.0 date=2010-05-25 status=final]
1476
1477 [xsl:params]
1478 $node: The node to create CSS for.
1479 $direction: The directionality of the text, either `ltr` or `rtl`.
1480 $left: The starting alignment, either `left` or `right`.
1481 $right: The ending alignment, either `left` or `right`.
1482
1483 This template is a stub, called by {html.css.content}. You can override this
1484 template to provide additional CSS that will be used by all HTML output.
1485 -->
1486 <xsl:template name="html.css.custom">
1487 <xsl:param name="node" select="."/>
1488 <xsl:param name="direction">
1489 <xsl:call-template name="l10n.direction">
1490 <xsl:with-param name="node" select="$node"/>
1491 </xsl:call-template>
1492 </xsl:param>
1493 <xsl:param name="left">
1494 <xsl:call-template name="l10n.align.start">
1495 <xsl:with-param name="direction" select="$direction"/>
1496 </xsl:call-template>
1497 </xsl:param>
1498 <xsl:param name="right">
1499 <xsl:call-template name="l10n.align.end">
1500 <xsl:with-param name="direction" select="$direction"/>
1501 </xsl:call-template>
1502 </xsl:param>
1503 </xsl:template>
1504
1505
1506 <!--**==========================================================================
1507 html.js
1508 Output all JavaScript for an HTML output page.
1509 @revision[version=3.28 date=2017-07-05 status=final]
1510
1511 [xsl:params]
1512 $node: The node to create JavaScript for.
1513
1514 This template creates the JavaScript for an HTML output page. It calls the
1515 templates {html.js.syntax} and {html.js.mathjax} to output references to
1516 external libraries. It then calls {html.js.custom} to output references to
1517 custom JavaScript files. Finally, it calls {html.js.script} to output local
1518 JavaScript created by {html.js.content}.
1519 -->
1520 <xsl:template name="html.js">
1521 <xsl:param name="node" select="."/>
1522 <xsl:call-template name="html.js.syntax">
1523 <xsl:with-param name="node" select="$node"/>
1524 </xsl:call-template>
1525 <xsl:call-template name="html.js.mathjax">
1526 <xsl:with-param name="node" select="$node"/>
1527 </xsl:call-template>
1528 <xsl:call-template name="html.js.custom">
1529 <xsl:with-param name="node" select="$node"/>
1530 </xsl:call-template>
1531 <xsl:call-template name="html.js.script">
1532 <xsl:with-param name="node" select="$node"/>
1533 </xsl:call-template>
1534 </xsl:template>
1535
1536
1537 <!--**==========================================================================
1538 html.js.mathjax
1539 Output a `script` element to include MathJax.
1540 @revision[version=1.0 date=2012-11-13 status=final]
1541
1542 [xsl:params]
1543 $node: The node to create JavaScript for.
1544
1545 This template outputs an HTML `script` tag to reference MathJax. It only
1546 outputs a `script` element if $node has MathML descendent content. By
1547 default, this template uses `cdn.mathjax.org`. If you wish to use a local
1548 copy, override this template and provide the necessary files.
1549 -->
1550 <xsl:template name="html.js.mathjax">
1551 <xsl:param name="node" select="."/>
1552 <xsl:if test="$node//mml:*[1]">
1553 <script type="text/javascript">
1554 <xsl:if test="$html.csp.nonce">
1555 <xsl:attribute name="nonce">
1556 <xsl:value-of select="$html.csp.nonce" />
1557 </xsl:attribute>
1558 </xsl:if>
1559 <xsl:attribute name="src">
1560 <xsl:text>http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=MML_HTMLorMML</xsl:text>
1561 </xsl:attribute>
1562 </script>
1563 </xsl:if>
1564 </xsl:template>
1565
1566
1567 <!--**==========================================================================
1568 html.js.script
1569 Output a JavaScript `script` tag containing local content.
1570 @revision[version=3.28 date=2017-05-24 status=final]
1571
1572 [xsl:params]
1573 $node: The node to create JavaScript for.
1574
1575 This template is called by {html.js} to output JavaScript content. It outputs
1576 a `script` tag and calls {html.js.content} to output the contents. To force
1577 all JavaScript into external files, override this template to output a `script`
1578 tag referencing an external file with the `src` attribute, then output the
1579 result of {html.js.content} to that file.
1580 -->
1581 <xsl:template name="html.js.script">
1582 <xsl:param name="node" select="."/>
1583 <script type="text/javascript">
1584 <xsl:if test="$html.csp.nonce">
1585 <xsl:attribute name="nonce">
1586 <xsl:value-of select="$html.csp.nonce" />
1587 </xsl:attribute>
1588 </xsl:if>
1589 <xsl:call-template name="html.js.content">
1590 <xsl:with-param name="node" select="$node"/>
1591 </xsl:call-template>
1592 </script>
1593 </xsl:template>
1594
1595
1596 <!--**==========================================================================
1597 html.js.content
1598 Output JavaScript content for an HTML output page.
1599 @revision[version=3.28 date=2017-07-05 status=final]
1600
1601 [xsl:params]
1602 $node: The node to create JavaScript for.
1603
1604 This template is called by {html.js.script} to output JavaScript content. It
1605 does not output an HTML `script` tag. This template calls the templates
1606 {html.js.core}, {html.js.ui}, and {html.js.media}. It then calls the mode
1607 {html.js.mode} on $node and calls the template {html.js.content.custom}.
1608 -->
1609 <xsl:template name="html.js.content">
1610 <xsl:param name="node" select="."/>
1611 <xsl:call-template name="html.js.core">
1612 <xsl:with-param name="node" select="$node"/>
1613 </xsl:call-template>
1614 <xsl:call-template name="html.js.ui">
1615 <xsl:with-param name="node" select="$node"/>
1616 </xsl:call-template>
1617 <xsl:call-template name="html.js.media">
1618 <xsl:with-param name="node" select="$node"/>
1619 </xsl:call-template>
1620 <xsl:apply-templates mode="html.js.mode" select="$node"/>
1621 <xsl:call-template name="html.js.content.custom">
1622 <xsl:with-param name="node" select="$node"/>
1623 </xsl:call-template>
1624 </xsl:template>
1625
1626
1627 <!--**==========================================================================
1628 html.js.core
1629 Output JavaScript for core features.
1630 @revision[version=3.4 date=2011-11-04 status=final]
1631
1632 [xsl:params]
1633 $node: The node to create JavaScript for.
1634
1635 This template outputs JavaScript to support basic features used by all documents.
1636 Currently, it outputs code to highlight a section when `location.hash` is set.
1637 -->
1638 <xsl:template name="html.js.core">
1639 <xsl:param name="node" select="."/>
1640 <xsl:text>
1641 document.addEventListener('DOMContentLoaded', function() {
1642 var yelp_hash_highlight = function () {
1643 if (location.hash != '') {
1644 var sect = document.querySelector(location.hash);
1645 if (sect != null) {
1646 sect.classList.add('yelp-hash-highlight');
1647 window.setTimeout(function () {
1648 sect.classList.remove('yelp-hash-highlight');
1649 }, 500);
1650 }
1651 }
1652 }
1653 window.addEventListener('hashchange', yelp_hash_highlight, false);
1654 yelp_hash_highlight();
1655 }, false);
1656 </xsl:text>
1657 </xsl:template>
1658
1659
1660 <!--**==========================================================================
1661 html.js.ui
1662 Output JavaScript for UI extensions.
1663 @revision[version=1.0 date=2011-06-17 status=final]
1664
1665 [xsl:params]
1666 $node: The node to create JavaScript for.
1667
1668 This template outputs JavaScript that implements certain common UI extensions,
1669 such as expandable blocks and sections.
1670 -->
1671 <xsl:template name="html.js.ui">
1672 <xsl:param name="node" select="."/>
1673 <xsl:text><![CDATA[
1674 var __yelp_generate_id_counter__ = 0;
1675 function yelp_generate_id () {
1676 var ret = 'yelp--' + (++__yelp_generate_id_counter__).toString();
1677 if (document.getElementById(ret) != null)
1678 return yelp_generate_id();
1679 else
1680 return ret;
1681 };
1682 function yelp_ui_expander_init (expander) {
1683 var yelpdata = null;
1684 var innerdiv = null;
1685 var region = null;
1686 var contents = null;
1687 var title = null;
1688 var title_e = null;
1689 var title_c = null;
1690 var titlespan = null;
1691 var issect = false;
1692 for (var i = 0; i < expander.children.length; i++) {
1693 var child = expander.children[i];
1694 if (child.classList.contains('yelp-data-ui-expander')) {
1695 yelpdata = child;
1696 }
1697 else if (child.classList.contains('inner')) {
1698 innerdiv = child;
1699 }
1700 }
1701 if (innerdiv == null) {
1702 return;
1703 }
1704 for (var i = 0; i < innerdiv.children.length; i++) {
1705 var child = innerdiv.children[i];
1706 if (child.classList.contains('region')) {
1707 region = child;
1708 }
1709 else if (child.classList.contains('title')) {
1710 title = child;
1711 }
1712 else if (child.classList.contains('hgroup')) {
1713 title = child;
1714 issect = true;
1715 }
1716 }
1717 if (region == null || title == null) {
1718 return;
1719 }
1720 if (!region.hasAttribute('id')) {
1721 region.setAttribute('id', yelp_generate_id());
1722 }
1723 title.setAttribute('aria-controls', region.getAttribute('id'));
1724
1725 if (yelpdata != null) {
1726 for (var i = 0; i < yelpdata.children.length; i++) {
1727 var child = yelpdata.children[i];
1728 if (child.classList.contains('yelp-title-expanded')) {
1729 title_e = child;
1730 }
1731 else if (child.classList.contains('yelp-title-collapsed')) {
1732 title_c = child;
1733 }
1734 }
1735 }
1736 titlespan = title.querySelector('span.title');
1737 if (titlespan == null) {
1738 return;
1739 }
1740 if (title_e == null) {
1741 var node = document.createElement('div');
1742 node.className = 'yelp-title-expanded';
1743 node.innerHTML = titlespan.innerHTML;
1744 yelpdata.appendChild(node);
1745 title_e = node;
1746 }
1747 if (title_c == null) {
1748 var node = document.createElement('div');
1749 node.className = 'yelp-title-collapsed';
1750 node.innerHTML = titlespan.innerHTML;
1751 yelpdata.appendChild(node);
1752 title_c = node;
1753 }
1754
1755 var ui_expander_zoom_region = function (event) {
1756 if (yelpdata.getAttribute('data-yelp-expanded') != 'false') {
1757 ui_expander_toggle();
1758 event.preventDefault();
1759 }
1760 }
1761 if (expander.nodeName == 'section' || expander.nodeName == 'SECTION') {
1762 for (var i = 0; i < region.children.length; i++) {
1763 var child = region.children[i];
1764 if (child.classList.contains('contents')) {
1765 contents = child;
1766 break;
1767 }
1768 }
1769 contents.addEventListener('click', ui_expander_zoom_region, true);
1770 }
1771 else {
1772 region.addEventListener('click', ui_expander_zoom_region, true);
1773 }
1774
1775 var ui_expander_toggle = function () {
1776 if (yelpdata.getAttribute('data-yelp-expanded') == 'false') {
1777 yelpdata.setAttribute('data-yelp-expanded', 'true');
1778 expander.classList.remove('ui-expander-e');
1779 expander.classList.add('ui-expander-c');
1780 region.setAttribute('aria-expanded', 'false');
1781 if (title_c != null)
1782 titlespan.innerHTML = title_c.innerHTML;
1783 }
1784 else {
1785 yelpdata.setAttribute('data-yelp-expanded', 'false');
1786 expander.classList.remove('ui-expander-c');
1787 expander.classList.add('ui-expander-e');
1788 region.setAttribute('aria-expanded', 'true');
1789 if (title_e != null)
1790 titlespan.innerHTML = title_e.innerHTML;
1791 }
1792 };
1793 expander.yelp_ui_expander_toggle = ui_expander_toggle;
1794 title.addEventListener('click', ui_expander_toggle, false);
1795 ui_expander_toggle();
1796 }
1797 document.addEventListener('DOMContentLoaded', function() {
1798 var matches = document.querySelectorAll('.ui-expander');
1799 for (var i = 0; i < matches.length; i++) {
1800 yelp_ui_expander_init(matches[i]);
1801 }
1802 var yelp_hash_ui_expand = function () {
1803 if (location.hash != '') {
1804 var sect = document.querySelector(location.hash);
1805 if (sect != null) {
1806 for (var cur = sect; cur instanceof Element; cur = cur.parentNode) {
1807 if (cur.classList.contains('ui-expander')) {
1808 if (cur.classList.contains('ui-expander-c')) {
1809 cur.yelp_ui_expander_toggle();
1810 }
1811 }
1812 }
1813 sect.scrollIntoView();
1814 }
1815 }
1816 };
1817 window.addEventListener('hashchange', yelp_hash_ui_expand, false);
1818 yelp_hash_ui_expand();
1819 }, false);
1820 ]]></xsl:text>
1821 </xsl:template>
1822
1823
1824 <!--**==========================================================================
1825 html.js.media
1826 Output JavaScript to control media elements.
1827 @revision[version=1.0 date=2010-01-01 status=final]
1828
1829 [xsl:params]
1830 $node: The node to create JavaScript for.
1831
1832 This template outputs JavaScript that controls media elements. It provides
1833 control for audio and video elements as well as support for captions.
1834 -->
1835 <xsl:template name="html.js.media">
1836 <xsl:param name="node" select="."/>
1837 <xsl:text><![CDATA[
1838 yelp_color_text_light = ']]></xsl:text>
1839 <xsl:value-of select="$color.fg.dark"/><xsl:text><![CDATA[';
1840 yelp_color_gray_background = ']]></xsl:text>
1841 <xsl:value-of select="$color.bg.gray"/><xsl:text><![CDATA[';
1842 yelp_color_gray_border = ']]></xsl:text>
1843 <xsl:value-of select="$color.gray"/><xsl:text><![CDATA[';
1844 function yelp_figure_init (figure) {
1845 var zoom = figure.querySelector('a.figure-zoom');
1846
1847 var figure_resize = function () {
1848 var zoomed = zoom.classList.contains('figure-zoomed');
1849 var imgs = figure.querySelectorAll('img');
1850 for (var i = 0; i < imgs.length; i++) {
1851 var img = imgs[i];
1852 var mediaDiv = null;
1853 for (var cur = img; cur instanceof Element; cur = cur.parentNode) {
1854 if ((cur.nodeName == 'div' || cur.nodeName == 'DIV') &&
1855 cur.classList.contains('media')) {
1856 mediaDiv = cur;
1857 break;
1858 }
1859 }
1860 if (mediaDiv == null)
1861 continue;
1862 if (!img.hasAttribute('data-yelp-original-width')) {
1863 var iwidth = null;
1864 if (img.hasAttribute('width'))
1865 iwidth = parseInt(img.getAttribute('width'));
1866 else
1867 iwidth = img.width;
1868 img.setAttribute('data-yelp-original-width', iwidth);
1869 var iheight = null;
1870 if (img.hasAttribute('height'))
1871 iheight = parseInt(img.getAttribute('height'));
1872 else
1873 iheight = img.height * (iwidth / img.width);
1874 img.setAttribute('data-yelp-original-height', iheight);
1875 }
1876 var owidth = img.width;
1877 var oheight = img.height;
1878 img.width = parseInt(img.getAttribute('data-yelp-original-width'));
1879 img.height = parseInt(img.getAttribute('data-yelp-original-height'));
1880 var mediaw = mediaDiv.offsetWidth;
1881 img.width = owidth;
1882 img.height = oheight;
1883 if (parseInt(img.getAttribute('data-yelp-original-width')) <= mediaw) {
1884 img.width = parseInt(img.getAttribute('data-yelp-original-width'));
1885 img.height = parseInt(img.getAttribute('data-yelp-original-height'));
1886 zoom.style.display = 'none';
1887 }
1888 else if (zoomed) {
1889 img.width = parseInt(img.getAttribute('data-yelp-original-width'));
1890 img.height = parseInt(img.getAttribute('data-yelp-original-height'));
1891 zoom.style.display = 'block';
1892 }
1893 else {
1894 img.width = mediaw;
1895 img.height = (parseInt(img.getAttribute('data-yelp-original-height')) *
1896 img.width /
1897 parseInt(img.getAttribute('data-yelp-original-width')));
1898 zoom.style.display = 'block';
1899 }
1900 }
1901 }
1902 figure.yelp_figure_resize = figure_resize;
1903 figure.yelp_figure_resize();
1904
1905 zoom.onclick = function (e) {
1906 var zoomed = zoom.classList.contains('figure-zoomed');
1907 if (zoomed)
1908 zoom.classList.remove('figure-zoomed');
1909 else
1910 zoom.classList.add('figure-zoomed');
1911 figure.yelp_figure_resize();
1912 return false;
1913 };
1914 }
1915 window.addEventListener('load', function() {
1916 var figures = document.querySelectorAll('div.figure');
1917 for (var i = 0; i < figures.length; i++) {
1918 if (figures[i].querySelector('img') != null)
1919 yelp_figure_init(figures[i]);
1920 }
1921 var timeout = null;
1922 var yelp_figures_resize = function () {
1923 if (timeout != null)
1924 return;
1925 timeout = window.setTimeout(function () {
1926 for (var i = 0; i < figures.length; i++) {
1927 if (figures[i].querySelector('img') != null)
1928 figures[i].yelp_figure_resize();
1929 }
1930 window.clearTimeout(timeout);
1931 timeout = null;
1932 }, 100);
1933 };
1934 window.addEventListener('resize', yelp_figures_resize, false);
1935 }, false);
1936 function yelp_media_init (media) {
1937 media.removeAttribute('controls');
1938 if (media.parentNode.classList.contains('links-tile-img')) {
1939 return;
1940 }
1941
1942 media.addEventListener('click', function () {
1943 if (media.paused)
1944 media.play();
1945 else
1946 media.pause();
1947 }, false);
1948
1949 var controls = null;
1950 for (var cur = media.nextSibling; cur instanceof Element; cur = cur.nextSibling) {
1951 if (cur.classList.contains('media-controls')) {
1952 controls = cur;
1953 break;
1954 }
1955 }
1956 if (controls == null) {
1957 media.setAttribute('controls', 'controls');
1958 return;
1959 }
1960 var playbutton = controls.querySelector('button.media-play');
1961 playbutton.addEventListener('click', function () {
1962 if (media.paused || media.ended)
1963 media.play();
1964 else
1965 media.pause();
1966 }, false);
1967
1968 var mediachange = function () {
1969 if (media.ended)
1970 media.pause()
1971 if (media.paused) {
1972 playbutton.setAttribute('value', playbutton.getAttribute('data-play-label'));
1973 playbutton.classList.remove('media-play-playing');
1974 }
1975 else {
1976 playbutton.setAttribute('value', playbutton.getAttribute('data-pause-label'));
1977 playbutton.classList.add('media-play-playing');
1978 }
1979 }
1980 media.addEventListener('play', mediachange, false);
1981 media.addEventListener('pause', mediachange, false);
1982 media.addEventListener('ended', mediachange, false);
1983
1984 var mediarange = controls.querySelector('input.media-range');
1985 mediarange.addEventListener('input', function () {
1986 var pct = this.value;
1987 if (pct < 0)
1988 pct = 0;
1989 if (pct > 100)
1990 pct = 100;
1991 media.currentTime = (pct / 100.0) * media.duration;
1992 }, false);
1993 var curspan = controls.querySelector('span.media-current');
1994 var durspan = controls.querySelector('span.media-duration');
1995 var durationUpdate = function () {
1996 if (!isNaN(media.duration)) {
1997 mins = parseInt(media.duration / 60);
1998 secs = parseInt(media.duration - (60 * mins));
1999 durspan.textContent = (mins + (secs < 10 ? ':0' : ':') + secs);
2000 }
2001 };
2002 media.addEventListener('durationchange', durationUpdate, false);
2003
2004 var ttmlDiv = null;
2005 var ttmlNodes = null;
2006 for (var i = 0; i < media.parentNode.children.length; i++) {
2007 var child = media.parentNode.children[i];
2008 if (child.classList.contains('media-ttml'))
2009 ttmlDiv = child;
2010 }
2011 if (ttmlDiv != null) {
2012 ttmlNodes = ttmlDiv.querySelectorAll('.media-ttml-node');
2013 }
2014
2015 var timeUpdate = function () {
2016 var pct = (media.currentTime / media.duration) * 100;
2017 mediarange.value = pct;
2018 var mins = parseInt(media.currentTime / 60);
2019 var secs = parseInt(media.currentTime - (60 * mins))
2020 curspan.textContent = (mins + (secs < 10 ? ':0' : ':') + secs);
2021 if (ttmlNodes != null) {
2022 for (var i = 0; i < ttmlNodes.length; i++) {
2023 var ttml = ttmlNodes[i];
2024 if (media.currentTime >= parseFloat(ttml.getAttribute('data-ttml-begin')) &&
2025 (!ttml.hasAttribute('data-ttml-end') ||
2026 media.currentTime < parseFloat(ttml.getAttribute('data-ttml-end')) )) {
2027 if (ttml.tagName == 'span' || ttml.tagName == 'SPAN')
2028 ttml.style.display = 'inline';
2029 else
2030 ttml.style.display = 'block';
2031 }
2032 else {
2033 ttml.style.display = 'none';
2034 }
2035 }
2036 }
2037 };
2038 media.addEventListener('timeupdate', timeUpdate, false);
2039 };
2040 document.addEventListener('DOMContentLoaded', function() {
2041 var matches = document.querySelectorAll('video, audio');
2042 for (var i = 0; i < matches.length; i++) {
2043 yelp_media_init(matches[i]);
2044 }
2045 }, false);
2046 ]]></xsl:text>
2047 </xsl:template>
2048
2049
2050 <!--**==========================================================================
2051 html.js.syntax
2052 Output `script` elements for syntax highlighting.
2053 @revision[version=3.28 date=2016-01-03 status=final]
2054
2055 [xsl:params]
2056 $node: The node to create JavaScript for.
2057
2058 This template outputs HTML `script` elements to enable syntax highlighting.
2059 It only outputs if {html.syntax.highlight} is `true`. It outputs one `script`
2060 element to load in `highlight.js`, and another to initialize `highlight.js`
2061 on all `code` elements with `"syntax"` in the class value.
2062 -->
2063 <xsl:template name="html.js.syntax">
2064 <xsl:param name="node" select="."/>
2065 <xsl:if test="$html.syntax.highlight">
2066 <script type="text/javascript" src="{$html.js.root}highlight.pack.js">
2067 <xsl:if test="$html.csp.nonce">
2068 <xsl:attribute name="nonce">
2069 <xsl:value-of select="$html.csp.nonce" />
2070 </xsl:attribute>
2071 </xsl:if>
2072 </script>
2073 <script>
2074 <xsl:if test="$html.csp.nonce">
2075 <xsl:attribute name="nonce">
2076 <xsl:value-of select="$html.csp.nonce" />
2077 </xsl:attribute>
2078 </xsl:if><![CDATA[
2079 document.addEventListener('DOMContentLoaded', function() {
2080 var matches = document.querySelectorAll('code.syntax')
2081 for (var i = 0; i < matches.length; i++) {
2082 hljs.highlightBlock(matches[i]);
2083 }
2084 }, false);]]></script>
2085 </xsl:if>
2086 </xsl:template>
2087
2088
2089 <!--%%==========================================================================
2090 html.js.mode
2091 Output JavaScript specific to the input format.
2092 @revision[version=1.0 date=2010-01-01 status=final]
2093
2094 This mode is called by {html.js.content} to output JavaScript specific to
2095 the input format. Importing stylesheets may implement this for any element that
2096 will be passed to {html.page}. If they do not, the output HTML will only have
2097 the common JavaScript.
2098 -->
2099 <xsl:template mode="html.js.mode" match="*">
2100 </xsl:template>
2101
2102
2103 <!--**==========================================================================
2104 html.js.custom
2105 Stub to reference custom JavaScript common to all HTML transformations.
2106 @xsl:stub
2107 @revision[version=1.0 date=2010-04-16 status=final]
2108
2109 [xsl:params]
2110 $node: The node to create JavaScript for.
2111
2112 This template is a stub, called by {html.js}. You can override this template
2113 to reference additional external JavaScript files. If you want to include
2114 JavaScript into the main `script` tag instead, use {html.js.content.custom}.
2115 -->
2116 <xsl:template name="html.js.custom">
2117 <xsl:param name="node" select="."/>
2118 </xsl:template>
2119
2120
2121 <!--**==========================================================================
2122 html.js.content.custom
2123 Stub to output custom JavaScript common to all HTML transformations.
2124 @xsl:stub
2125 @revision[version=1.0 date=2010-04-16 status=final]
2126
2127 [xsl:params]
2128 $node: The node to create JavaScript for.
2129
2130 This template is a stub, called by {html.js.content}. You can override this
2131 template to provide additional JavaScript that will be used by all HTML output.
2132 This template is called inside a `script` tag, and is intended to include
2133 JavaScript code in the output page. See {html.js.custom} to include a custom
2134 reference to an external JavaScript file.
2135 -->
2136 <xsl:template name="html.js.content.custom">
2137 <xsl:param name="node" select="."/>
2138 </xsl:template>
2139
2140
2141 <!--**==========================================================================
2142 html.lang.attrs
2143 Output `lang` and `dir` attributes.
2144 @revision[version=1.0 date=2010-06-10 status=final]
2145
2146 [xsl:params]
2147 $node: The current element in the input document.
2148 $parent: A parent node to take $lang and $dir from.
2149 $lang: The language for $node.
2150 $dir: The text directionality for $node.
2151
2152 This template outputs `lang`, `xml:lang`, or `dir` attributes if necessary.
2153 If $lang is not set, it will be taken from the `xml:lang` or `lang`
2154 attribute of $node. If $dir is not set, it will be taken from the `its:dir`
2155 attribute of $node or computed based on $lang.
2156
2157 The $parent parameter defaults to an empty node set. If it is set to a
2158 non-empty node set, this template will attempt to get $lang and $dir from
2159 $parent if they are not set on $node. This is occasionally useful when a
2160 wrapper element in a source language doesn't directly create any output
2161 elements.
2162
2163 This template outputs either an `xml:lang` or a `lang` attribute, depending
2164 on whether {html.xhtml} is `true`. It only outputs an `xml:lang` or `lang`
2165 attribute if $lang is non-empty. This template also outputs a `dir` attribute
2166 if $dir is non-empty.
2167 -->
2168 <xsl:template name="html.lang.attrs">
2169 <xsl:param name="node" select="."/>
2170 <xsl:param name="parent" select="/false"/>
2171 <xsl:param name="lang">
2172 <xsl:choose>
2173 <xsl:when test="$node/@xml:lang">
2174 <xsl:value-of select="$node/@xml:lang"/>
2175 </xsl:when>
2176 <xsl:when test="$node/@lang">
2177 <xsl:value-of select="$node/@lang"/>
2178 </xsl:when>
2179 <xsl:when test="$parent/@xml:lang">
2180 <xsl:value-of select="$parent/@xml:lang"/>
2181 </xsl:when>
2182 <xsl:when test="$parent/@lang">
2183 <xsl:value-of select="$parent/@lang"/>
2184 </xsl:when>
2185 </xsl:choose>
2186 </xsl:param>
2187 <xsl:param name="dir">
2188 <xsl:choose>
2189 <xsl:when test="$node/@its:dir">
2190 <xsl:value-of select="$node/@its:dir"/>
2191 </xsl:when>
2192 <xsl:when test="($node/@xml:lang or $node/@lang) and (string($lang) != '')">
2193 <xsl:call-template name="l10n.direction">
2194 <xsl:with-param name="lang" select="$lang"/>
2195 </xsl:call-template>
2196 </xsl:when>
2197 <xsl:when test="$parent/@its:dir">
2198 <xsl:value-of select="$node/@its:dir"/>
2199 </xsl:when>
2200 <xsl:when test="string($lang) != ''">
2201 <xsl:call-template name="l10n.direction">
2202 <xsl:with-param name="lang" select="$lang"/>
2203 </xsl:call-template>
2204 </xsl:when>
2205 </xsl:choose>
2206 </xsl:param>
2207 <xsl:if test="string($lang) != ''">
2208 <xsl:choose>
2209 <xsl:when test="$html.xhtml">
2210 <xsl:attribute name="xml:lang">
2211 <xsl:value-of select="$lang"/>
2212 </xsl:attribute>
2213 </xsl:when>
2214 <xsl:otherwise>
2215 <xsl:attribute name="lang">
2216 <xsl:value-of select="$lang"/>
2217 </xsl:attribute>
2218 </xsl:otherwise>
2219 </xsl:choose>
2220 </xsl:if>
2221 <xsl:if test="string($dir) != ''">
2222 <xsl:attribute name="dir">
2223 <xsl:value-of select="$dir"/>
2224 </xsl:attribute>
2225 </xsl:if>
2226 </xsl:template>
2227
2228
2229 <!--**==========================================================================
2230 html.syntax.class
2231 Output HTML class values for syntax highlighting.
2232 @revision[version=3.28 date=2016-01-03 status=final]
2233
2234 [xsl:params]
2235 $node: The source element whose content will be syntax highlighted.
2236
2237 This template calls {html.syntax.class.mode} on $node. If the result of that
2238 mode is a suitable language identifier, it outputs appropriate CSS class names
2239 to enable syntax highlighting. The output should be placed in the `class`
2240 attribute of a `pre` or similar output element by the calling template.
2241
2242 Importing stylesheets should implement {html.syntax.class.mode} for any source
2243 elements that may be syntax highlighted, then call this template when building
2244 the `class` attribute for output elements.
2245 -->
2246 <xsl:template name="html.syntax.class">
2247 <xsl:param name="node" select="."/>
2248 <xsl:variable name="class">
2249 <xsl:apply-templates mode="html.syntax.class.mode" select="$node"/>
2250 </xsl:variable>
2251 <xsl:if test="normalize-space($class) != ''">
2252 <xsl:text>syntax language-</xsl:text>
2253 <xsl:value-of select="$class"/>
2254 </xsl:if>
2255 </xsl:template>
2256
2257
2258 <!--%%==========================================================================
2259 html.syntax.class.mode
2260 Get the syntax highlighting language for a source-specific element.
2261 @revision[version=3.28 date=2016-01-03 status=final]
2262
2263 This mode is called by {html.syntax.class} on source elements that may have
2264 syntax highlighted. This template should be implemented by importing stylesheets.
2265 It should return a simple language identifier.
2266 -->
2267 <xsl:template mode="html.syntax.class.mode" match="*"/>
2268
2269
2270 <!--**==========================================================================
2271 html.media.controls
2272 Output media controls for a video or audio object.
2273 @revision[version=3.38 date=2020-04-30 status=final]
2274
2275 [xsl:params]
2276 $type: The type of media element, either 'video' or 'audio'.
2277 $ttml: Whether there are TTML subtitles for this media element.
2278
2279 This template outputs HTML containing controls for a media play for audio or
2280 video HTML elements. To work with the built-in JavaScript binding code, it
2281 should be placed immediately after the `audio` or `video` element.
2282 -->
2283 <xsl:template name="html.media.controls">
2284 <xsl:param name="type" select="'video'"/>
2285 <xsl:param name="ttml" select="false()"/>
2286 <div>
2287 <xsl:attribute name="class">
2288 <xsl:text>media-controls media-controls-</xsl:text>
2289 <xsl:value-of select="$type"/>
2290 <xsl:if test="$ttml">
2291 <xsl:text> media-controls-ttml</xsl:text>
2292 </xsl:if>
2293 </xsl:attribute>
2294 <button class="media-play">
2295 <xsl:attribute name="data-play-label">
2296 <xsl:call-template name="l10n.gettext">
2297 <xsl:with-param name="msgid" select="'Play'"/>
2298 </xsl:call-template>
2299 </xsl:attribute>
2300 <xsl:attribute name="data-pause-label">
2301 <xsl:call-template name="l10n.gettext">
2302 <xsl:with-param name="msgid" select="'Pause'"/>
2303 </xsl:call-template>
2304 </xsl:attribute>
2305 <xsl:attribute name="value">
2306 <xsl:call-template name="l10n.gettext">
2307 <xsl:with-param name="msgid" select="'Play'"/>
2308 </xsl:call-template>
2309 </xsl:attribute>
2310 <xsl:call-template name="icons.svg.media.play"/>
2311 <xsl:call-template name="icons.svg.media.pause"/>
2312 </button>
2313 <input type="range" class="media-range" value="0"/>
2314 <span class="media-time">
2315 <span class="media-current">0:00</span>
2316 <span class="media-duration">-:--</span>
2317 </span>
2318 </div>
2319 </xsl:template>
2320
2321 </xsl:stylesheet>