]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
man: handle leading/trailing/repeating whitespaces in anchor links
authorFrantisek Sumsal <frantisek@sumsal.cz>
Thu, 23 Oct 2025 13:30:52 +0000 (15:30 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Thu, 23 Oct 2025 13:42:28 +0000 (15:42 +0200)
So even if a <term> section contains newlines, we get a reasonable
anchor link to it.

Before:
<dt id="
  bind
  UNIT
  PATH
  [PATH]
"><span class="term">
...
<a class="headerlink" title="Permalink to this term" href="#%0A%20%20%20%20%20%20%20%20%20%20%20%20bind%0A%20%20%20%20%20%20%20%20%20%20%20%20UNIT%0A%20%20%20%20%20%20%20%20%20%20%20%20PATH%0A%20%20%20%20%20%20%20%20%20%20%20%20[PATH]%0A%20%20%20%20%20%20%20%20%20%20">¶</a>

After:
<dt id="bind UNIT PATH [PATH]"><span class="term">
...
<a class="headerlink" title="Permalink to this term" href="#bind%20UNIT%20PATH%20[PATH]">¶</a>

Resolves: #39196

man/custom-html.xsl

index 98ec95303d7928f33771373737d581acedf681f1..45cd1f922d639787bde2d169226e2456ac9d259d 100644 (file)
   <xsl:param name="keyNode"/>
   <!-- suggested value for generatedID output, a contextually meaningful ID string -->
   <xsl:param name="templateID"/>
+  <!-- Strip leading and trailing whitespaces, and replace repeating whitespaces with a single space -->
+  <xsl:variable name="normalizedID" select="normalize-space($templateID)"/>
   <xsl:variable name="conflictSource" select="preceding::refsect1/title|preceding::refsect1/info/title|
                                              preceding::refsect2/title|preceding::refsect2/info/title|
                                              preceding::varlistentry/term[1]"/>
   <xsl:choose>
     <!-- special case conflictCount = 0 to preserve compatibility with URLs generated by previous versions of this XSL stylesheet where possible -->
     <xsl:when test="$conflictCount = 0">
-      <xsl:value-of select="$templateID"/>
+      <xsl:value-of select="$normalizedID"/>
     </xsl:when>
     <xsl:otherwise>
-      <xsl:value-of select="concat($templateID, $conflictCount)"/>
+      <xsl:value-of select="concat($normalizedID, $conflictCount)"/>
     </xsl:otherwise>
   </xsl:choose>
 </xsl:template>