Handle not existing creation date on note object
[grauphel.git] / lib / converter / cleanhtml.php
1 <?php
2 /**
3  * Part of grauphel
4  *
5  * PHP version 5
6  *
7  * @category  Tools
8  * @package   Grauphel
9  * @author    Christian Weiske <cweiske@cweiske.de>
10  * @copyright 2014 Christian Weiske
11  * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
12  * @link      http://cweiske.de/grauphel.htm
13  */
14 namespace OCA\Grauphel\Converter;
15 use \XMLReader;
16
17 /**
18  * Convert Tomboy note XML to HTML that can be used (nearly) standalone.
19  * This means it tries to use as many native tags as possible and
20  * does not rely on classes so much.
21  *
22  * @category  Tools
23  * @package   Grauphel
24  * @author    Christian Weiske <cweiske@cweiske.de>
25  * @copyright 2014 Christian Weiske
26  * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
27  * @version   Release: @package_version@
28  * @link      http://cweiske.de/grauphel.htm
29  */
30 class CleanHtml extends Html
31 {
32     protected static $tagMap = array(
33         'list'      => 'ul',
34         'list-item' => 'li',
35         'bold'      => 'b',
36         'italic'    => 'i',
37
38         'size:large' => 'h3',
39         'size:huge'  => 'h2',
40
41         'strikethrough' => 'del',
42         'highlight'     => 'ins',
43     );
44
45     protected static $styleClassMap = array(
46         'size:small' => 'small',
47     );
48
49     protected static $styleMap = array(
50         'monospace' => 'font-family:monospace; white-space: pre-wrap'
51     );
52
53     /**
54      * Converts the tomboy note XML into HTML.
55      * Cleans HTML a bit up after it has been generated with the clean tags.
56      *
57      * @param string $xmlContent Tomboy note content
58      *
59      * @return string HTML
60      */
61     public function convert($xmlContent)
62     {
63         $html = parent::convert($xmlContent);
64         $html = str_replace('</h2><br />', '</h2>', $html);
65         $html = str_replace('</h3><br />', '</h3>', $html);
66         $html = str_replace("<br />\n</h2>", "</h2>\n", $html);
67         $html = str_replace("<br />\n</h3>", "</h3>\n", $html);
68         $html = str_replace("<br />\n</li>", "</li>\n", $html);
69         $html = str_replace("<br />\n<ul>", "<ul>\n", $html);
70         return $html;
71     }
72 }
73 ?>