Skip to content

Commit

Permalink
EZP-31272: Handled anchors generated with name attribute (#107)
Browse files Browse the repository at this point in the history
* EZP-31272: Handled anchors generated with name attribute

* added checking whether anchor names can be mapped to id uniqueness wise

* intentional failed test to check duplicated name attributes

* validation and tests reworked to strip anchors having duplicated names
  • Loading branch information
konradoboza authored Feb 7, 2020
1 parent aa4eded commit 9111ffd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/lib/eZ/RichText/Resources/stylesheets/xhtml5/edit/docbook.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -255,20 +255,28 @@
</xsl:template>

<xsl:template name="link.anchor">
<xsl:param name="attribute"/>
<anchor>
<xsl:attribute name="xml:id">
<xsl:value-of select="@id"/>
<xsl:value-of select="$attribute"/>
</xsl:attribute>
</anchor>
</xsl:template>

<xsl:template match="ezxhtml5:a">
<xsl:template match="ezxhtml5:a[not(@name=preceding::ezxhtml5:a/@name)]">
<xsl:choose>
<xsl:when test="@href">
<xsl:call-template name="link.href"/>
</xsl:when>
<xsl:when test="@id">
<xsl:call-template name="link.anchor"/>
<xsl:call-template name="link.anchor">
<xsl:with-param name="attribute" select="@id"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="@name">
<xsl:call-template name="link.anchor">
<xsl:with-param name="attribute" select="@name"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:message terminate="yes">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<section
xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml"
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>
</section>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
</section>

0 comments on commit 9111ffd

Please sign in to comment.