]> xenbits.xensource.com Git - libvirt.git/commitdiff
docs: newapi: Avoid empty <div>s when there is no description
authorPeter Krempa <pkrempa@redhat.com>
Thu, 29 Feb 2024 12:06:39 +0000 (13:06 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 1 Mar 2024 11:51:56 +0000 (12:51 +0100)
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>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
docs/newapi.xsl

index b60680ae97d261f5aad4c4108724e8eab6b6d418..539e0a4175873dc6e2bdf01f729edd8ab38d2e95 100644 (file)
     </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>
   <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>
         <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">
     <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>
 
     <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">
     </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">