Skip to content

Commit

Permalink
EZP-29027: Added support for conversion of ezxmltest tag <literal> (e…
Browse files Browse the repository at this point in the history
…zsystems#71)

* Added support for <literal> in ezxmltext to docbook xslt
* Added support for custom attribute language when converting <literal>
* Bump kernel requirement to 6.13.6-dev || 7.2.5-dev
  • Loading branch information
vidarl authored and andrerom committed Oct 5, 2018
1 parent 2cedfa1 commit 0c3743f
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 30 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"ezsystems/ezpublish-kernel": "^6.11@dev || ^7.0@dev",
"ezsystems/ezpublish-kernel": "^6.13.6@dev || ^7.2.5@dev",
"ezsystems/repository-forms": "^1.9 || ^2.0"
},
"require-dev": {
Expand Down
40 changes: 20 additions & 20 deletions lib/FieldType/XmlText/Converter/RichText.php
Expand Up @@ -532,25 +532,6 @@ public function getErrors()
return $this->errors;
}

/**
* @param DOMDocument $document
* @param null|int $contentFieldId
*/
protected function writeWarningOnNonSupportedLiterals(DOMDocument $document, $contentFieldId)
{
$xpath = new DOMXPath($document);

$xpathExpression = '//literal';

$elements = $xpath->query($xpathExpression);

foreach ($elements as $element) {
if ($element->getAttribute('class') !== 'html') {
$this->log(LogLevel::ERROR, "Only literal tag with class=\"html\" supported at the moment. Tag with different class removed where contentobject_attribute.id=$contentFieldId");
}
}
}

/**
* @param DOMDocument $document
* @param null|int $contentFieldId
Expand Down Expand Up @@ -585,6 +566,25 @@ protected function writeWarningOnNonSupportedCustomTags(DOMDocument $document, $
}
}

/**
* CDATA's content cannot contain the sequence ']]>' as that will terminate the CDATA section.
* So, if the end sequence ']]>' appears in the string, we split the text into multiple CDATA sections.
*
* @param DOMDocument $document
*/
protected function encodeLiteral(DOMDocument $document)
{
$xpath = new DOMXPath($document);

$xpathExpression = '//literal[not(@class="html")]';

$elements = $xpath->query($xpathExpression);

foreach ($elements as $element) {
$element->textContent = str_replace(']]>', ']]]]><![CDATA[>', $element->textContent);
}
}

/**
* Before calling this function, make sure you are logged in as admin, or at least have access to all the objects
* being embedded and linked to in the $inputDocument.
Expand All @@ -605,7 +605,7 @@ public function convert(DOMDocument $inputDocument, $checkDuplicateIds = false,
$this->fixLinksWithRemoteIds($inputDocument, $contentFieldId);
$this->flattenLinksInLinks($inputDocument, $contentFieldId);
$this->moveEmbedsInHeaders($inputDocument, $contentFieldId);
$this->writeWarningOnNonSupportedLiterals($inputDocument, $contentFieldId);
$this->encodeLiteral($inputDocument);

try {
$convertedDocument = $this->getConverter()->convert($inputDocument);
Expand Down
Expand Up @@ -103,6 +103,23 @@
</xsl:if>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="programlisting">
<xsl:if test="@class">
<xsl:attribute name="ezxhtml:class">
<xsl:value-of select="@class"/>
</xsl:attribute>
</xsl:if>
<xsl:if test="@custom:language">
<xsl:attribute name="language">
<xsl:value-of select="@custom:language"/>
</xsl:attribute>
</xsl:if>
<xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
<xsl:value-of disable-output-escaping="yes" select="./text()"/>
<xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

Expand Down
Expand Up @@ -3,7 +3,10 @@
xmlns:image="http://ez.no/namespaces/ezpublish3/image/"
xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"
xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/">
<paragraph>next one</paragraph>
<paragraph
xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
<literal>Literal with CNAME end sequence here : ]]&gt; and some more text here</literal>
</paragraph>
<paragraph
xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
<literal>ordinary literal</literal>
Expand All @@ -20,7 +23,7 @@
xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
<literal class="php">function foobar()
{
thisIsSomePHPCode();
thisIsSomePHPCode('string with special characters &amp; &lt; &gt; â');
return 0;
}</literal>
</paragraph>
Expand Down
Expand Up @@ -6,7 +6,7 @@
<paragraph>some text with bold tag</paragraph>
<paragraph
xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
<literal class="html">This is some &lt;b&gt;bold&lt;/b&gt; text&lt;br/&gt;</literal>
<literal class="html">this is some &lt;b&gt;html&lt;/b&gt; text</literal>
</paragraph>
<paragraph>some text with utf8 characters</paragraph>
<paragraph xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
Expand All @@ -17,4 +17,9 @@
<paragraph xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
<literal class="html">&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;indend using nbsp entities&lt;br/&gt;</literal>
</paragraph>
<paragraph>some text with CNAME end sequence</paragraph>
<paragraph
xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
<literal class="html">Literal with CNAME end sequence here : ]]&gt; and some more text here</literal>
</paragraph>
</section>
@@ -1,4 +0,0 @@
error:Only literal tag with class="html" supported at the moment. Tag with different class removed where contentobject_attribute.id=
error:Only literal tag with class="html" supported at the moment. Tag with different class removed where contentobject_attribute.id=
error:Only literal tag with class="html" supported at the moment. Tag with different class removed where contentobject_attribute.id=
error:Only literal tag with class="html" supported at the moment. Tag with different class removed where contentobject_attribute.id=
@@ -1,5 +1,20 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom" xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0-variant ezpublish-1.0">
<para>next one</para>
<programlisting><![CDATA[Literal with CNAME end sequence here : ]]]]><![CDATA[> and some more text here]]></programlisting>
<programlisting><![CDATA[ordinary literal]]></programlisting>
<programlisting><![CDATA[more
complicated
literal
tag]]></programlisting>
<para>the php one:</para>
<programlisting ezxhtml:class="php"><![CDATA[function foobar()
{
thisIsSomePHPCode('string with special characters & < > â');
return 0;
}]]></programlisting>
<para>the php one with language attribute:</para>
<programlisting language="php" ezxhtml:class="red">function foobar()
{
thisIsSomePHPCode();
return 0;
}</programlisting>
</section>
@@ -1,7 +1,7 @@
<section xmlns="http://docbook.org/ns/docbook" xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom" xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml" xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0-variant ezpublish-1.0">
<para>some text with bold tag</para>
<eztemplate name="rawhtml">
<ezcontent>This is some &lt;b&gt;bold&lt;/b&gt; text&lt;br/&gt;</ezcontent>
<ezcontent>this is some &lt;b&gt;html&lt;/b&gt; text</ezcontent>
</eztemplate>
<para>some text with utf8 characters</para>
<eztemplate name="rawhtml">
Expand All @@ -12,4 +12,8 @@
<eztemplate name="rawhtml">
<ezcontent>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;indend using nbsp entities&lt;br/&gt;</ezcontent>
</eztemplate>
<para>some text with CNAME end sequence</para>
<eztemplate name="rawhtml">
<ezcontent>Literal with CNAME end sequence here : ]]&gt; and some more text here</ezcontent>
</eztemplate>
</section>

0 comments on commit 0c3743f

Please sign in to comment.