Skip to content

Commit

Permalink
IBX-8258: richtext: Html5Input is not washed for duplicate IDs (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
vidarl authored Jul 4, 2024
1 parent 314fd1f commit 59149ee
Show file tree
Hide file tree
Showing 5 changed files with 472 additions and 56 deletions.
110 changes: 57 additions & 53 deletions src/lib/eZ/RichText/Resources/stylesheets/xhtml5/edit/docbook.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
version="1.0">
<xsl:output indent="yes" encoding="UTF-8"/>

<xsl:key name="ids" match="*[@id]" use="@id"/>
<xsl:key name="ids" match="ezxhtml5:a[@name]" use="@name"/>

<xsl:template match="/ezxhtml5:section">
<section xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
Expand Down Expand Up @@ -85,13 +88,30 @@
</xsl:choose>
</xsl:template>

<xsl:template name="addUniqueIdAttribute">
<xsl:param name="attribute"/>

<xsl:if test="$attribute">
<xsl:choose>
<xsl:when test="count(key('ids', $attribute)) &gt; 1">
<xsl:attribute name="xml:id">
<xsl:value-of select="concat($attribute, '_', generate-id(.))"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="xml:id">
<xsl:value-of select="$attribute"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:template>

<xsl:template match="ezxhtml5:p" name="paragraph">
<para>
<xsl:if test="@id">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="@id"/>
</xsl:call-template>
<xsl:if test="@class">
<xsl:attribute name="ezxhtml:class">
<xsl:value-of select="@class"/>
Expand Down Expand Up @@ -125,11 +145,9 @@

<xsl:template match="ezxhtml5:pre">
<xsl:element name="programlisting">
<xsl:if test="@id">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="@id"/>
</xsl:call-template>
<xsl:if test="@class">
<xsl:attribute name="ezxhtml:class">
<xsl:value-of select="@class"/>
Expand Down Expand Up @@ -243,11 +261,9 @@
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:if test="@id">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="@id"/>
</xsl:call-template>
<xsl:if test="@title">
<xsl:attribute name="xlink:title">
<xsl:value-of select="@title"/>
Expand All @@ -268,13 +284,13 @@
<xsl:template name="link.anchor">
<xsl:param name="attribute"/>
<anchor>
<xsl:attribute name="xml:id">
<xsl:value-of select="$attribute"/>
</xsl:attribute>
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="$attribute"/>
</xsl:call-template>
</anchor>
</xsl:template>

<xsl:template match="ezxhtml5:a[not(@name=preceding::ezxhtml5:a/@name)]">
<xsl:template match="ezxhtml5:a">
<xsl:choose>
<xsl:when test="@href">
<xsl:call-template name="link.href"/>
Expand Down Expand Up @@ -307,11 +323,9 @@
<xsl:value-of select="@class"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@id">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="@id"/>
</xsl:call-template>
<xsl:if test="contains( @style, 'text-align:' )">
<xsl:variable name="textAlign">
<xsl:call-template name="extractTextAlignValue">
Expand All @@ -334,11 +348,9 @@

<xsl:template match="ezxhtml5:ol">
<orderedlist>
<xsl:if test="@id">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="@id"/>
</xsl:call-template>
<xsl:if test="@class">
<xsl:attribute name="ezxhtml:class">
<xsl:value-of select="@class"/>
Expand All @@ -351,11 +363,9 @@

<xsl:template match="ezxhtml5:ul">
<itemizedlist>
<xsl:if test="@id">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="@id"/>
</xsl:call-template>
<xsl:if test="@class">
<xsl:attribute name="ezxhtml:class">
<xsl:value-of select="@class"/>
Expand Down Expand Up @@ -397,11 +407,9 @@
</xsl:choose>
</xsl:variable>
<xsl:element name="{$tablename}" namespace="http://docbook.org/ns/docbook">
<xsl:if test="@id">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="@id"/>
</xsl:call-template>
<xsl:if test="@class">
<xsl:attribute name="class">
<xsl:value-of select="@class"/>
Expand Down Expand Up @@ -625,11 +633,9 @@
</xsl:template>

<xsl:template name="addCommonEmbedAttributes">
<xsl:if test="@id">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="@id"/>
</xsl:call-template>
<xsl:if test="@data-href">
<xsl:attribute name="xlink:href">
<xsl:value-of select="@data-href"/>
Expand Down Expand Up @@ -672,11 +678,9 @@
<xsl:value-of select="@title"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@id">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
</xsl:if>
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="@id"/>
</xsl:call-template>
<xsl:if test="@class">
<xsl:attribute name="ezxhtml:class">
<xsl:value-of select="@class"/>
Expand Down Expand Up @@ -721,10 +725,10 @@
<xsl:value-of select="@class"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@id">
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
</xsl:attribute>
<xsl:if test="@data-ezelement='eztemplate'">
<xsl:call-template name="addUniqueIdAttribute">
<xsl:with-param name="attribute" select="@id"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="contains( @style, 'text-align:' )">
<xsl:variable name="textAlign">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom"
version="5.0-variant ezpublish-1.0">
<para><anchor xml:id="top"/>some anchor with a name attribute.</para>
<para><anchor xml:id="bottom"/>some anchor with a name attribute.</para>
<para>another anchor that should be removed due to lack of name uniqueness.</para>
<para><anchor xml:id="bottom_idm5"/>some anchor with a name attribute.</para>
<para><anchor xml:id="bottom_idm7"/>another anchor with the same name attribute.</para>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<section xmlns="http://ez.no/namespaces/ezpublish5/xhtml5/edit">
<p><a name="top"/>some anchor with a name attribute.</p>
<p><a name="bottom"/>some anchor with a name attribute.</p>
<p><a name="bottom"/>another anchor that should be removed due to lack of name uniqueness.</p>
<p><a name="bottom"/>another anchor with the same name attribute.</p>
</section>
Loading

0 comments on commit 59149ee

Please sign in to comment.