diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-08-28 19:54:16 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-08-28 19:54:16 +0000 |
commit | 365c349249c9550da51e03407594a27ce5d2143e (patch) | |
tree | cfa269c4886436819a30c66e0ec56871bfa9585a | |
parent | 8fdf8c1d4cf33972a5fef7bf8dcf75478733da8c (diff) | |
download | pandoc-365c349249c9550da51e03407594a27ce5d2143e.tar.gz |
Main: Replaced tabsToSpacesInLine and tabFilter with single function
tabFilter, which operates on the whole string rather than breaking
it into lines.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@943 788f1e2b-df1e-0410-8736-df70ead52e1b
-rw-r--r-- | src/Main.hs | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/Main.hs b/src/Main.hs index 4bd3982d2..16c26fd94 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -445,17 +445,18 @@ main = do Just cols -> read cols Nothing -> stateColumns defaultParserState - let tabsToSpacesInLine _ [] = "" - tabsToSpacesInLine _ ('\r':[]) = "" -- remove DOS line-endings - tabsToSpacesInLine spsToNextStop (x:xs) = - if x == '\t' - then if preserveTabs - then x:(tabsToSpacesInLine tabStop xs) - else replicate spsToNextStop ' ' ++ - tabsToSpacesInLine tabStop xs - else x:(tabsToSpacesInLine (spsToNextStop - 1) xs) - - let tabFilter = unlines . map (tabsToSpacesInLine tabStop) . lines + let tabFilter _ [] = "" + tabFilter _ ('\n':xs) = '\n':(tabFilter tabStop xs) + tabFilter _ ('\r':'\n':xs) = '\n':(tabFilter tabStop xs) + -- remove DOS line endings + tabFilter spsToNextStop ('\t':xs) = + if preserveTabs + then '\t':(tabFilter tabStop xs) + else replicate spsToNextStop ' ' ++ tabFilter tabStop xs + tabFilter 1 (x:xs) = + x:(tabFilter tabStop xs) + tabFilter spsToNextStop (x:xs) = + x:(tabFilter (spsToNextStop - 1) xs) let startParserState = defaultParserState { stateParseRaw = parseRaw, @@ -493,7 +494,7 @@ main = do (readSources sources) >>= (hPutStrLn output . toUTF8 . (writer writerOptions) . - (reader startParserState) . tabFilter . + (reader startParserState) . tabFilter tabStop . fromUTF8 . (joinWithSep "\n")) >> hClose output |