]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/custom-html.xsl
Merge pull request #34499 from YHNdnzj/sd-path-trivial-cleanup
[thirdparty/systemd.git] / man / custom-html.xsl
CommitLineData
76318284 1<?xml version='1.0'?> <!--*-nxml-*-->
db9ecf05 2<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
76318284
LP
3
4<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
5
6<xsl:import href="http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl"/>
d77c25b1
JO
7<!--
8 - The docbook stylesheet injects empty anchor tags into generated HTML, identified by an auto-generated ID.
9 - Ask the docbook stylesheet to generate reproducible output when generating (these) ID values.
10 - This makes the output of this stylesheet reproducible across identical invocations on the same input,
11 - which is an easy and significant win for achieving reproducible builds.
12 -
13 - It may be even better to strip the empty anchors from the document output in addition to turning on consistent IDs,
14 - for this stylesheet contains its own custom ID logic (for generating permalinks) already.
15 -->
16<xsl:param name="generate.consistent.ids" select="1"/>
76318284 17
ecca17f6 18<!-- translate man page references to links to html pages -->
5aded369 19<xsl:template match="citerefentry[not(@project)]">
ecca17f6
KS
20 <a>
21 <xsl:attribute name="href">
affa893d 22 <xsl:value-of select="refentrytitle"/>
23 <xsl:text>.html#</xsl:text>
958caa58 24 <xsl:value-of select="refentrytitle/@target"/>
ecca17f6
KS
25 </xsl:attribute>
26 <xsl:call-template name="inline.charseq"/>
27 </a>
28</xsl:template>
29
5aded369
ZJS
30<xsl:template match="citerefentry[@project='man-pages'] | citerefentry[manvolnum='2'] | citerefentry[manvolnum='4']">
31 <a>
32 <xsl:attribute name="href">
e2285c57 33 <xsl:text>https://man7.org/linux/man-pages/man</xsl:text>
5aded369
ZJS
34 <xsl:value-of select="manvolnum"/>
35 <xsl:text>/</xsl:text>
36 <xsl:value-of select="refentrytitle"/>
37 <xsl:text>.</xsl:text>
38 <xsl:value-of select="manvolnum"/>
39 <xsl:text>.html</xsl:text>
40 </xsl:attribute>
41 <xsl:call-template name="inline.charseq"/>
42 </a>
43</xsl:template>
44
45<xsl:template match="citerefentry[@project='die-net']">
46 <a>
47 <xsl:attribute name="href">
48 <xsl:text>http://linux.die.net/man/</xsl:text>
49 <xsl:value-of select="manvolnum"/>
50 <xsl:text>/</xsl:text>
51 <xsl:value-of select="refentrytitle"/>
52 </xsl:attribute>
53 <xsl:call-template name="inline.charseq"/>
54 </a>
55</xsl:template>
56
74a6d87d
ZJS
57<xsl:template match="citerefentry[@project='mankier']">
58 <a>
59 <xsl:attribute name="href">
60 <xsl:text>https://www.mankier.com/</xsl:text>
61 <xsl:value-of select="manvolnum"/>
62 <xsl:text>/</xsl:text>
63 <xsl:value-of select="refentrytitle"/>
64 </xsl:attribute>
65 <xsl:call-template name="inline.charseq"/>
66 </a>
67</xsl:template>
68
5aded369
ZJS
69<xsl:template match="citerefentry[@project='archlinux']">
70 <a>
71 <xsl:attribute name="href">
41fead40 72 <xsl:text>https://man.archlinux.org/man/</xsl:text>
5aded369
ZJS
73 <xsl:value-of select="refentrytitle"/>
74 <xsl:text>.</xsl:text>
75 <xsl:value-of select="manvolnum"/>
41fead40 76 <xsl:text>.en.html</xsl:text>
5aded369
ZJS
77 </xsl:attribute>
78 <xsl:call-template name="inline.charseq"/>
79 </a>
80</xsl:template>
81
42ecca2e
ZJS
82<xsl:template match="citerefentry[@project='debian']">
83 <a>
84 <xsl:attribute name="href">
85 <xsl:text>https://manpages.debian.org/unstable/</xsl:text>
86 <xsl:value-of select="refentrytitle"/>
87 <xsl:text>/</xsl:text>
88 <xsl:value-of select="refentrytitle"/>
89 <xsl:text>.</xsl:text>
90 <xsl:value-of select="manvolnum"/>
91 <xsl:text>.en.html</xsl:text>
92 </xsl:attribute>
93 <xsl:call-template name="inline.charseq"/>
94 </a>
95</xsl:template>
96
b5c7d097
ZJS
97<xsl:template match="citerefentry[@project='freebsd']">
98 <a>
99 <xsl:attribute name="href">
100 <xsl:text>https://www.freebsd.org/cgi/man.cgi?</xsl:text>
101 <xsl:value-of select="refentrytitle"/>
102 <xsl:text>(</xsl:text>
103 <xsl:value-of select="manvolnum"/>
104 <xsl:text>)</xsl:text>
105 </xsl:attribute>
106 <xsl:call-template name="inline.charseq"/>
107 </a>
108</xsl:template>
109
3b5cfcdb
ZJS
110<xsl:template match="citerefentry[@project='dbus']">
111 <a>
112 <xsl:attribute name="href">
41d6f3bf 113 <xsl:text>https://dbus.freedesktop.org/doc/</xsl:text>
3b5cfcdb
ZJS
114 <xsl:value-of select="refentrytitle"/>
115 <xsl:text>.</xsl:text>
116 <xsl:value-of select="manvolnum"/>
117 <xsl:text>.html</xsl:text>
118 </xsl:attribute>
119 <xsl:call-template name="inline.charseq"/>
120 </a>
121</xsl:template>
122
affa893d 123<xsl:template match="citerefentry[@project='url']">
124 <a>
125 <xsl:attribute name="href">
126 <xsl:value-of select="refentrytitle/@url"/>
127 </xsl:attribute>
128 <xsl:call-template name="inline.charseq"/>
129 </a>
130</xsl:template>
131
aa116977
JO
132<!--
133 - helper template to do conflict resolution between various headings with the same inferred ID attribute/tag from the headerlink template
a8eaaee7 134 - this conflict resolution is necessary to prevent malformed HTML output (multiple ID attributes with the same value)
aa116977
JO
135 - and it fixes xsltproc warnings during compilation of HTML man pages
136 -
137 - A simple top-to-bottom numbering scheme is implemented for nodes with the same ID value to derive unique ID values for HTML output.
138 - It uses two parameters:
139 templateID the proposed ID string to use which must be checked for conflicts
140 keyNode the context node which 'produced' the given templateID.
141 -
142 - Conflicts are detected solely based on keyNode, templateID is not taken into account for that purpose.
143 -->
144<xsl:template name="generateID">
145 <!-- node which generatedID needs to assume as the 'source' of the ID -->
146 <xsl:param name="keyNode"/>
147 <!-- suggested value for generatedID output, a contextually meaningful ID string -->
148 <xsl:param name="templateID"/>
149 <xsl:variable name="conflictSource" select="preceding::refsect1/title|preceding::refsect1/info/title|
150 preceding::refsect2/title|preceding::refsect2/info/title|
151 preceding::varlistentry/term[1]"/>
152 <xsl:variable name="conflictCount" select="count($conflictSource[. = $keyNode])"/>
153 <xsl:choose>
154 <!-- special case conflictCount = 0 to preserve compatibility with URLs generated by previous versions of this XSL stylesheet where possible -->
155 <xsl:when test="$conflictCount = 0">
156 <xsl:value-of select="$templateID"/>
157 </xsl:when>
158 <xsl:otherwise>
159 <xsl:value-of select="concat($templateID, $conflictCount)"/>
160 </xsl:otherwise>
161 </xsl:choose>
162</xsl:template>
163
164<!--
165 - a helper template to abstract over the structure of generated subheading + permalink HTML output
166 - It helps reduce tedious repetition and groups all actual markup output (as opposed to URL/ID logic) in a single location.
167 -->
168<xsl:template name="permalink">
169 <xsl:param name="nodeType"/> <!-- local name of the element node to generate, e.g. 'h2' for <h2></h2> -->
170 <xsl:param name="nodeContent"/> <!-- nodeset to apply further templates to obtain the content of the subheading/term -->
171 <xsl:param name="linkTitle"/> <!-- value for title attribute of generated permalink, e.g. 'this is a permalink' -->
172
173 <!-- parameters passed to generateID template, otherwise unused. -->
174 <xsl:param name="keyNode"/>
175 <xsl:param name="templateID"/>
176
177 <!--
178 - If stable URLs with fragment markers (references to the ID) turn out not to be important:
179 - generatedID could simply take the value of generate-id(), and various other helper templates may be dropped entirely.
b938cb90 180 - Alternatively, if xsltproc is patched to generate reproducible generate-id() output, the same simplifications can be
aa116977
JO
181 - applied at the cost of breaking compatibility with URLs generated from output of previous versions of this stylesheet.
182 -->
183 <xsl:variable name="generatedID">
184 <xsl:call-template name="generateID">
185 <xsl:with-param name="keyNode" select="$keyNode"/>
186 <xsl:with-param name="templateID" select="$templateID"/>
187 </xsl:call-template>
188 </xsl:variable>
189
190 <xsl:element name="{$nodeType}">
20089f95 191 <xsl:attribute name="id">
aa116977 192 <xsl:value-of select="$generatedID"/>
20089f95 193 </xsl:attribute>
aa116977
JO
194 <xsl:apply-templates select="$nodeContent"/>
195 <a class="headerlink" title="{$linkTitle}" href="#{$generatedID}">¶</a>
196 </xsl:element>
20089f95
ZJS
197</xsl:template>
198
aa116977
JO
199<!-- simple wrapper around permalink to avoid repeating common info for each level of subheading covered by the permalink logic (h2, h3) -->
200<xsl:template name="headerlink">
201 <xsl:param name="nodeType"/>
202 <xsl:call-template name="permalink">
203 <xsl:with-param name="nodeType" select="$nodeType"/>
204 <xsl:with-param name="linkTitle" select="'Permalink to this headline'"/>
205 <xsl:with-param name="nodeContent" select="node()"/>
206 <xsl:with-param name="keyNode" select="."/>
207 <!--
208 - To retain compatibility with IDs generated by previous versions of the template, inline.charseq must be called.
209 - The purpose of that template is to generate markup (according to docbook documentation its purpose is to mark/format something as plain text).
210 - The only reason to call this template is to get the auto-generated text such as brackets ([]) before flattening it.
211 -->
212 <xsl:with-param name="templateID">
fa13e4a7 213 <xsl:call-template name="inline.charseq"/>
aa116977
JO
214 </xsl:with-param>
215 </xsl:call-template>
216</xsl:template>
217
218<xsl:template match="refsect1/title|refsect1/info/title">
219 <!-- the ID is output in the block.object call for refsect1 -->
220 <xsl:call-template name="headerlink">
221 <xsl:with-param name="nodeType" select="'h2'"/>
222 </xsl:call-template>
223</xsl:template>
224
225<xsl:template match="refsect2/title|refsect2/info/title">
226 <xsl:call-template name="headerlink">
227 <xsl:with-param name="nodeType" select="'h3'"/>
228 </xsl:call-template>
fa13e4a7
ZJS
229</xsl:template>
230
20089f95 231<xsl:template match="varlistentry">
aa116977
JO
232 <xsl:call-template name="permalink">
233 <xsl:with-param name="nodeType" select="'dt'"/>
234 <xsl:with-param name="linkTitle" select="'Permalink to this term'"/>
235 <xsl:with-param name="nodeContent" select="term"/>
236 <xsl:with-param name="keyNode" select="term[1]"/>
237 <!--
238 - To retain compatibility with IDs generated by previous versions of the template, inline.charseq must be called.
239 - The purpose of that template is to generate markup (according to docbook documentation its purpose is to mark/format something as plain text).
240 - The only reason to call this template is to get the auto-generated text such as brackets ([]) before flattening it.
241 -->
242 <xsl:with-param name="templateID">
20089f95 243 <xsl:call-template name="inline.charseq">
aa116977 244 <xsl:with-param name="content" select="term[1]"/>
20089f95 245 </xsl:call-template>
aa116977
JO
246 </xsl:with-param>
247 </xsl:call-template>
20089f95
ZJS
248 <dd>
249 <xsl:apply-templates select="listitem"/>
250 </dd>
251</xsl:template>
252
253
ecca17f6
KS
254<!-- add Index link at top of page -->
255<xsl:template name="user.header.content">
20089f95
ZJS
256 <style>
257 a.headerlink {
258 color: #c60f0f;
259 font-size: 0.8em;
260 padding: 0 4px 0 4px;
261 text-decoration: none;
262 visibility: hidden;
263 }
264
265 a.headerlink:hover {
266 background-color: #c60f0f;
267 color: white;
268 }
269
270 h1:hover > a.headerlink, h2:hover > a.headerlink, h3:hover > a.headerlink, dt:hover > a.headerlink {
271 visibility: visible;
272 }
273 </style>
274
ecca17f6
KS
275 <a>
276 <xsl:attribute name="href">
277 <xsl:text>index.html</xsl:text>
278 </xsl:attribute>
279 <xsl:text>Index </xsl:text>
2cc8d973
ZJS
280 </a>·
281 <a>
282 <xsl:attribute name="href">
283 <xsl:text>systemd.directives.html</xsl:text>
284 </xsl:attribute>
285 <xsl:text>Directives </xsl:text>
1f35347a 286 </a>
702f64b9
ZJS
287
288 <span style="float:right">
289 <xsl:text>systemd </xsl:text>
290 <xsl:value-of select="$systemd.version"/>
291 </span>
ecca17f6
KS
292 <hr/>
293</xsl:template>
294
909f413d
ZJS
295<xsl:template match="literal">
296 <xsl:text>"</xsl:text>
297 <xsl:call-template name="inline.monoseq"/>
298 <xsl:text>"</xsl:text>
299</xsl:template>
300
76318284
LP
301<!-- Switch things to UTF-8, ISO-8859-1 is soo yesteryear -->
302<xsl:output method="html" encoding="UTF-8" indent="no"/>
303
304</xsl:stylesheet>