@@ -45,14 +45,14 @@ module Text.Pandoc.Shared (
45 toRomanNumeral,
45 toRomanNumeral,
46 escapeURI,
46 escapeURI,
47 unescapeURI,
47 unescapeURI,
49 wrapIfNeeded,
51 wrapIfNeeded,
50 wrappedTeX,
52 wrappedTeX,
51 wrapTeXIfNeeded,
53 wrapTeXIfNeeded,
52 BlockWrapper (..),
54 BlockWrapper (..),
53 wrappedBlocksToDoc,
55 wrappedBlocksToDoc,
57 -- * Pandoc block and inline list processing
57 -- * Pandoc block and inline list processing
58 orderedListMarkers,
58 orderedListMarkers,
@@ -195,6 +195,30 @@ unescapeURI :: String -> String
195unescapeURI = escapeURIString (\c -> isAllowedInURI c || not (isAscii c)) .
195unescapeURI = escapeURIString (\c -> isAllowedInURI c || not (isAscii c)) .
196 decodeString . unEscapeString
196 decodeString . unEscapeString
198+-- | Convert tabs to spaces and filter out DOS line endings.
199+-- Tabs will be preserved if tab stop is set to 0.
200+tabFilter :: Int -- ^ Tab stop
201+ -> String -- ^ Input
205+ go _ ('\n':xs) = '\n' : go tabStop xs
206+ go _ ('\r':'\n':xs) = '\n' : go tabStop xs
207+ go _ ('\r':xs) = '\n' : go tabStop xs
208+ go spsToNextStop ('\t':xs) =
210+ then '\t' : go tabStop xs
211+ else replicate spsToNextStop ' ' ++ go tabStop xs
214+ go spsToNextStop (x:xs) =
215+ x : go (spsToNextStop - 1) xs
198-- | Wrap inlines to line length.
222-- | Wrap inlines to line length.
199wrapped :: Monad m => ([Inline] -> m Doc) -> [Inline] -> m Doc
223wrapped :: Monad m => ([Inline] -> m Doc) -> [Inline] -> m Doc
200wrapped listWriter sect = (mapM listWriter $ splitBy Space sect) >>=
224wrapped listWriter sect = (mapM listWriter $ splitBy Space sect) >>=
@@ -264,30 +288,6 @@ wrappedBlocksToDoc = foldr addBlock empty
264 addBlock (Pad d) accum = d $$ text "" $$ accum
288 addBlock (Pad d) accum = d $$ text "" $$ accum
265 addBlock (Reg d) accum = d $$ accum
289 addBlock (Reg d) accum = d $$ accum
267−-- | Convert tabs to spaces and filter out DOS line endings.
268−-- Tabs will be preserved if tab stop is set to 0.
269−tabFilter :: Int -- ^ Tab stop
270− -> String -- ^ Input
274− go _ ('\n':xs) = '\n' : go tabStop xs
275− go _ ('\r':'\n':xs) = '\n' : go tabStop xs
276− go _ ('\r':xs) = '\n' : go tabStop xs
277− go spsToNextStop ('\t':xs) =
279− then '\t' : go tabStop xs
280− else replicate spsToNextStop ' ' ++ go tabStop xs
283− go spsToNextStop (x:xs) =
284− x : go (spsToNextStop - 1) xs
291-- | A version of hang that works like the version in pretty-1.0.0.0
291-- | A version of hang that works like the version in pretty-1.0.0.0
292hang' :: Doc -> Int -> Doc -> Doc
292hang' :: Doc -> Int -> Doc -> Doc
293hang' d1 n d2 = d1 $$ (nest n d2)
293hang' d1 n d2 = d1 $$ (nest n d2)