From ede0d805a03f1f9a6c5c4790980a7de56eea8945 Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Sat, 31 Jan 2009 17:13:41 +0000 Subject: Moved tabFilter to Shared. Removed optPreserveTabs; instead, tabstop of 0 means preserve tabs. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1532 788f1e2b-df1e-0410-8736-df70ead52e1b --- src/Text/Pandoc/Shared.hs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 6854e5ae6..13eab9bdb 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -49,6 +49,7 @@ module Text.Pandoc.Shared ( wrapTeXIfNeeded, BlockWrapper (..), wrappedBlocksToDoc, + tabFilter, -- * Parsing (>>~), anyLine, @@ -285,6 +286,26 @@ wrappedBlocksToDoc = foldr addBlock empty addBlock (Pad d) accum = d $$ text "" $$ accum addBlock (Reg d) accum = d $$ accum +-- | Convert tabs to spaces and filter out DOS line endings. +-- Tabs will be preserved if tab stop is set to 0. +tabFilter :: Int -- ^ Tab stop + -> String -- ^ Input + -> String +tabFilter tabStop = + let go _ [] = "" + go _ ('\n':xs) = '\n' : go tabStop xs + go _ ('\r':'\n':xs) = '\n' : go tabStop xs + go _ ('\r':xs) = '\n' : go tabStop xs + go spsToNextStop ('\t':xs) = + if tabStop == 0 + then '\t' : go tabStop xs + else replicate spsToNextStop ' ' ++ go tabStop xs + go 1 (x:xs) = + x : go tabStop xs + go spsToNextStop (x:xs) = + x : go (spsToNextStop - 1) xs + in go tabStop + -- -- Parsing -- -- cgit v1.2.3