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