git.iko.soy/typeable/pandoc
on master help sign in
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

commitede0d805a03f1f9a6c5c4790980a7de56eea8945 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSat 31 Jan 2009, 17:13 (18 years ago) parent5a9e3b7
2 files changed+26−22
src/Text/Pandoc/Shared.hs+21 src/pandoc.hs+5−22
src/Text/Pandoc/Shared.hs+21
@@ -49,6 +49,7 @@ module Text.Pandoc.Shared (
4949 wrapTeXIfNeeded,
5050 BlockWrapper (..),
5151 wrappedBlocksToDoc,
52+ tabFilter,
5253 -- * Parsing
5354 (>>~),
5455 anyLine,
@@ -285,6 +286,26 @@ wrappedBlocksToDoc = foldr addBlock empty
285286 addBlock (Pad d) accum = d $$ text "" $$ accum
286287 addBlock (Reg d) accum = d $$ accum
287288
289+-- | Convert tabs to spaces and filter out DOS line endings.
290+-- Tabs will be preserved if tab stop is set to 0.
291+tabFilter :: Int -- ^ Tab stop
292+ -> String -- ^ Input
293+ -> String
294+tabFilter tabStop =
295+ let go _ [] = ""
296+ go _ ('\n':xs) = '\n' : go tabStop xs
297+ go _ ('\r':'\n':xs) = '\n' : go tabStop xs
298+ go _ ('\r':xs) = '\n' : go tabStop xs
299+ go spsToNextStop ('\t':xs) =
300+ if tabStop == 0
301+ then '\t' : go tabStop xs
302+ else replicate spsToNextStop ' ' ++ go tabStop xs
303+ go 1 (x:xs) =
304+ x : go tabStop xs
305+ go spsToNextStop (x:xs) =
306+ x : go (spsToNextStop - 1) xs
307+ in go tabStop
308+
288309--
289310-- Parsing
290311--
src/pandoc.hs+5−22
@@ -32,7 +32,7 @@ writers.
3232module Main where
3333import Text.Pandoc
3434import Text.Pandoc.ODT
35−import Text.Pandoc.Shared ( HTMLMathMethod (..), splitBy, ObfuscationMethod (..) )
35+import Text.Pandoc.Shared ( HTMLMathMethod (..), splitBy, tabFilter, ObfuscationMethod (..) )
3636import Text.Pandoc.Highlighting ( languages )
3737import System.Environment ( getArgs, getProgName, getEnvironment )
3838import System.Exit ( exitWith, ExitCode (..) )
@@ -131,8 +131,7 @@ writeDoc _ = prettyPandoc
131131
132132-- | Data structure for command line options.
133133data Opt = Opt
134− { optPreserveTabs :: Bool -- ^ Convert tabs to spaces
135− , optTabStop :: Int -- ^ Number of spaces per tab
134+ { optTabStop :: Int -- ^ Number of spaces per tab
136135 , optStandalone :: Bool -- ^ Include header, footer
137136 , optReader :: String -- ^ Reader format
138137 , optWriter :: String -- ^ Writer format
@@ -167,8 +166,7 @@ data Opt = Opt
167166-- | Defaults for command-line options.
168167defaultOpts :: Opt
169168defaultOpts = Opt
170− { optPreserveTabs = False
171− , optTabStop = 4
169+ { optTabStop = 4
172170 , optStandalone = False
173171 , optReader = "" -- null for default reader
174172 , optWriter = "" -- null for default writer
@@ -229,7 +227,7 @@ options =
229227
230228 , Option "p" ["preserve-tabs"]
231229 (NoArg
232− (\opt -> return opt { optPreserveTabs = True }))
230+ (\opt -> return opt { optTabStop = 0 }))
233231 "" -- "Preserve tabs instead of converting to spaces"
234232
235233 , Option "" ["tab-stop"]
@@ -519,8 +517,7 @@ main = do
519517 -- thread option data structure through all supplied option actions
520518 opts <- foldl (>>=) (return defaultOpts') actions
521519
522− let Opt { optPreserveTabs = preserveTabs
523− , optTabStop = tabStop
520+ let Opt { optTabStop = tabStop
524521 , optStandalone = standalone
525522 , optReader = readerName
526523 , optWriter = writerName
@@ -581,20 +578,6 @@ main = do
581578 Just cols -> read cols
582579 Nothing -> stateColumns defaultParserState
583580
584− let tabFilter _ [] = ""
585− tabFilter _ ('\n':xs) = '\n' : tabFilter tabStop xs
586− -- remove DOS line endings
587− tabFilter _ ('\r':'\n':xs) = '\n' : tabFilter tabStop xs
588− tabFilter _ ('\r':xs) = '\n' : tabFilter tabStop xs
589− tabFilter spsToNextStop ('\t':xs) =
590− if preserveTabs
591− then '\t' : tabFilter tabStop xs
592− else replicate spsToNextStop ' ' ++ tabFilter tabStop xs
593− tabFilter 1 (x:xs) =
594− x : tabFilter tabStop xs
595− tabFilter spsToNextStop (x:xs) =
596− x : tabFilter (spsToNextStop - 1) xs
597−
598581 let standalone' = (standalone && not strict) || isNonTextOutput writerName'
599582
600583#ifdef _CITEPROC