man: handle leading/trailing/repeating whitespaces in anchor links (#39423)

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: https://github.com/systemd/systemd/issues/39196

---

The reverts are not strictly necessary here (as already pointed out in
https://github.com/systemd/systemd/pull/39154#issuecomment-3360118164)
but they were helpful in checking if the fix works as expected. I can
drop them if needed.
This commit is contained in:
Yu Watanabe
2025-10-28 15:28:54 +09:00
committed by GitHub
2 changed files with 29 additions and 8 deletions

View File

@@ -158,6 +158,8 @@
<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]"/>
@@ -165,10 +167,10 @@
<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>

View File

@@ -375,7 +375,10 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
</varlistentry>
<varlistentry>
<term><command>list-dependencies</command> <optional><replaceable>UNIT</replaceable></optional></term>
<term>
<command>list-dependencies</command>
<optional><replaceable>UNIT</replaceable>...</optional>
</term>
<listitem>
<para>Shows units required and wanted by the specified
@@ -691,7 +694,12 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
</varlistentry>
<varlistentry>
<term><command>bind</command> <replaceable>UNIT</replaceable> <replaceable>PATH</replaceable> [<replaceable>PATH</replaceable>]</term>
<term>
<command>bind</command>
<replaceable>UNIT</replaceable>
<replaceable>PATH</replaceable>
[<replaceable>PATH</replaceable>]
</term>
<listitem><para>Bind-mounts a file or directory from the host into the specified unit's mount
namespace. The first path argument is the source file or directory on the host, the second path
@@ -718,7 +726,13 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
</varlistentry>
<varlistentry>
<term><command>mount-image</command> <replaceable>UNIT</replaceable> <replaceable>IMAGE</replaceable> [<replaceable>PATH</replaceable> [<replaceable>PARTITION_NAME</replaceable>:<replaceable>MOUNT_OPTIONS</replaceable>]]</term>
<term>
<command>mount-image</command>
<replaceable>UNIT</replaceable>
<replaceable>IMAGE</replaceable>
[<replaceable>PATH</replaceable>
[<replaceable>PARTITION_NAME</replaceable>:<replaceable>MOUNT_OPTIONS</replaceable>]]
</term>
<listitem><para>Mounts an image from the host into the specified unit's mount namespace. The first
path argument is the source image on the host, the second path argument is the destination
@@ -1201,8 +1215,10 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
</varlistentry>
<varlistentry>
<term><command>add-wants <replaceable>TARGET</replaceable> <replaceable>UNIT</replaceable></command></term>
<term><command>add-requires <replaceable>TARGET</replaceable> <replaceable>UNIT</replaceable></command></term>
<term><command>add-wants <replaceable>TARGET</replaceable>
<replaceable>UNIT</replaceable></command></term>
<term><command>add-requires <replaceable>TARGET</replaceable>
<replaceable>UNIT</replaceable></command></term>
<listitem>
<para>Adds <literal>Wants=</literal> or <literal>Requires=</literal>
@@ -1428,7 +1444,10 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err
</listitem>
</varlistentry>
<varlistentry>
<term><command>import-environment</command> <replaceable>VARIABLE…</replaceable></term>
<term>
<command>import-environment</command>
<replaceable>VARIABLE…</replaceable>
</term>
<listitem>
<para>Import all, one or more environment variables set on the client into the systemd manager