diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2018-10-07 13:42:09 +0200 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2018-10-07 13:42:09 +0200 |
| commit | 1105322aac9cc8e71eafbf5a5eea8e709c8c77ce (patch) | |
| tree | bb2026db2adb7e1b7ab7396a047f64bbc17d0210 | |
| parent | 076545376eb1ce47de2135373fb858db5a411e8c (diff) | |
| download | grauphel-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.php | 9 | ||||
| -rw-r--r-- | templates/html2tomboy.xsl | 26 | ||||
| -rw-r--r-- | tests/data/formattest.html | 11 | ||||
| -rw-r--r-- | tests/data/formattest.tomboynotecontent | 11 | ||||
| -rw-r--r-- | tests/data/full-formattest.html | 11 |
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( + ' ', 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="'        '" /> + <xsl:with-param name="by" select="'	'" /> + </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 /> +        b<br /> +                c<br /> +        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 /> +        b<br /> +                c<br /> +        d<br /> +e<br /> +<br /> +Tabs in text:<br /> +a b c<br /> +ab cd ef<br /> +<br /> Ende.<br /></body> </html> |
