Skip to content

Commit 85c63fa

Browse files
committed
IBX-8258: richtext: Html5Input is not washed for duplicate IDs
1 parent 314fd1f commit 85c63fa

File tree

5 files changed

+472
-56
lines changed

5 files changed

+472
-56
lines changed

src/lib/eZ/RichText/Resources/stylesheets/xhtml5/edit/docbook.xsl

+57-53
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
version="1.0">
1010
<xsl:output indent="yes" encoding="UTF-8"/>
1111

12+
<xsl:key name="ids" match="*[@id]" use="@id"/>
13+
<xsl:key name="ids" match="ezxhtml5:a[@name]" use="@name"/>
14+
1215
<xsl:template match="/ezxhtml5:section">
1316
<section xmlns="http://docbook.org/ns/docbook"
1417
xmlns:xlink="http://www.w3.org/1999/xlink"
@@ -85,13 +88,30 @@
8588
</xsl:choose>
8689
</xsl:template>
8790

91+
<xsl:template name="conditionallyAddIdAttribute">
92+
<xsl:param name="attribute"/>
93+
94+
<xsl:if test="$attribute">
95+
<xsl:choose>
96+
<xsl:when test="count(key('ids', $attribute)) &gt; 1">
97+
<xsl:attribute name="xml:id">
98+
<xsl:value-of select="concat($attribute, '_', generate-id(.))"/>
99+
</xsl:attribute>
100+
</xsl:when>
101+
<xsl:otherwise>
102+
<xsl:attribute name="xml:id">
103+
<xsl:value-of select="$attribute"/>
104+
</xsl:attribute>
105+
</xsl:otherwise>
106+
</xsl:choose>
107+
</xsl:if>
108+
</xsl:template>
109+
88110
<xsl:template match="ezxhtml5:p" name="paragraph">
89111
<para>
90-
<xsl:if test="@id">
91-
<xsl:attribute name="xml:id">
92-
<xsl:value-of select="@id"/>
93-
</xsl:attribute>
94-
</xsl:if>
112+
<xsl:call-template name="conditionallyAddIdAttribute">
113+
<xsl:with-param name="attribute" select="@id"/>
114+
</xsl:call-template>
95115
<xsl:if test="@class">
96116
<xsl:attribute name="ezxhtml:class">
97117
<xsl:value-of select="@class"/>
@@ -125,11 +145,9 @@
125145

126146
<xsl:template match="ezxhtml5:pre">
127147
<xsl:element name="programlisting">
128-
<xsl:if test="@id">
129-
<xsl:attribute name="xml:id">
130-
<xsl:value-of select="@id"/>
131-
</xsl:attribute>
132-
</xsl:if>
148+
<xsl:call-template name="conditionallyAddIdAttribute">
149+
<xsl:with-param name="attribute" select="@id"/>
150+
</xsl:call-template>
133151
<xsl:if test="@class">
134152
<xsl:attribute name="ezxhtml:class">
135153
<xsl:value-of select="@class"/>
@@ -243,11 +261,9 @@
243261
</xsl:otherwise>
244262
</xsl:choose>
245263
</xsl:attribute>
246-
<xsl:if test="@id">
247-
<xsl:attribute name="xml:id">
248-
<xsl:value-of select="@id"/>
249-
</xsl:attribute>
250-
</xsl:if>
264+
<xsl:call-template name="conditionallyAddIdAttribute">
265+
<xsl:with-param name="attribute" select="@id"/>
266+
</xsl:call-template>
251267
<xsl:if test="@title">
252268
<xsl:attribute name="xlink:title">
253269
<xsl:value-of select="@title"/>
@@ -268,13 +284,13 @@
268284
<xsl:template name="link.anchor">
269285
<xsl:param name="attribute"/>
270286
<anchor>
271-
<xsl:attribute name="xml:id">
272-
<xsl:value-of select="$attribute"/>
273-
</xsl:attribute>
287+
<xsl:call-template name="conditionallyAddIdAttribute">
288+
<xsl:with-param name="attribute" select="$attribute"/>
289+
</xsl:call-template>
274290
</anchor>
275291
</xsl:template>
276292

277-
<xsl:template match="ezxhtml5:a[not(@name=preceding::ezxhtml5:a/@name)]">
293+
<xsl:template match="ezxhtml5:a">
278294
<xsl:choose>
279295
<xsl:when test="@href">
280296
<xsl:call-template name="link.href"/>
@@ -307,11 +323,9 @@
307323
<xsl:value-of select="@class"/>
308324
</xsl:attribute>
309325
</xsl:if>
310-
<xsl:if test="@id">
311-
<xsl:attribute name="xml:id">
312-
<xsl:value-of select="@id"/>
313-
</xsl:attribute>
314-
</xsl:if>
326+
<xsl:call-template name="conditionallyAddIdAttribute">
327+
<xsl:with-param name="attribute" select="@id"/>
328+
</xsl:call-template>
315329
<xsl:if test="contains( @style, 'text-align:' )">
316330
<xsl:variable name="textAlign">
317331
<xsl:call-template name="extractTextAlignValue">
@@ -334,11 +348,9 @@
334348

335349
<xsl:template match="ezxhtml5:ol">
336350
<orderedlist>
337-
<xsl:if test="@id">
338-
<xsl:attribute name="xml:id">
339-
<xsl:value-of select="@id"/>
340-
</xsl:attribute>
341-
</xsl:if>
351+
<xsl:call-template name="conditionallyAddIdAttribute">
352+
<xsl:with-param name="attribute" select="@id"/>
353+
</xsl:call-template>
342354
<xsl:if test="@class">
343355
<xsl:attribute name="ezxhtml:class">
344356
<xsl:value-of select="@class"/>
@@ -351,11 +363,9 @@
351363

352364
<xsl:template match="ezxhtml5:ul">
353365
<itemizedlist>
354-
<xsl:if test="@id">
355-
<xsl:attribute name="xml:id">
356-
<xsl:value-of select="@id"/>
357-
</xsl:attribute>
358-
</xsl:if>
366+
<xsl:call-template name="conditionallyAddIdAttribute">
367+
<xsl:with-param name="attribute" select="@id"/>
368+
</xsl:call-template>
359369
<xsl:if test="@class">
360370
<xsl:attribute name="ezxhtml:class">
361371
<xsl:value-of select="@class"/>
@@ -397,11 +407,9 @@
397407
</xsl:choose>
398408
</xsl:variable>
399409
<xsl:element name="{$tablename}" namespace="http://docbook.org/ns/docbook">
400-
<xsl:if test="@id">
401-
<xsl:attribute name="xml:id">
402-
<xsl:value-of select="@id"/>
403-
</xsl:attribute>
404-
</xsl:if>
410+
<xsl:call-template name="conditionallyAddIdAttribute">
411+
<xsl:with-param name="attribute" select="@id"/>
412+
</xsl:call-template>
405413
<xsl:if test="@class">
406414
<xsl:attribute name="class">
407415
<xsl:value-of select="@class"/>
@@ -625,11 +633,9 @@
625633
</xsl:template>
626634

627635
<xsl:template name="addCommonEmbedAttributes">
628-
<xsl:if test="@id">
629-
<xsl:attribute name="xml:id">
630-
<xsl:value-of select="@id"/>
631-
</xsl:attribute>
632-
</xsl:if>
636+
<xsl:call-template name="conditionallyAddIdAttribute">
637+
<xsl:with-param name="attribute" select="@id"/>
638+
</xsl:call-template>
633639
<xsl:if test="@data-href">
634640
<xsl:attribute name="xlink:href">
635641
<xsl:value-of select="@data-href"/>
@@ -672,11 +678,9 @@
672678
<xsl:value-of select="@title"/>
673679
</xsl:attribute>
674680
</xsl:if>
675-
<xsl:if test="@id">
676-
<xsl:attribute name="xml:id">
677-
<xsl:value-of select="@id"/>
678-
</xsl:attribute>
679-
</xsl:if>
681+
<xsl:call-template name="conditionallyAddIdAttribute">
682+
<xsl:with-param name="attribute" select="@id"/>
683+
</xsl:call-template>
680684
<xsl:if test="@class">
681685
<xsl:attribute name="ezxhtml:class">
682686
<xsl:value-of select="@class"/>
@@ -721,10 +725,10 @@
721725
<xsl:value-of select="@class"/>
722726
</xsl:attribute>
723727
</xsl:if>
724-
<xsl:if test="@id">
725-
<xsl:attribute name="xml:id">
726-
<xsl:value-of select="@id"/>
727-
</xsl:attribute>
728+
<xsl:if test="@data-ezelement='eztemplate'">
729+
<xsl:call-template name="conditionallyAddIdAttribute">
730+
<xsl:with-param name="attribute" select="@id"/>
731+
</xsl:call-template>
728732
</xsl:if>
729733
<xsl:if test="contains( @style, 'text-align:' )">
730734
<xsl:variable name="textAlign">

tests/lib/eZ/RichText/Converter/Xslt/_fixtures/xhtml5/edit/lossy/008-anchor.docbook.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom"
77
version="5.0-variant ezpublish-1.0">
88
<para><anchor xml:id="top"/>some anchor with a name attribute.</para>
9-
<para><anchor xml:id="bottom"/>some anchor with a name attribute.</para>
10-
<para>another anchor that should be removed due to lack of name uniqueness.</para>
9+
<para><anchor xml:id="bottom_idm5"/>some anchor with a name attribute.</para>
10+
<para><anchor xml:id="bottom_idm7"/>another anchor with the same name attribute.</para>
1111
</section>

tests/lib/eZ/RichText/Converter/Xslt/_fixtures/xhtml5/edit/lossy/008-anchor.xhtml5.edit.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
<section xmlns="http://ez.no/namespaces/ezpublish5/xhtml5/edit">
33
<p><a name="top"/>some anchor with a name attribute.</p>
44
<p><a name="bottom"/>some anchor with a name attribute.</p>
5-
<p><a name="bottom"/>another anchor that should be removed due to lack of name uniqueness.</p>
5+
<p><a name="bottom"/>another anchor with the same name attribute.</p>
66
</section>

0 commit comments

Comments
 (0)