Display tab-based line indentation in HTML
authorChristian Weiske <cweiske@cweiske.de>
Sun, 7 Oct 2018 11:42:09 +0000 (13:42 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Sun, 7 Oct 2018 11:42:09 +0000 (13:42 +0200)
Resolves: https://github.com/cweiske/grauphel/issues/60

lib/converter/html.php
templates/html2tomboy.xsl
tests/data/formattest.html
tests/data/formattest.tomboynotecontent
tests/data/full-formattest.html

index 11cf105ceb2a01c1928ff9e9f4137c0bc309688d..c777cadd921425e243a0d15fffdbd695ae2e1195 100644 (file)
@@ -134,6 +134,15 @@ class Html extends Base
                 if ($nesting[0] != 'monospace') {
                     $text = nl2br($text);
                 }
                 if ($nesting[0] != 'monospace') {
                     $text = nl2br($text);
                 }
+                $text = preg_replace_callback(
+                    "#^\t+#m",
+                    function ($matches) {
+                        return str_repeat(
+                            '&#160;', strlen($matches[0]) * 8
+                        );
+                    },
+                    $text
+                );
                 $store .= $text;
                 break;
             default:
                 $store .= $text;
                 break;
             default:
index a35400092c37fb854bbebfb110d0b90a6381f21c..f3da05e5a2865cb34ee9ddd1e47bd412d72d561a 100644 (file)
   <xsl:for-each select="child::node()">
    <xsl:choose>
     <xsl:when test="local-name(.) = ''">
   <xsl:for-each select="child::node()">
    <xsl:choose>
     <xsl:when test="local-name(.) = ''">
-     <xsl:value-of select="."/>
+     <xsl:call-template name="string-replace-all">
+      <xsl:with-param name="text" select="string(.)" />
+      <xsl:with-param name="replace" select="'&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;'" />
+      <xsl:with-param name="by" select="'&#09;'" />
+     </xsl:call-template>
     </xsl:when>
     <xsl:when test="local-name(.) = 'br'">
      <!-- do nothing -->
     </xsl:when>
     <xsl:when test="local-name(.) = 'br'">
      <!-- do nothing -->
   </xsl:for-each>
  </xsl:template>
 
   </xsl:for-each>
  </xsl:template>
 
+ <!-- http://geekswithblogs.net/Erik/archive/2008/04/01/120915.aspx -->
+ <xsl:template name="string-replace-all">
+  <xsl:param name="text" />
+  <xsl:param name="replace" />
+  <xsl:param name="by" />
+  <xsl:choose>
+   <xsl:when test="contains($text, $replace)">
+    <xsl:value-of select="substring-before($text,$replace)" />
+    <xsl:value-of select="$by" />
+    <xsl:call-template name="string-replace-all">
+     <xsl:with-param name="text" select="substring-after($text,$replace)" />
+     <xsl:with-param name="replace" select="$replace" />
+     <xsl:with-param name="by" select="$by" />
+    </xsl:call-template>
+   </xsl:when>
+   <xsl:otherwise>
+    <xsl:value-of select="$text" />
+   </xsl:otherwise>
+  </xsl:choose>
+ </xsl:template>
 </xsl:stylesheet>
 </xsl:stylesheet>
index a7dbe14dcb75101e2dbdc8bffd21e01c1f196559..b704c2226f3141e2bce8d13a64b4b642e09ffd51 100644 (file)
@@ -33,4 +33,15 @@ Links:<br />
 </li><li><a href="http://cweiske.de/?foo#bar">http://cweiske.de/?foo#bar</a><br />
 </li><li><a href="file:///home/cweiske/fam.jpg">/home/cweiske/fam.jpg</a></li></ul>
 <br />
 </li><li><a href="http://cweiske.de/?foo#bar">http://cweiske.de/?foo#bar</a><br />
 </li><li><a href="file:///home/cweiske/fam.jpg">/home/cweiske/fam.jpg</a></li></ul>
 <br />
+Tabs:<br />
+a<br />
+&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;b<br />
+&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;c<br />
+&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;d<br />
+e<br />
+<br />
+Tabs in text:<br />
+a      b       c<br />
+ab     cd      ef<br />
+<br />
 Ende.<br />
 Ende.<br />
index 8f0b017fc47b86d3712a731f3a2f8430c064e331..3e5dedb2ebaf51f64923c9840229e5ae3967b6a3 100644 (file)
@@ -33,4 +33,15 @@ Links:
 </list-item><list-item dir="ltr"><link:url>http://cweiske.de/?foo#bar</link:url>
 </list-item><list-item dir="ltr"><link:url>/home/cweiske/fam.jpg</link:url></list-item></list>
 
 </list-item><list-item dir="ltr"><link:url>http://cweiske.de/?foo#bar</link:url>
 </list-item><list-item dir="ltr"><link:url>/home/cweiske/fam.jpg</link:url></list-item></list>
 
+Tabs:
+a
+       b
+               c
+       d
+e
+
+Tabs in text:
+a      b       c
+ab     cd      ef
+
 Ende.
 Ende.
index 74d27c0fdcf946feb54f041ba84c0729ebdf304e..79ab51f34ceb1beba191c49f0c75e89b4cca42aa 100644 (file)
@@ -37,5 +37,16 @@ Links:<br />
 </li><li><a href="http://cweiske.de/?foo#bar">http://cweiske.de/?foo#bar</a><br />
 </li><li><a href="file:///home/cweiske/fam.jpg">/home/cweiske/fam.jpg</a></li></ul>
 <br />
 </li><li><a href="http://cweiske.de/?foo#bar">http://cweiske.de/?foo#bar</a><br />
 </li><li><a href="file:///home/cweiske/fam.jpg">/home/cweiske/fam.jpg</a></li></ul>
 <br />
+Tabs:<br />
+a<br />
+&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;b<br />
+&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;c<br />
+&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;d<br />
+e<br />
+<br />
+Tabs in text:<br />
+a      b       c<br />
+ab     cd      ef<br />
+<br />
 Ende.<br /></body>
 </html>
 Ende.<br /></body>
 </html>