git.iko.soy/typeable/pandoc
on master help sign in
+ Removed tabsToSpaces and tabsInLine from Text.Pandoc.Shared.
8fdf8c1fiddlosopher
src/Main.hs+14−4
@@ -31,7 +31,7 @@ writers.
31module Main where
31module Main where
32import Text.Pandoc
32import Text.Pandoc
33import Text.Pandoc.UTF8
33import Text.Pandoc.UTF8
34−import Text.Pandoc.Shared ( joinWithSep, tabsToSpaces )
34+import Text.Pandoc.Shared ( joinWithSep )
35import Text.Regex ( mkRegex, matchRegex )
35import Text.Regex ( mkRegex, matchRegex )
36import System.Environment ( getArgs, getProgName, getEnvironment )
36import System.Environment ( getArgs, getProgName, getEnvironment )
37import System.Exit ( exitWith, ExitCode (..) )
37import System.Exit ( exitWith, ExitCode (..) )
@@ -445,8 +445,18 @@ main = do
445 Just cols -> read cols
445 Just cols -> read cols
446 Nothing -> stateColumns defaultParserState
446 Nothing -> stateColumns defaultParserState
447
447
448− let tabFilter = if preserveTabs then id else (tabsToSpaces tabStop)
448+ let tabsToSpacesInLine _ [] = ""
449− let removeCRs str = filter (/= '\r') str -- remove DOS-style line endings
449+ tabsToSpacesInLine _ ('\r':[]) = "" -- remove DOS line-endings
450+ tabsToSpacesInLine spsToNextStop (x:xs) =
451+ if x == '\t'
452+ then if preserveTabs
453+ then x:(tabsToSpacesInLine tabStop xs)
454+ else replicate spsToNextStop ' ' ++
455+ tabsToSpacesInLine tabStop xs
456+ else x:(tabsToSpacesInLine (spsToNextStop - 1) xs)
457+
458+ let tabFilter = unlines . map (tabsToSpacesInLine tabStop) . lines
459+
450 let startParserState =
460 let startParserState =
451 defaultParserState { stateParseRaw = parseRaw,
461 defaultParserState { stateParseRaw = parseRaw,
452 stateTabStop = tabStop,
462 stateTabStop = tabStop,
@@ -484,7 +494,7 @@ main = do
484 (readSources sources) >>= (hPutStrLn output . toUTF8 .
494 (readSources sources) >>= (hPutStrLn output . toUTF8 .
485 (writer writerOptions) .
495 (writer writerOptions) .
486 (reader startParserState) . tabFilter .
496 (reader startParserState) . tabFilter .
487− removeCRs . fromUTF8 . (joinWithSep "\n")) >>
497+ fromUTF8 . (joinWithSep "\n")) >>
488 hClose output
498 hClose output
489
499
490 where
500 where
src/Text/Pandoc/Shared.hs−22
@@ -34,7 +34,6 @@ module Text.Pandoc.Shared (
34 substitute,
34 substitute,
35 joinWithSep,
35 joinWithSep,
36 -- * Text processing
36 -- * Text processing
37− tabsToSpaces,
38 backslashEscapes,
37 backslashEscapes,
39 escapeStringUsing,
38 escapeStringUsing,
40 stripTrailingNewlines,
39 stripTrailingNewlines,
@@ -143,27 +142,6 @@ joinWithSep sep lst = foldr1 (\a b -> a ++ sep ++ b) lst
143-- Text processing
142-- Text processing
144--
143--
145
144
146−-- | Convert tabs to spaces (with adjustable tab stop).
147−tabsToSpaces :: Int -- ^ Tabstop
148− -> String -- ^ String to convert
149− -> String
150−tabsToSpaces tabstop str =
151− unlines $ map (tabsInLine tabstop tabstop) (lines str)
152−
153−-- | Convert tabs to spaces in one line.
154−tabsInLine :: Int -- ^ Number of spaces to next tab stop
155− -> Int -- ^ Tabstop
156− -> String -- ^ Line to convert
157− -> String
158−tabsInLine num tabstop [] = ""
159−tabsInLine num tabstop (c:cs) =
160− let (replacement, nextnum) = if c == '\t'
161− then (replicate num ' ', tabstop)
162− else if num > 1
163− then ([c], num - 1)
164− else ([c], tabstop)
165− in replacement ++ tabsInLine nextnum tabstop cs
166−
167-- | Returns an association list of backslash escapes for the
145-- | Returns an association list of backslash escapes for the
168-- designated characters.
146-- designated characters.
169backslashEscapes :: [Char] -- ^ list of special characters to escape
147backslashEscapes :: [Char] -- ^ list of special characters to escape