Fix bug #19: Tabs ignored in HTML export
authorChristian Weiske <cweiske@cweiske.de>
Thu, 4 Jun 2015 05:49:14 +0000 (07:49 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Thu, 4 Jun 2015 05:49:14 +0000 (07:49 +0200)
lib/converter/cleanhtml.php
lib/converter/html.php

index 6c5dabf..6ee3431 100644 (file)
@@ -34,7 +34,6 @@ class CleanHtml extends Html
         'list-item' => 'li',
         'bold'      => 'b',
         'italic'    => 'i',
-        'monospace' => 'tt',
 
         'size:large' => 'h3',
         'size:huge'  => 'h2',
@@ -47,6 +46,10 @@ class CleanHtml extends Html
         'size:small' => 'small',
     );
 
+    protected static $styleMap = array(
+        'monospace' => 'font-family:monospace; white-space: pre-wrap'
+    );
+
     /**
      * Converts the tomboy note XML into HTML.
      * Cleans HTML a bit up after it has been generated with the clean tags.
index a6a92bc..29064e5 100644 (file)
@@ -37,7 +37,6 @@ class Html extends Base
         'list-item' => 'li',
         'bold'      => 'b',
         'italic'    => 'i',
-        'monospace' => 'tt',
     );
 
     protected static $styleClassMap = array(
@@ -48,6 +47,10 @@ class Html extends Base
         'size:huge'  => 'huge',
     );
 
+    protected static $styleMap = array(
+        'monospace' => 'font-family:monospace; white-space: pre-wrap'
+    );
+
     public $internalLinkHandler;
 
 
@@ -80,17 +83,23 @@ class Html extends Base
         );
 
         $withinLink = false;
+        $nesting = array();
         $store = &$html;
         while ($reader->read()) {
             switch ($reader->nodeType) {
             case XMLReader::ELEMENT:
                 //echo $reader->name . "\n";
+                array_unshift($nesting, $reader->name);
                 if (isset(static::$tagMap[$reader->name])) {
                     $store .= '<' . static::$tagMap[$reader->name] . '>';
                 } else if (isset(static::$styleClassMap[$reader->name])) {
                     $store .= '<span class="'
                         . static::$styleClassMap[$reader->name]
                         . '">';
+                } else if (isset(static::$styleMap[$reader->name])) {
+                    $store .= '<span style="'
+                        . static::$styleMap[$reader->name]
+                        . '">';
                 } else if (substr($reader->name, 0, 5) == 'link:') {
                     $withinLink = true;
                     $linkText    = '';
@@ -98,10 +107,13 @@ class Html extends Base
                 }
                 break;
             case XMLReader::END_ELEMENT:
+                array_shift($nesting, $reader->name);
                 if (isset(static::$tagMap[$reader->name])) {
                     $store .= '</' . static::$tagMap[$reader->name] . '>';
                 } else if (isset(static::$styleClassMap[$reader->name])) {
                     $store .= '</span>';
+                } else if (isset(static::$styleMap[$reader->name])) {
+                    $store .= '</span>';
                 } else if (substr($reader->name, 0, 5) == 'link:') {
                     $withinLink = false;
                     $store      = &$html;
@@ -118,7 +130,11 @@ class Html extends Base
                 break;
             case XMLReader::TEXT:
             case XMLReader::SIGNIFICANT_WHITESPACE:
-                $store .= nl2br(htmlspecialchars($reader->value));
+                $text = htmlspecialchars($reader->value);
+                if ($nesting[0] != 'monospace') {
+                    $text = nl2br($text);
+                }
+                $store .= $text;
                 break;
             default:
                 throw new Exception(