docs: newapi: Avoid empty <div>s when there is no description

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>
This commit is contained in:
Peter Krempa 2024-02-29 13:06:39 +01:00
parent 3a0af92df6
commit 47a8ff9979

View File

@ -222,6 +222,19 @@
</xsl:if> </xsl:if>
</xsl:template> </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"> <xsl:template match="macro" mode="toc">
<span class="directive">#define</span><xsl:text> </xsl:text> <span class="directive">#define</span><xsl:text> </xsl:text>
<a href="#{@name}"><xsl:value-of select="@name"/></a> <a href="#{@name}"><xsl:value-of select="@name"/></a>
@ -287,11 +300,10 @@
<xsl:template match="typedef[@type = 'enum']"> <xsl:template match="typedef[@type = 'enum']">
<xsl:variable name="name" select="string(@name)"/> <xsl:variable name="name" select="string(@name)"/>
<h3><a id="{$name}"><code><xsl:value-of select="$name"/></code></a></h3> <h3><a id="{$name}"><code><xsl:value-of select="$name"/></code></a></h3>
<div class="description"> <xsl:call-template name="formattextdiv">
<xsl:call-template name="formattext">
<xsl:with-param name="text" select="info"/> <xsl:with-param name="text" select="info"/>
<xsl:with-param name="divclass">description</xsl:with-param>
</xsl:call-template> </xsl:call-template>
</div>
<div class="api"> <div class="api">
<pre> <pre>
<span class="keyword">enum</span><xsl:text> </xsl:text> <span class="keyword">enum</span><xsl:text> </xsl:text>
@ -343,11 +355,10 @@
<xsl:text>;</xsl:text> <xsl:text>;</xsl:text>
</pre> </pre>
</div> </div>
<div class="description"> <xsl:call-template name="formattextdiv">
<xsl:call-template name="formattext">
<xsl:with-param name="text" select="info"/> <xsl:with-param name="text" select="info"/>
<xsl:with-param name="divclass">description</xsl:with-param>
</xsl:call-template> </xsl:call-template>
</div>
</xsl:template> </xsl:template>
<xsl:template match="struct" mode="toc"> <xsl:template match="struct" mode="toc">
@ -452,11 +463,11 @@
<xsl:variable name="name" select="string(@name)"/> <xsl:variable name="name" select="string(@name)"/>
<h3><a id="{$name}"><code><xsl:value-of select="$name"/></code></a></h3> <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> <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="formattextdiv">
<xsl:call-template name="formattext">
<xsl:with-param name="text" select="info"/> <xsl:with-param name="text" select="info"/>
<xsl:with-param name="divclass">description</xsl:with-param>
</xsl:call-template> </xsl:call-template>
</div><xsl:text> <xsl:text>
</xsl:text> </xsl:text>
</xsl:template> </xsl:template>
@ -604,11 +615,10 @@
<xsl:text>) <xsl:text>)
</xsl:text> </xsl:text>
</pre> </pre>
<div class="description"> <xsl:call-template name="formattextdiv">
<xsl:call-template name="formattext">
<xsl:with-param name="text" select="info"/> <xsl:with-param name="text" select="info"/>
<xsl:with-param name="divclass">description</xsl:with-param>
</xsl:call-template> </xsl:call-template>
</div>
<xsl:if test="arg | return"> <xsl:if test="arg | return">
<dl class="variablelist"> <dl class="variablelist">
<xsl:for-each select="arg"> <xsl:for-each select="arg">
@ -680,11 +690,11 @@
</xsl:for-each> </xsl:for-each>
<xsl:text>)</xsl:text> <xsl:text>)</xsl:text>
</pre> </pre>
<div class="description"> <xsl:call-template name="formattextdiv">
<xsl:call-template name="formattext">
<xsl:with-param name="text" select="info"/> <xsl:with-param name="text" select="info"/>
<xsl:with-param name="divclass">description</xsl:with-param>
</xsl:call-template> </xsl:call-template>
</div><xsl:text> <xsl:text>
</xsl:text> </xsl:text>
<xsl:if test="arg | return/@info"> <xsl:if test="arg | return/@info">
<dl class="variablelist"> <dl class="variablelist">