[prev in list] [next in list] [prev in thread] [next in thread] 

List:       libvir-list
Subject:    [PATCH 6/9] docs: newapi: Avoid empty <div>s when there is no description
From:       Peter Krempa <pkrempa () redhat ! com>
Date:       2024-02-29 14:58:20
Message-ID: 237ca029e7a5170f56278af8c3fb27f4805f125d.1709218314.git.pkrempa () redhat ! com
[Download RAW message or body]

The various objects we generate API for may have empty description in
which case an empty div would be generated when processing the API
description. As we're using XML output mode the generator would shorten
such divs to the non-pair empty element version, which doesn't work well
with HTML5 parsers requiring a pair tag for <div>

Avoid empty description <div> elements altogether by skipping it if the
description is empty.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 docs/newapi.xsl | 40 +++++++++++++++++++++++++---------------
 1 file changed, 25 insertions(+), 15 deletions(-)

diff --git a/docs/newapi.xsl b/docs/newapi.xsl
index b60680ae97..539e0a4175 100644
--- a/docs/newapi.xsl
+++ b/docs/newapi.xsl
@@ -222,6 +222,19 @@
     </xsl:if>
   </xsl:template>

+  <xsl:template name="formattextdiv">
+    <xsl:param name="text"/>
+    <xsl:param name="divclass"/>
+
+    <xsl:if test="$text">
+      <div class="{$divclass}">
+        <xsl:call-template name="formattext">
+          <xsl:with-param name="text" select="$text"/>
+        </xsl:call-template>
+      </div>
+    </xsl:if>
+  </xsl:template>
+
   <xsl:template match="macro" mode="toc">
     <span class="directive">#define</span><xsl:text> </xsl:text>
     <a href="#{@name}"><xsl:value-of select="@name"/></a>
@@ -287,11 +300,10 @@
   <xsl:template match="typedef[@type = 'enum']">
     <xsl:variable name="name" select="string(@name)"/>
     <h3><a id="{$name}"><code><xsl:value-of select="$name"/></code></a></h3>
-    <div class="description">
-    <xsl:call-template name="formattext">
+    <xsl:call-template name="formattextdiv">
       <xsl:with-param name="text" select="info"/>
+      <xsl:with-param name="divclass">description</xsl:with-param>
     </xsl:call-template>
-    </div>
     <div class="api">
       <pre>
         <span class="keyword">enum</span><xsl:text> </xsl:text>
@@ -343,11 +355,10 @@
         <xsl:text>;</xsl:text>
       </pre>
     </div>
-    <div class="description">
-    <xsl:call-template name="formattext">
+    <xsl:call-template name="formattextdiv">
       <xsl:with-param name="text" select="info"/>
+      <xsl:with-param name="divclass">description</xsl:with-param>
     </xsl:call-template>
-    </div>
   </xsl:template>

   <xsl:template match="struct" mode="toc">
@@ -452,11 +463,11 @@
     <xsl:variable name="name" select="string(@name)"/>
     <h3><a id="{$name}"><code><xsl:value-of select="$name"/></code></a></h3>
     <pre class="api"><span class="directive">#define</span><xsl:text> \
                </xsl:text><xsl:value-of select="$name"/></pre>
-    <div class="description">
-    <xsl:call-template name="formattext">
+    <xsl:call-template name="formattextdiv">
       <xsl:with-param name="text" select="info"/>
+      <xsl:with-param name="divclass">description</xsl:with-param>
     </xsl:call-template>
-    </div><xsl:text>
+    <xsl:text>
 </xsl:text>
   </xsl:template>

@@ -604,11 +615,10 @@
     <xsl:text>)
 </xsl:text>
     </pre>
-    <div class="description">
-    <xsl:call-template name="formattext">
+    <xsl:call-template name="formattextdiv">
       <xsl:with-param name="text" select="info"/>
+      <xsl:with-param name="divclass">description</xsl:with-param>
     </xsl:call-template>
-    </div>
     <xsl:if test="arg | return">
       <dl class="variablelist">
       <xsl:for-each select="arg">
@@ -680,11 +690,11 @@
     </xsl:for-each>
     <xsl:text>)</xsl:text>
     </pre>
-    <div class="description">
-    <xsl:call-template name="formattext">
+    <xsl:call-template name="formattextdiv">
       <xsl:with-param name="text" select="info"/>
+      <xsl:with-param name="divclass">description</xsl:with-param>
     </xsl:call-template>
-    </div><xsl:text>
+    <xsl:text>
 </xsl:text>
     <xsl:if test="arg | return/@info">
       <dl class="variablelist">
-- 
2.43.0
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic