Skip to content

Commit dbd425a

Browse files
author
Sanders Kleinfeld
committed
Merge branch 'master' of github.com:oreillymedia/HTMLBook into gh-pages
2 parents 336ee12 + 73534ce commit dbd425a

File tree

12 files changed

+1167
-77
lines changed

12 files changed

+1167
-77
lines changed

htmlbook-xsl/chunk.xsl

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ sect5:s
5555
<!-- Use the PI <?yield?> in the location in which the HTML chunk content should be inserted -->
5656
<xsl:param name="custom.chunk.wrapper"/>
5757

58+
<!-- Typically we DON'T want URLs rendered in parens for chunked content, as the presumption is that it's for digital uses where
59+
links will be clickable -->
60+
<xsl:param name="url.in.parens" select="0"/>
61+
5862
<xsl:template match="/h:html">
5963
<xsl:apply-templates select="h:body"/>
6064
</xsl:template>
@@ -387,7 +391,8 @@ sect5:s
387391
<xsl:template match="h:a[not((contains(@data-type, 'xref')) or
388392
(contains(@data-type, 'footnoteref')) or
389393
(contains(@data-type, 'indexterm')))][@href]">
390-
<!-- If the element is empty, does not have data-type="link", and is a valid XREF, go ahead and treat it like an <a> element with data-type="xref" -->
394+
<xsl:param name="url.in.parens" select="$url.in.parens"/>
395+
<!-- If the element is empty, does not have data-type="link", and is a valid XREF, go ahead and treat it like an <a> element with data-type="xref" -->
391396
<xsl:variable name="is-xref">
392397
<xsl:call-template name="href-is-xref">
393398
<xsl:with-param name="href-value" select="@href"/>
@@ -405,7 +410,7 @@ sect5:s
405410
not(@data-type='link')">
406411
<xsl:call-template name="process-as-xref"/>
407412
</xsl:when>
408-
<!-- If href is an xref then process href -->
413+
<!-- Else if href is not external hyperlink, then process href -->
409414
<xsl:when test="$is-xref = 1">
410415
<xsl:copy>
411416
<xsl:apply-templates select="@*[not(name(.) = 'href')]"/>
@@ -440,6 +445,36 @@ sect5:s
440445
<xsl:copy>
441446
<xsl:apply-templates select="@*|node()"/>
442447
</xsl:copy>
448+
<xsl:if test="$url.in.parens = 1">
449+
<!-- Put the URL after the <a> element in parentheses, unless one of the following two cases is true:
450+
1. A @class attribute containing the text orm:hideurl was specified
451+
2. The href is a mailto link.
452+
3. The <a> has data-type="link"
453+
4. Text node is identical to @url attribute (or matches if http:// or http://www. is dropped) -->
454+
<xsl:variable name="trimmed_href_attr">
455+
<xsl:call-template name="trim-url">
456+
<xsl:with-param name="url-to-trim" select="@href"/>
457+
</xsl:call-template>
458+
</xsl:variable>
459+
<xsl:variable name="trimmed_anchor_text_node">
460+
<xsl:call-template name="trim-url">
461+
<xsl:with-param name="url-to-trim" select="."/>
462+
</xsl:call-template>
463+
</xsl:variable>
464+
<xsl:variable name="render_url_in_parens">
465+
<xsl:choose>
466+
<xsl:when test="contains(@class, 'orm:hideurl')">0</xsl:when>
467+
<xsl:when test="contains(@href, 'mailto:')">0</xsl:when>
468+
<xsl:when test="@data-type = 'link'">0</xsl:when>
469+
<xsl:when test=". = @href">0</xsl:when>
470+
<xsl:when test="$trimmed_href_attr = $trimmed_anchor_text_node">0</xsl:when>
471+
<xsl:otherwise>1</xsl:otherwise>
472+
</xsl:choose>
473+
</xsl:variable>
474+
<xsl:if test="$render_url_in_parens = 1">
475+
<span class="print_url_in_parens"> (<span class="print_url"><xsl:value-of select="@href"/></span>)</span>
476+
</xsl:if>
477+
</xsl:if>
443478
</xsl:otherwise>
444479
</xsl:choose>
445480
</xsl:template>

htmlbook-xsl/common.xsl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,14 @@
450450
<xsl:when test="$node[self::h:div and @data-type]">
451451
<xsl:value-of select="$node/@data-type"/> <!-- for <div>, default to @data-type value -->
452452
</xsl:when>
453+
<xsl:when test="$node[self::h:aside]">
454+
<xsl:choose>
455+
<xsl:when test="@data-type">
456+
<xsl:value-of select="@data-type"/>
457+
</xsl:when>
458+
<xsl:otherwise>sidebar</xsl:otherwise>
459+
</xsl:choose>
460+
</xsl:when>
453461
<xsl:otherwise>
454462
<!-- For all other elements besides <section> and <div>, just use the local-name -->
455463
<xsl:value-of select="local-name($node)"/>
@@ -460,6 +468,7 @@
460468
<xsl:template name="html.output.element">
461469
<!-- Logic to decide which HTML element to output for a given source element. -->
462470
<xsl:param name="node" select="."/>
471+
<xsl:param name="html4.structural.elements" select="$html4.structural.elements"/>
463472
<xsl:choose>
464473
<!-- If $html4.structural.elements is enabled, HTML5 <section> and <figure> elements are replaced with a <div> -->
465474
<xsl:when test="$html4.structural.elements = 1">
@@ -468,7 +477,7 @@
468477
<xsl:text>div</xsl:text>
469478
</xsl:when>
470479
<xsl:when test="$node[self::h:figcaption]">
471-
<xsl:text>h5</xsl:text>
480+
<xsl:text>h6</xsl:text>
472481
</xsl:when>
473482
<xsl:otherwise>
474483
<!-- No change in element name for other elements -->

htmlbook-xsl/elements.xsl

Lines changed: 111 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,46 @@
2424
<!-- WARNING: If you need additional handling for these elements for other functionality,
2525
and you override this template elsewhere, make sure you add in id-decoration functionality -->
2626
<xsl:template match="h:section|h:div[contains(@data-type, 'part')]|h:aside|h:a[contains(@data-type, 'indexterm')]">
27+
<xsl:param name="html4.structural.elements" select="$html4.structural.elements"/>
2728
<xsl:variable name="output-element-name">
28-
<xsl:call-template name="html.output.element"/>
29+
<xsl:call-template name="html.output.element">
30+
<xsl:with-param name="html4.structural.elements" select="$html4.structural.elements"/>
31+
</xsl:call-template>
2932
</xsl:variable>
30-
<xsl:element name="{$output-element-name}" namespace="http://www.w3.org/1999/xhtml">
33+
<xsl:copy>
3134
<xsl:apply-templates select="@*[not(local-name() = 'id')]"/>
32-
<xsl:attribute name="id">
33-
<xsl:call-template name="object.id"/>
34-
</xsl:attribute>
3535
<xsl:apply-templates select="." mode="pdf-bookmark"/>
36-
<xsl:apply-templates/>
37-
<xsl:if test="$process.footnotes = 1">
38-
<xsl:call-template name="generate-footnotes"/>
39-
</xsl:if>
40-
</xsl:element>
36+
<xsl:choose>
37+
<!-- If output element name matches local name (i.e., HTML4 fallback elements disabled), copy element as is and process descendant content -->
38+
<!-- ToDo: Refactor duplicate code in when/otherwise; perhaps do an apply-templates select="." with a process-section mode -->
39+
<xsl:when test="$output-element-name = local-name()">
40+
<xsl:attribute name="id">
41+
<xsl:call-template name="object.id"/>
42+
</xsl:attribute>
43+
<xsl:apply-templates/>
44+
<xsl:if test="$process.footnotes = 1">
45+
<xsl:call-template name="generate-footnotes"/>
46+
</xsl:if>
47+
</xsl:when>
48+
<!-- If output element name does not match local name (i.e., HTML4 fallback elements enabled), copy element, but add an HTML4
49+
fallback child wrapper to include descendant content -->
50+
<xsl:otherwise>
51+
<xsl:element name="{$output-element-name}" namespace="http://www.w3.org/1999/xhtml">
52+
<!-- Put a class on it with the proper semantic name -->
53+
<xsl:attribute name="class">
54+
<xsl:call-template name="semantic-name"/>
55+
</xsl:attribute>
56+
<xsl:attribute name="id">
57+
<xsl:call-template name="object.id"/>
58+
</xsl:attribute>
59+
<xsl:apply-templates/>
60+
<xsl:if test="$process.footnotes = 1">
61+
<xsl:call-template name="generate-footnotes"/>
62+
</xsl:if>
63+
</xsl:element>
64+
</xsl:otherwise>
65+
</xsl:choose>
66+
</xsl:copy>
4167
</xsl:template>
4268

4369
<xsl:template match="h:section[@data-type]/*[self::h:h1 or self::h:h2 or self::h:h3 or self::h:h4 or self::h:h5 or self::h:h6]|
@@ -51,20 +77,51 @@
5177
</xsl:template>
5278

5379
<xsl:template match="h:figure">
80+
<xsl:param name="html4.structural.elements" select="$html4.structural.elements"/>
81+
<xsl:param name="figure.border.div" select="$figure.border.div"/>
5482
<xsl:variable name="output-element-name">
55-
<xsl:call-template name="html.output.element"/>
83+
<xsl:call-template name="html.output.element">
84+
<xsl:with-param name="html4.structural.elements" select="$html4.structural.elements"/>
85+
</xsl:call-template>
5686
</xsl:variable>
57-
<xsl:element name="{$output-element-name}" namespace="http://www.w3.org/1999/xhtml">
58-
<xsl:apply-templates select="@*"/>
59-
<!-- If there's no data-type already and $html4.structural.elements is enabled, plop in a data type of "figure" -->
60-
<xsl:if test="not(@data-type) and $html4.structural.elements = 1">
61-
<xsl:attribute name="data-type">figure</xsl:attribute>
62-
</xsl:if>
63-
<!-- If the parameter $figure.border.div is enabled, and there is a figure caption, add a child div and put everything but the caption in it -->
87+
<xsl:copy>
88+
<xsl:apply-templates select="@*[not(local-name() = 'id')]"/>
6489
<xsl:choose>
65-
<xsl:when test="$figure.border.div = 1 and h:figcaption">
90+
<!-- If output element name matches local name (i.e., HTML4 fallback elements disabled), copy element as is and process descendant content -->
91+
<xsl:when test="$output-element-name = local-name()">
92+
<xsl:apply-templates select="@id"/>
93+
<xsl:call-template name="process-figure-contents">
94+
<xsl:with-param name="figure.border.div" select="$figure.border.div"/>
95+
</xsl:call-template>
96+
</xsl:when>
97+
<!-- If output element name does not match local name (i.e., HTML4 fallback elements enabled), copy element, but add an HTML4
98+
fallback child wrapper to include descendant content -->
99+
<xsl:otherwise>
100+
<xsl:element name="{$output-element-name}" namespace="http://www.w3.org/1999/xhtml">
101+
<xsl:apply-templates select="@id"/>
102+
<xsl:attribute name="class">
103+
<xsl:call-template name="semantic-name"/>
104+
</xsl:attribute>
105+
<xsl:call-template name="process-figure-contents">
106+
<xsl:with-param name="figure.border.div" select="$figure.border.div"/>
107+
</xsl:call-template>
108+
</xsl:element>
109+
</xsl:otherwise>
110+
</xsl:choose>
111+
</xsl:copy>
112+
</xsl:template>
113+
114+
<xsl:template name="process-figure-contents">
115+
<xsl:param name="node" select="."/>
116+
<xsl:param name="figure.border.div" select="$figure.border.div"/>
117+
<!-- If the parameter $figure.border.div is enabled, and there is a figure caption, add a child div and put everything but the caption in it -->
118+
<!-- Switch to the appropriate context node -->
119+
<xsl:for-each select="$node[1]">
120+
<xsl:choose>
121+
<xsl:when test="$figure.border.div = 1 and h:figcaption[text()]">
66122
<!-- figcaption must be first or last; handle accordingly -->
67123
<xsl:choose>
124+
<!-- Only do border box when you've got a nonempty fig caption -->
68125
<xsl:when test="*[1][self::h:figcaption]">
69126
<xsl:apply-templates select="h:figcaption"/>
70127
<div class="border-box">
@@ -82,9 +139,9 @@
82139
<xsl:call-template name="log-message">
83140
<xsl:with-param name="type" select="'WARNING'"/>
84141
<xsl:with-param name="message">
85-
<xsl:text>Error: figcaption for figure </xsl:text>
142+
<xsl:text>Warning: figcaption for figure </xsl:text>
86143
<xsl:value-of select="@id"/>
87-
<xsl:text> not at beginning or end of figure. Unable to add border box</xsl:text>
144+
<xsl:text>not at beginning or end of figure. Unable to add border box</xsl:text>
88145
</xsl:with-param>
89146
</xsl:call-template>
90147
<xsl:apply-templates/>
@@ -95,7 +152,7 @@
95152
<xsl:apply-templates/>
96153
</xsl:otherwise>
97154
</xsl:choose>
98-
</xsl:element>
155+
</xsl:for-each>
99156
</xsl:template>
100157

101158
<xsl:template match="h:caption">
@@ -105,14 +162,45 @@
105162
</xsl:template>
106163

107164
<xsl:template match="h:figcaption">
165+
<xsl:param name="html4.structural.elements" select="$html4.structural.elements"/>
108166
<xsl:apply-templates select="." mode="process-heading">
109167
<xsl:with-param name="labeled-element-semantic-name" select="'figure'"/>
110168
<xsl:with-param name="output-element-name">
111-
<xsl:call-template name="html.output.element"/>
169+
<xsl:call-template name="html.output.element">
170+
<xsl:with-param name="html4.structural.elements" select="$html4.structural.elements"/>
171+
</xsl:call-template>
112172
</xsl:with-param>
113173
</xsl:apply-templates>
114174
</xsl:template>
115175

176+
<!-- Admonition handling -->
177+
<xsl:template match="h:div[@data-type='note' or
178+
@data-type='tip' or
179+
@data-type='warning' or
180+
@data-type='caution' or
181+
@data-type='important']">
182+
<xsl:param name="add.title.heading.for.admonitions" select="$add.title.heading.for.admonitions"/>
183+
<xsl:copy>
184+
<xsl:apply-templates select="@*"/>
185+
<!-- Add admonition heading title if $add.title.heading.for.admonitions is enabled AND there is not a heading first child already -->
186+
<xsl:if test="($add.title.heading.for.admonitions = 1) and
187+
not(*[1][self::h:h1|self::h:h2|self::h:h3|self::h:h4|self::h:h5|self::h:h6])">
188+
<h6>
189+
<!-- For title, use proper admonition title gentext, based on localization -->
190+
<xsl:variable name="admon-semantic-name">
191+
<xsl:call-template name="semantic-name">
192+
<xsl:with-param name="node" select="."/>
193+
</xsl:call-template>
194+
</xsl:variable>
195+
<xsl:call-template name="get-localization-value">
196+
<xsl:with-param name="gentext-key" select="$admon-semantic-name"/>
197+
</xsl:call-template>
198+
</h6>
199+
</xsl:if>
200+
<xsl:apply-templates/>
201+
</xsl:copy>
202+
</xsl:template>
203+
116204
<!-- Footnote handling -->
117205
<xsl:template match="h:span[@data-type='footnote']">
118206
<xsl:choose>

htmlbook-xsl/epub.xsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,11 @@ UbuntuMono-Italic.otf</xsl:param>
207207
<!-- Directory to place embedded fonts, relative to content directory; leave blank to put in root content dir (e.g., in "OEBPS" dir) -->
208208
<xsl:param name="embedded.fonts.directory"/>
209209

210-
<!-- Off by default, but may be useful for EPUB 2 backward compatibility. Setting to 1 with turn on EPUB2-compatible elements,
210+
<!-- Useful for EPUB 2 backward compatibility. Setting to 1 will turn on EPUB2-compatible elements,
211211
which means that HTML5 structural semantic elements
212-
like <section> and <figure> will be converted to <div> to ensure compatibility in
212+
like <section> and <figure> will be replicated as <div> to help ensure compatibility for cross-referencing and CSS styling in
213213
non-EPUB3-compliant ereaders -->
214-
<xsl:param name="html4.structural.elements" select="0"/>
214+
<xsl:param name="html4.structural.elements" select="1"/>
215215

216216
<!-- Do default to turning on autolabeling for EPUB, as some older ereaders may not support the necessary CSS -->
217217
<xsl:param name="autogenerate.labels" select="1"/>

htmlbook-xsl/indexgen.xsl

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,40 +49,57 @@
4949
<xsl:key name="sections" match="*[@id or @xml:id]" use="@id|@xml:id"/>
5050

