[PATCH] docs: page.xsl: Improve generation of paragraph anchor links

Peter Krempa posted 1 patch 3 years, 5 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/6b1c26b43797899b8f8a3305d4e583cc39a661e6.1603716632.git.pkrempa@redhat.com
docs/page.xsl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] docs: page.xsl: Improve generation of paragraph anchor links
Posted by Peter Krempa 3 years, 5 months ago
Use the 'parent' axis to check whether the parent is a div with
class='section' rather than looking for 'toc-backref' anchor to see
whether to generate one of the headerlink alternatives. Both hare
docutils-specific thus apply to docs generated from RST documents.

This adds the links for pages generated from RST documents which don't
have a table of contents (and thus lack the 'toc-backref' anchors) and
thus fixes pages such as hacking.html and news.html to have reasonable
links which can be shared.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---

Note that whether or not to add table of contents to hacking.rst is out
of scope of this patch.

 docs/page.xsl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/docs/page.xsl b/docs/page.xsl
index 36168305fa..07bfc52a4c 100644
--- a/docs/page.xsl
+++ b/docs/page.xsl
@@ -196,7 +196,7 @@
       <xsl:if test="./html:a/@id">
         <a class="headerlink" href="#{html:a/@id}" title="Permalink to this headline">&#xb6;</a>
       </xsl:if>
-      <xsl:if test="./html:a[@class='toc-backref']">
+      <xsl:if test="parent::html:div[@class='section']">
         <a class="headerlink" href="#{../@id}" title="Permalink to this headline">&#xb6;</a>
       </xsl:if>
     </xsl:element>
-- 
2.26.2

Re: [PATCH] docs: page.xsl: Improve generation of paragraph anchor links
Posted by Michal Privoznik 3 years, 5 months ago
On 10/26/20 1:51 PM, Peter Krempa wrote:
> Use the 'parent' axis to check whether the parent is a div with
> class='section' rather than looking for 'toc-backref' anchor to see
> whether to generate one of the headerlink alternatives. Both hare
> docutils-specific thus apply to docs generated from RST documents.
> 
> This adds the links for pages generated from RST documents which don't
> have a table of contents (and thus lack the 'toc-backref' anchors) and
> thus fixes pages such as hacking.html and news.html to have reasonable
> links which can be shared.
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
> 
> Note that whether or not to add table of contents to hacking.rst is out
> of scope of this patch.
> 
>   docs/page.xsl | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal