Skip to content

Commit

Permalink
EZP-29484: ezxmltext -> richtext conversion : Paragraphs containing t…
Browse files Browse the repository at this point in the history
…ext and block elements could mistakenly by considered temporary (#62)

* EZP-29484: ezxmltext -> richtext conversion : Paragraphs containing text and block elements could mistakenly by considered temporary
  • Loading branch information
vidarl committed Aug 13, 2018
1 parent 1dff9d7 commit 3da761a
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/FieldType/XmlText/Converter/ExpandingToRichText.php
Expand Up @@ -45,6 +45,7 @@ protected function isTemporary(DOMElement $paragraph)
{
return
$paragraph->hasAttribute('xmlns:tmp')
&& !$this->containsText($paragraph)
&& (
$this->containsBlock($paragraph)
|| $this->containsCustomTag($paragraph)
Expand All @@ -66,4 +67,32 @@ protected function containsCustomTag(DOMElement $paragraph)

return false;
}

protected function containsText(DOMElement $paragraph)
{
foreach ($paragraph->childNodes as $child) {
if ($child instanceof \DOMText) {
return true;
} elseif ($child instanceof \DOMElement) {
switch ($child->localName) {
case 'strong':
case 'emphasize':
case 'underline':
case 'link':
return true;
case 'custom':
switch ($child->getAttribute('name')) {
case 'underline':
case 'strike':
case 'sub':
case 'sup':
return true;
}
break;
}
}
}

return false;
}
}
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<section
xmlns:image="http://ez.no/namespaces/ezpublish3/image/"
xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"
xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/">
<section>
<paragraph
xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
<embed align="left" view="embed" size="small" object_id="123"/>sometext</paragraph>
<paragraph
xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
<embed align="left" view="embed" size="small" object_id="123"/><strong>strong text</strong>
</paragraph>
<paragraph
xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
<embed align="left" view="embed" size="small" object_id="123"/><emphasize>emphasized text</emphasize>
</paragraph>
<paragraph
xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
<embed align="left" view="embed" size="small" object_id="123"/><underline>underlined text</underline>
</paragraph>
<paragraph
xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
<embed align="left" view="embed" size="small" object_id="123"/><link anchor_name="anchor1">link text</link>
</paragraph>
<paragraph
xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
<embed align="left" view="embed" size="small" object_id="123"/><custom name="underline">underlinded text</custom>
</paragraph>
<paragraph
xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
<embed align="left" view="embed" size="small" object_id="123"/><custom name="strike">striked</custom>
</paragraph>
<paragraph
xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
<embed align="left" view="embed" size="small" object_id="123"/><custom name="sub">subscript text</custom>
</paragraph>
<paragraph
xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
<embed align="left" view="embed" size="small" object_id="123"/><custom name="sup">superscript text</custom>
</paragraph>
</section>
</section>
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<section
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>foobar.</paragraph>
<section>
<header>my header</header>
<paragraph
xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
<ul>
<li>
<paragraph
xmlns:tmp="http://ez.no/namespaces/ezpublish3/temporary/">
<embed align="right" view="embed" object_id="123"/>foobartest</paragraph>
</li>
</ul>
</paragraph>
</section>
</section>
@@ -0,0 +1,72 @@
<?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">
<ezembed xlink:href="ezcontent://123" view="embed" ezxhtml:align="left">
<ezconfig>
<ezvalue key="size">small</ezvalue>
</ezconfig>
</ezembed>
<para>sometext</para>
<ezembed xlink:href="ezcontent://123" view="embed" ezxhtml:align="left">
<ezconfig>
<ezvalue key="size">small</ezvalue>
</ezconfig>
</ezembed>
<para>
<emphasis role="strong">strong text</emphasis>
</para>
<ezembed xlink:href="ezcontent://123" view="embed" ezxhtml:align="left">
<ezconfig>
<ezvalue key="size">small</ezvalue>
</ezconfig>
</ezembed>
<para>
<emphasis>emphasized text</emphasis>
</para>
<ezembed xlink:href="ezcontent://123" view="embed" ezxhtml:align="left">
<ezconfig>
<ezvalue key="size">small</ezvalue>
</ezconfig>
</ezembed>
<para>underlined text</para>
<ezembed xlink:href="ezcontent://123" view="embed" ezxhtml:align="left">
<ezconfig>
<ezvalue key="size">small</ezvalue>
</ezconfig>
</ezembed>
<para>
<link xlink:href="#anchor1" xlink:show="none">link text</link>
</para>
<ezembed xlink:href="ezcontent://123" view="embed" ezxhtml:align="left">
<ezconfig>
<ezvalue key="size">small</ezvalue>
</ezconfig>
</ezembed>
<para>
<emphasis role="underlined">underlinded text</emphasis>
</para>
<ezembed xlink:href="ezcontent://123" view="embed" ezxhtml:align="left">
<ezconfig>
<ezvalue key="size">small</ezvalue>
</ezconfig>
</ezembed>
<para>
<emphasis role="strikedthrough">striked</emphasis>
</para>
<ezembed xlink:href="ezcontent://123" view="embed" ezxhtml:align="left">
<ezconfig>
<ezvalue key="size">small</ezvalue>
</ezconfig>
</ezembed>
<para>
<subscript>subscript text</subscript>
</para>
<ezembed xlink:href="ezcontent://123" view="embed" ezxhtml:align="left">
<ezconfig>
<ezvalue key="size">small</ezvalue>
</ezconfig>
</ezembed>
<para>
<superscript>superscript text</superscript>
</para>
</section>

@@ -0,0 +1,15 @@
<?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>foobar.</para>
<title ezxhtml:level="2">my header</title>
<ezembed view="embed" ezxhtml:align="right" xlink:href="ezcontent://123"/>
<itemizedlist>
<listitem>
<para>foobartest</para>
</listitem>
</itemizedlist>
</section>

0 comments on commit 3da761a

Please sign in to comment.