5151
<xsl:template match="h:section[@data-type='index']">
52+
<xsl:param name="html4.structural.elements" select="$html4.structural.elements"/>
5253
<xsl:variable name="output-element-name">
53-
<xsl:call-template name="html.output.element"/>
54+
<xsl:call-template name="html.output.element">
55+
<xsl:with-param name="html4.structural.elements" select="$html4.structural.elements"/>
56+
</xsl:call-template>
5457
</xsl:variable>
55-
<xsl:choose>
56-
<!-- If autogenerate-index is enabled, and it's the first index-placeholder-element, and it's either empty or overwrite-contents is specified, then
57-
go ahead and generate the Index here -->
58-
<xsl:when test="($autogenerate-index = 1) and
59-
(not(preceding::h:section[@data-type='index'])) and
60-
(not(node()) or $index-placeholder-overwrite-contents != 0)">
61-
<xsl:element name="{$output-element-name}" namespace="http://www.w3.org/1999/xhtml">
62-
<xsl:apply-templates select="@*[not(local-name() = 'id')]"/>
58+
<xsl:copy>
59+
<xsl:apply-templates select="@*[not(local-name() = 'id')]"/>
60+
<xsl:choose>
61+
<!-- If output element name matches local name (i.e., HTML4 fallback elements disabled), copy element as is and process descendant content -->
62+
<xsl:when test="$output-element-name = local-name()">
6363
<xsl:attribute name="id">
6464
<xsl:call-template name="object.id"/>
6565
</xsl:attribute>
66+
<xsl:call-template name="process-index-content"/>
67+
</xsl:when>
68+
<xsl:otherwise>
69+
<xsl:element name="{$output-element-name}" namespace="http://www.w3.org/1999/xhtml">
70+
<!-- Put a class on it with the proper semantic name -->
71+
<xsl:attribute name="class">
72+
<xsl:call-template name="semantic-name"/>
73+
</xsl:attribute>
74+
<xsl:attribute name="id">
75+
<xsl:call-template name="object.id"/>
76+
</xsl:attribute>
77+
<xsl:call-template name="process-index-content"/>
78+
</xsl:element>
79+
</xsl:otherwise>
80+
</xsl:choose>
81+
</xsl:copy>
82+
</xsl:template>
83+
84+
<xsl:template name="process-index-content">
85+
<xsl:param name="node" select="."/>
86+
<xsl:for-each select="$node[1]">
87+
<xsl:choose>
88+
<xsl:when test="($autogenerate-index = 1) and
89+
(not(preceding::h:section[@data-type='index'])) and
90+
(not(node()) or $index-placeholder-overwrite-contents != 0)">
6691
<h1>
6792
<xsl:call-template name="get-localization-value">
6893
<xsl:with-param name="gentext-key" select="'index'"/>
6994
</xsl:call-template>
7095
</h1>
7196
<xsl:call-template name="generate-index"/>
72-
</xsl:element>
73-
</xsl:when>
74-
<xsl:otherwise>
75-
<!-- Otherwise, just process as normal -->
76-
<!-- ToDo: Consider using <xsl:apply-imports> here, depending on how we decide to do stylesheet layering for packaging for EPUB, etc. -->
77-
<xsl:element name="{$output-element-name}" namespace="http://www.w3.org/1999/xhtml">
78-
<xsl:apply-templates select="@*[not(local-name() = 'id')]"/>
79-
<xsl:attribute name="id">
80-
<xsl:call-template name="object.id"/>
81-
</xsl:attribute>
97+
</xsl:when>
98+
<xsl:otherwise>
8299
<xsl:apply-templates/>
83-
</xsl:element>
84-
</xsl:otherwise>
85-
</xsl:choose>
100+
</xsl:otherwise>
101+
</xsl:choose>
102+
</xsl:for-each>
86103
</xsl:template>
87104

88105
<xsl:template name="generate-index">

htmlbook-xsl/localizations/en.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@
460460
<l:template name="segmentedlist" text="%t"/>
461461
<l:template name="set" text="%t"/>
462462
<l:template name="setindex" text="%t"/>
463-
<l:template name="sidebar" text="%t"/>
463+
<l:template name="sidebar" text="“%t”"/>
464464
<l:template name="table" text="%t"/>
465465
<l:template name="task" text="%t"/>
466466
<l:template name="tip" text="%t"/>

0 commit comments

Comments
 (0)