forked from ezsystems/ezpublish-kernel
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
231 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
eZ/Publish/Core/FieldType/RichText/Converter/ProgramListing.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/** | ||
* File containing the ProgramListing class. | ||
* | ||
* @copyright Copyright (C) eZ Systems AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
namespace eZ\Publish\Core\FieldType\RichText\Converter; | ||
|
||
use eZ\Publish\Core\FieldType\RichText\Converter; | ||
use DOMDocument; | ||
use DOMXPath; | ||
|
||
/** | ||
* Class ProgramListing. | ||
* | ||
* Processes <code>programlisting</code> DocBook tag. | ||
*/ | ||
class ProgramListing implements Converter | ||
{ | ||
/** | ||
* 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 | ||
* @return DOMDocument | ||
*/ | ||
public function convert(DOMDocument $document) | ||
{ | ||
$xpath = new DOMXPath($document); | ||
$xpathExpression = '//ns:pre'; | ||
$ns = $document->documentElement->namespaceURI; | ||
$xpath->registerNamespace('ns', $ns); | ||
$elements = $xpath->query($xpathExpression); | ||
|
||
foreach ($elements as $element) { | ||
$element->textContent = str_replace(']]>', ']]]]><![CDATA[>', $element->textContent); | ||
} | ||
|
||
return $document; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...ish/Core/FieldType/Tests/RichText/Converter/Xslt/_fixtures/docbook/033-programlisting.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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"> | ||
<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="red"><![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> |
21 changes: 21 additions & 0 deletions
21
...Core/FieldType/Tests/RichText/Converter/Xslt/_fixtures/xhtml5/edit/033-programlisting.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<section xmlns="http://ez.no/namespaces/ezpublish5/xhtml5/edit"> | ||
<pre>Literal with CNAME end sequence here : ]]> and some more text here</pre> | ||
<pre>ordinary literal</pre> | ||
<pre>more | ||
complicated | ||
literal | ||
tag</pre> | ||
<p>the php one:</p> | ||
<pre class="red">function foobar() | ||
{ | ||
thisIsSomePHPCode('string with special characters & < > â'); | ||
return 0; | ||
}</pre> | ||
<p>the php one with language attribute:</p> | ||
<pre class="red" data-language="php">function foobar() | ||
{ | ||
thisIsSomePHPCode(); | ||
return 0; | ||
}</pre> | ||
</section> |
21 changes: 21 additions & 0 deletions
21
...re/FieldType/Tests/RichText/Converter/Xslt/_fixtures/xhtml5/output/033-programlisting.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<section xmlns="http://ez.no/namespaces/ezpublish5/xhtml5"> | ||
<pre>Literal with CNAME end sequence here : ]]> and some more text here</pre> | ||
<pre>ordinary literal</pre> | ||
<pre>more | ||
complicated | ||
literal | ||
tag</pre> | ||
<p>the php one:</p> | ||
<pre class="red">function foobar() | ||
{ | ||
thisIsSomePHPCode('string with special characters & < > â'); | ||
return 0; | ||
}</pre> | ||
<p>the php one with language attribute:</p> | ||
<pre class="red" data-language="php">function foobar() | ||
{ | ||
thisIsSomePHPCode(); | ||
return 0; | ||
}</pre> | ||
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters