aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2018-10-07 13:42:09 +0200
committerChristian Weiske <cweiske@cweiske.de>2018-10-07 13:42:09 +0200
commit1105322aac9cc8e71eafbf5a5eea8e709c8c77ce (patch)
treebb2026db2adb7e1b7ab7396a047f64bbc17d0210
parent076545376eb1ce47de2135373fb858db5a411e8c (diff)
downloadgrauphel-1105322aac9cc8e71eafbf5a5eea8e709c8c77ce.tar.gz
grauphel-1105322aac9cc8e71eafbf5a5eea8e709c8c77ce.zip
Display tab-based line indentation in HTML
Resolves: https://github.com/cweiske/grauphel/issues/60
-rw-r--r--lib/converter/html.php9
-rw-r--r--templates/html2tomboy.xsl26
-rw-r--r--tests/data/formattest.html11
-rw-r--r--tests/data/formattest.tomboynotecontent11
-rw-r--r--tests/data/full-formattest.html11
5 files changed, 67 insertions, 1 deletions
diff --git a/lib/converter/html.php b/lib/converter/html.php
index 11cf105..c777cad 100644
--- a/lib/converter/html.php
+++ b/lib/converter/html.php
@@ -134,6 +134,15 @@ class Html extends Base
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:
diff --git a/templates/html2tomboy.xsl b/templates/html2tomboy.xsl
index a354000..f3da05e 100644
--- a/templates/html2tomboy.xsl
+++ b/templates/html2tomboy.xsl
@@ -21,7 +21,11 @@
<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 -->
@@ -90,4 +94,24 @@
</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>
diff --git a/tests/data/formattest.html b/tests/data/formattest.html
index a7dbe14..b704c22 100644
--- a/tests/data/formattest.html
+++ b/tests/data/formattest.html
@@ -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 />
+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 />
diff --git a/tests/data/formattest.tomboynotecontent b/tests/data/formattest.tomboynotecontent
index 8f0b017..3e5dedb 100644
--- a/tests/data/formattest.tomboynotecontent
+++ b/tests/data/formattest.tomboynotecontent
@@ -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>
+Tabs:
+a
+ b
+ c
+ d
+e
+
+Tabs in text:
+a b c
+ab cd ef
+
Ende.
diff --git a/tests/data/full-formattest.html b/tests/data/full-formattest.html
index 74d27c0..79ab51f 100644
--- a/tests/data/full-formattest.html
+++ b/tests/data/full-formattest.html
@@ -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 />
+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>