block.xsl 16 KB

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