Bump to docbook-xsl-stylesheets 1.79.2
[platform/upstream/docbook-xsl-stylesheets.git] / manpages / block.xsl
1 <?xml version='1.0'?>
2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3                 xmlns:d="http://docbook.org/ns/docbook"
4                 xmlns:exsl="http://exslt.org/common"
5                 exclude-result-prefixes="exsl d"
6                 version='1.0'>
7
8 <!-- ********************************************************************
9
10      This file is part of the XSL DocBook Stylesheet distribution.
11      See ../README or http://cdn.docbook.org/release/xsl/current/ for
12      copyright and other information.
13
14      ******************************************************************** -->
15
16 <!-- ==================================================================== -->
17
18 <xsl:template match="d:caution|d:important|d:note|d:tip|d:warning">
19   <xsl:call-template name="roff-if-start">
20     <xsl:with-param name="condition">n</xsl:with-param>
21   </xsl:call-template>
22   <xsl:text>.sp&#10;</xsl:text>
23   <xsl:call-template name="roff-if-end"/>
24   <xsl:text>.RS 4&#10;</xsl:text>
25   <xsl:if test="not($man.output.better.ps.enabled = 0)">
26     <xsl:text>.BM yellow&#10;</xsl:text>
27   </xsl:if>
28   <xsl:call-template name="pinch.together"/>
29   <xsl:text>.ps +1&#10;</xsl:text>
30   <xsl:call-template name="make.bold.title"/>
31   <xsl:text>.ps -1&#10;</xsl:text>
32   <xsl:text>.br&#10;</xsl:text>
33   <xsl:apply-templates/>
34   <xsl:text>.sp .5v&#10;</xsl:text>
35   <xsl:if test="not($man.output.better.ps.enabled = 0)">
36     <xsl:text>.EM yellow&#10;</xsl:text>
37   </xsl:if>
38   <xsl:text>.RE&#10;</xsl:text>
39 </xsl:template> 
40
41 <xsl:template match="d:formalpara">
42   <xsl:variable name="title.wrapper">
43     <xsl:value-of select="normalize-space(d:title[1])"/>
44   </xsl:variable>
45   <xsl:text>.PP&#10;</xsl:text>
46   <!-- * don't put linebreak after head; instead render it as a "run in" -->
47   <!-- * head, that is, inline, with a period and space following it -->
48   <xsl:call-template name="bold">
49     <xsl:with-param name="node" select="exsl:node-set($title.wrapper)"/>
50     <xsl:with-param name="context" select="."/>
51   </xsl:call-template>
52   <xsl:text>. </xsl:text>
53   <xsl:apply-templates/>
54 </xsl:template>
55
56 <xsl:template match="d:formalpara/d:para">
57   <xsl:call-template name="mixed-block"/>
58   <xsl:text>&#10;</xsl:text>
59 </xsl:template>
60
61 <xsl:template match="d:para">
62   <!-- * FIXME: Need to extract the ancestor::footnote, etc. checking and -->
63   <!-- * move to named template so that we can call it from templates for -->
64   <!-- * other block elements also -->
65   <xsl:choose>
66     <!-- * If a para is a descendant of a footnote, etc., then indent it -->
67     <!-- * (unless it is the first child, in which case don't generate -->
68     <!-- * anything at all to mark its start). -->
69     <!-- * FIXME: *blurb checking should not be munged in here the way -->
70     <!-- * it currently is; this probably breaks blurb indenting. -->
71     <xsl:when test="ancestor::d:footnote or
72                     ancestor::d:annotation or
73                     ancestor::d:authorblurb or
74                     ancestor::d:personblurb or
75                     ancestor::d:callout">
76       <xsl:if test="preceding-sibling::*[not(name() ='')]">
77         <xsl:text>.sp</xsl:text>
78         <xsl:text>&#10;</xsl:text>
79         <xsl:text>.RS 4n</xsl:text>
80         <xsl:text>&#10;</xsl:text>
81       </xsl:if>
82     </xsl:when>
83     <xsl:otherwise>
84       <xsl:text>.PP</xsl:text>
85       <xsl:text>&#10;</xsl:text>
86     </xsl:otherwise>
87   </xsl:choose>
88   <xsl:call-template name="mixed-block"/>
89     <xsl:if test="ancestor::d:footnote or
90                   ancestor::d:annotation or
91                   ancestor::d:authorblurb or
92                   ancestor::d:personblurb">
93       <xsl:if test="preceding-sibling::*[not(name() ='')]">
94         <xsl:text>&#10;</xsl:text>
95         <xsl:text>.RE</xsl:text>
96         <xsl:text>&#10;</xsl:text>
97       </xsl:if>
98     </xsl:if>
99   <xsl:text>&#10;</xsl:text>
100 </xsl:template>
101
102 <xsl:template match="d:simpara">
103   <xsl:choose>
104     <xsl:when test="ancestor::d:footnote or
105                     ancestor::d:annotation or
106                     ancestor::d:authorblurb or
107                     ancestor::d:personblurb or
108                     ancestor::d:callout">
109       <xsl:if test="preceding-sibling::*[not(name() ='')]">
110         <xsl:text>.sp</xsl:text>
111         <xsl:text>&#10;</xsl:text>
112         <xsl:text>.RS 4n</xsl:text>
113         <xsl:text>&#10;</xsl:text>
114       </xsl:if>
115     </xsl:when>
116     <xsl:otherwise>
117       <xsl:text>.sp</xsl:text>
118       <xsl:text>&#10;</xsl:text>
119     </xsl:otherwise>
120   </xsl:choose>
121   <xsl:variable name="content">
122     <xsl:apply-templates/>
123   </xsl:variable>
124   <xsl:value-of select="normalize-space($content)"/>
125   <xsl:text>&#10;</xsl:text>
126 </xsl:template>
127
128 <!-- ==================================================================== -->
129
130 <!-- * Yes, address, synopsis, and funcsynopsisinfo are verbatim environments. -->
131 <xsl:template match="d:literallayout|d:programlisting|d:screen|
132                      d:address|d:synopsis|d:funcsynopsisinfo">
133   <xsl:param name="indent">
134     <!-- * Only indent this verbatim if $man.indent.verbatims is -->
135     <!-- * non-zero and it is not a child of a *synopsis element or a -->
136     <!-- * descendant of a refsynopsisdiv -->
137     <xsl:if test="not($man.indent.verbatims = 0)
138       and not(substring(local-name(..),
139       string-length(local-name(..))-7) = 'synopsis')
140       and not(ancestor::*[local-name() = 'refsynopsisdiv'])
141       and not(ancestor::*[local-name() = 'term'])
142       ">
143       <xsl:text>Yes</xsl:text>
144     </xsl:if>
145   </xsl:param>
146
147   <!-- * if this verbatim environment starts with a newline/linebreak -->
148   <!-- * (that is, if there is a linebreak after the opening tag), that -->
149   <!-- * break would otherwise show up in output; that does not seem to -->
150   <!-- * be what most users would expect, so we check to see if it does -->
151   <!-- * indeed start with a leading newline. if so, later in this -->
152   <!-- * template, we adjust for the leading new line by doing some -->
153   <!-- * monkeyshines with "sp -1" vertical spacing -->
154   <xsl:variable name="adjust-for-leading-newline">
155     <xsl:if test="substring(., 1, 1) = '&#10;'">Yes</xsl:if>
156   </xsl:variable>
157
158   <xsl:choose>
159     <!-- * Check to see if this verbatim item is within a parent element that -->
160     <!-- * allows mixed content. -->
161     <!-- * -->
162     <!-- * If it is within a mixed-content parent, then a line space is -->
163     <!-- * already added before it by the mixed-block template, so we don't -->
164     <!-- * need to add one here. -->
165     <!-- * -->
166     <!-- * If it is not within a mixed-content parent, then we need to add a -->
167     <!-- * line space before it. -->
168     <xsl:when test="parent::d:caption|parent::d:entry|parent::d:para|
169                     parent::d:td|parent::d:th" /> <!-- do nothing -->
170     <xsl:otherwise>
171       <xsl:text>&#10;</xsl:text>
172       <xsl:text>.sp&#10;</xsl:text>
173     </xsl:otherwise>
174   </xsl:choose>
175   <xsl:if test="$indent = 'Yes'">
176     <!-- * start indented section -->
177     <xsl:call-template name="roff-if-start"/>
178     <!-- * only indent in TTY output, not in non-TTY/PS -->
179     <xsl:text>.RS</xsl:text> 
180     <xsl:if test="not($man.indent.width = '')">
181       <xsl:text> </xsl:text>
182       <xsl:value-of select="$man.indent.width"/>
183     </xsl:if>
184     <xsl:text>&#10;</xsl:text>
185     <xsl:call-template name="roff-if-end"/>
186   </xsl:if>
187   <xsl:choose>
188     <xsl:when test="self::d:funcsynopsisinfo">
189       <!-- * All Funcsynopsisinfo content is by default rendered in bold, -->
190       <!-- * because the man(7) man page says this: -->
191       <!-- * -->
192       <!-- *   For functions, the arguments are always specified using -->
193       <!-- *   italics, even in the SYNOPSIS section, where the rest of -->
194       <!-- *   the function is specified in bold -->
195       <!-- * -->
196       <!-- * Look through the contents of the man/man2 and man3 directories -->
197       <!-- * on your system, and you'll see that most existing pages do follow -->
198       <!-- * this "bold everything in function synopsis" rule. -->
199       <!-- * -->
200       <!-- * Users who don't want the bold output can choose to adjust the -->
201       <!-- * man.font.funcsynopsisinfo parameter on their own. So even if you -->
202       <!-- * don't personally like the way it looks, please don't change the -->
203       <!-- * default to be non-bold - because it's a convention that's -->
204       <!-- * followed is the vast majority of existing man pages that document -->
205       <!-- * functions, and we need to follow it by default, like it or no. -->
206       <xsl:text>.ft </xsl:text>
207       <xsl:value-of select="$man.font.funcsynopsisinfo"/>
208       <xsl:text>&#10;</xsl:text>
209       <xsl:call-template name="verbatim-block-start"/>
210       <xsl:text>.nf&#10;</xsl:text>
211       <xsl:apply-templates/>
212       <xsl:text>&#10;</xsl:text>
213       <xsl:text>.fi&#10;</xsl:text>
214       <xsl:call-template name="verbatim-block-end"/>
215       <xsl:text>.ft&#10;</xsl:text>
216     </xsl:when>
217     <xsl:otherwise>
218       <!-- * Other verbatims do not need to get bolded -->
219       <xsl:call-template name="verbatim-block-start"/>
220       <xsl:text>.nf&#10;</xsl:text>
221       <xsl:choose>
222         <xsl:when test="self::d:literallayout|self::d:programlisting|self::d:screen
223           and not(ancestor::*[local-name() = 'refsynopsisdiv'])
224           and not($man.output.better.ps.enabled = 0)
225           ">
226           <!-- * if this is a literallayout|programlisting|screen, -->
227           <!-- * and user has set man.output.better.ps.enabled to non-zero, -->
228           <!-- * then we put a background behind it in non-TTY output; except -->
229           <!-- * if it’s a descendant of a refsynopsisdiv (as can be -->
230           <!-- * found in the git docs) -->
231           <xsl:choose>
232             <!-- * if content has a leading newline, we need to back up -->
233             <!-- * one line vertically to get it boxed correctly -->
234             <xsl:when test="not($adjust-for-leading-newline = '')">
235               <xsl:call-template name="roff-if-start">
236                 <xsl:with-param name="condition">t</xsl:with-param>
237               </xsl:call-template>
238               <xsl:text>.sp -1&#10;</xsl:text>
239               <xsl:call-template name="roff-if-end"/>
240               <xsl:text>.BB lightgray</xsl:text>
241               <xsl:text> </xsl:text>
242               <xsl:text>adjust-for-leading-newline&#10;</xsl:text>
243               <!-- * in non-TTY output, for the case where we have a -->
244               <!-- * leading newline, we need to also back up one line -->
245               <!-- * vertically inside the background box -->
246               <xsl:text>.sp -1&#10;</xsl:text>
247             </xsl:when>
248             <xsl:otherwise>
249               <xsl:text>.BB lightgray&#10;</xsl:text>
250             </xsl:otherwise>
251           </xsl:choose>
252           <xsl:apply-templates/>
253           <xsl:text>&#10;</xsl:text>
254           <xsl:choose>
255             <xsl:when test="not($adjust-for-leading-newline = '')">
256               <xsl:text>.EB lightgray</xsl:text>
257               <xsl:text> </xsl:text>
258               <xsl:text>adjust-for-leading-newline&#10;</xsl:text>
259               <xsl:call-template name="roff-if-start">
260                 <xsl:with-param name="condition">t</xsl:with-param>
261               </xsl:call-template>
262               <!-- * in non-TTY output, for the case where we have a -->
263               <!-- * leading newline, we need to add back at the end of -->
264               <!-- * the content some of the vertical space we chopped -->
265               <!-- * off at the beginning -->
266               <xsl:text>.sp 1&#10;</xsl:text>
267               <xsl:call-template name="roff-if-end"/>
268             </xsl:when>
269             <xsl:otherwise>
270               <xsl:text>.EB lightgray&#10;</xsl:text>
271             </xsl:otherwise>
272           </xsl:choose>
273         </xsl:when>
274         <xsl:otherwise>
275           <!-- * otherwise this is not a literallayout|programlisting|screen, -->
276           <!-- * so we don’t put a background behind -->
277           <xsl:apply-templates/>
278           <xsl:text>&#10;</xsl:text>
279         </xsl:otherwise>
280       </xsl:choose>
281       <xsl:text>.fi&#10;</xsl:text>
282       <xsl:call-template name="verbatim-block-end"/>
283     </xsl:otherwise>
284   </xsl:choose>
285   <xsl:if test="$indent = 'Yes'">
286     <!-- * end indented section -->
287     <xsl:call-template name="roff-if-start"/>
288     <xsl:text>.RE&#10;</xsl:text> 
289     <xsl:call-template name="roff-if-end"/>
290   </xsl:if>
291   <!-- * if this verbatim environment has a following sibling node, -->
292   <!-- * output a line of space to separate the content -->
293   <xsl:if test="following-sibling::text()
294     |following-sibling::d:para
295     |following-sibling::d:simpara">
296     <xsl:text>.sp&#10;</xsl:text>
297   </xsl:if>
298 </xsl:template>
299
300 <!-- ==================================================================== -->
301
302 <xsl:template match="d:table|d:informaltable">
303   <xsl:apply-templates select="." mode="to.tbl">
304     <!--* we call the to.tbl mode with the "source" param so that we can -->
305     <!--* preserve the context information and pass it down to the -->
306     <!--* named templates that do the actual table processing -->
307     <xsl:with-param name="source" select="ancestor::d:refentry/d:refnamediv[1]/d:refname[1]"/>
308   </xsl:apply-templates>
309 </xsl:template>
310
311 <!-- ==================================================================== -->
312
313 <xsl:template match="d:informalexample">
314   <xsl:apply-templates/>
315 </xsl:template>
316
317 <!-- ==================================================================== -->
318
319 <xsl:template match="d:figure|d:example">
320   <xsl:variable name="param.placement"
321                 select="substring-after(normalize-space($formal.title.placement),
322                         concat(local-name(.), ' '))"/>
323
324   <xsl:variable name="placement">
325     <xsl:choose>
326       <xsl:when test="contains($param.placement, ' ')">
327         <xsl:value-of select="substring-before($param.placement, ' ')"/>
328       </xsl:when>
329       <xsl:when test="$param.placement = ''">before</xsl:when>
330       <xsl:otherwise>
331         <xsl:value-of select="$param.placement"/>
332       </xsl:otherwise>
333     </xsl:choose>
334   </xsl:variable>
335
336   <xsl:text>.PP&#10;</xsl:text>
337   <xsl:call-template name="formal.object">
338     <xsl:with-param name="placement" select="$placement"/>
339   </xsl:call-template>
340   <xsl:text>&#10;</xsl:text>
341 </xsl:template>
342
343 <!-- ==================================================================== -->
344
345 <xsl:template match="d:mediaobject">
346   <xsl:text>.sp</xsl:text>
347   <xsl:text>&#10;</xsl:text>
348   <xsl:text>.RS</xsl:text> 
349   <xsl:if test="not($list-indent = '')">
350     <xsl:text> </xsl:text>
351     <xsl:value-of select="$list-indent"/>
352   </xsl:if>
353   <xsl:text>&#10;</xsl:text>
354   <xsl:apply-templates/>
355   <xsl:text>&#10;</xsl:text>
356   <xsl:text>.RE&#10;</xsl:text>
357 </xsl:template>
358
359 <xsl:template match="d:imageobject">
360   <xsl:text>[IMAGE]</xsl:text>
361   <xsl:apply-templates/>
362   <xsl:text>&#10;</xsl:text>
363 </xsl:template>
364
365 <xsl:template match="d:textobject[parent::d:inlinemediaobject]">
366   <xsl:text>[</xsl:text>
367   <xsl:value-of select="."/>
368   <xsl:text>]</xsl:text>
369 </xsl:template>
370
371 <xsl:template match="d:textobject">
372   <xsl:apply-templates/>
373 </xsl:template>
374
375 <!-- ==================================================================== -->
376
377 <xsl:template name="formal.object">
378   <xsl:param name="placement" select="'before'"/>
379   <xsl:param name="class" select="local-name(.)"/>
380
381   <xsl:choose>
382     <xsl:when test="$placement = 'before'">
383       <xsl:call-template name="formal.object.heading"/>
384       <xsl:apply-templates/>
385     </xsl:when>
386     <xsl:otherwise>
387       <xsl:apply-templates/>
388       <xsl:call-template name="formal.object.heading"/>
389     </xsl:otherwise>
390   </xsl:choose>
391 </xsl:template>
392
393 <xsl:template name="formal.object.heading">
394   <xsl:param name="object" select="."/>
395   <xsl:param name="title">
396     <xsl:apply-templates select="$object" mode="object.title.markup.textonly"/>
397   </xsl:param>
398   <xsl:call-template name="bold">
399     <xsl:with-param name="node" select="exsl:node-set($title)"/>
400     <xsl:with-param name="context" select="."/>
401   </xsl:call-template>
402
403   <xsl:text>&#10;</xsl:text>
404 </xsl:template>
405
406 <!-- ==================================================================== -->
407
408 <!-- * suppress abstract -->
409 <xsl:template match="d:abstract"/>
410
411 </xsl:stylesheet>