git.iko.soy/typeable/pandoc
on master help sign in
App: change readSource(s) to use Text instead of String.
627e27fJohn MacFarlane
src/Text/Pandoc/App.hs+14−10
@@ -53,7 +53,9 @@ import Data.List (intercalate, isPrefixOf, isSuffixOf, sort)
53import qualified Data.Map as M
53import qualified Data.Map as M
54import Data.Maybe (fromMaybe, isJust, isNothing)
54import Data.Maybe (fromMaybe, isJust, isNothing)
55import qualified Data.Set as Set
55import qualified Data.Set as Set
56+import Data.Text (Text)
56import qualified Data.Text as T
57import qualified Data.Text as T
58+import qualified Data.Text.IO as T
57import Data.Yaml (decode)
59import Data.Yaml (decode)
58import qualified Data.Yaml as Yaml
60import qualified Data.Yaml as Yaml
59import GHC.Generics
61import GHC.Generics
@@ -381,8 +383,8 @@ convertWithOpts opts = do
381 then 0
383 then 0
382 else optTabStop opts)
384 else optTabStop opts)
383
385
384− readSources :: [FilePath] -> PandocIO String
386+ readSources :: [FilePath] -> PandocIO Text
385− readSources srcs = convertTabs . intercalate "\n" <$>
387+ readSources srcs = convertTabs . T.intercalate (T.pack "\n") <$>
386 mapM readSource srcs
388 mapM readSource srcs
387
389
388 let runIO' :: PandocIO a -> IO a
390 let runIO' :: PandocIO a -> IO a
@@ -405,9 +407,9 @@ convertWithOpts opts = do
405 case reader of
407 case reader of
406 StringReader r
408 StringReader r
407 | optFileScope opts || readerName == "json" ->
409 | optFileScope opts || readerName == "json" ->
408− mconcat <$> mapM (readSource >=> r readerOpts) sources
410+ mconcat <$> mapM (readSource >=> r readerOpts . T.unpack) sources
409 | otherwise ->
411 | otherwise ->
410− readSources sources' >>= r readerOpts
412+ readSources sources' >>= r readerOpts . T.unpack
411 ByteStringReader r ->
413 ByteStringReader r ->
412 mconcat <$> mapM (readFile' >=> r readerOpts) sources
414 mconcat <$> mapM (readFile' >=> r readerOpts) sources
413
415
@@ -782,21 +784,23 @@ applyFilters mbDatadir filters args d = do
782 expandedFilters <- mapM (expandFilterPath mbDatadir) filters
784 expandedFilters <- mapM (expandFilterPath mbDatadir) filters
783 foldrM ($) d $ map (flip externalFilter args) expandedFilters
785 foldrM ($) d $ map (flip externalFilter args) expandedFilters
784
786
785−readSource :: FilePath -> PandocIO String
787+readSource :: FilePath -> PandocIO Text
786−readSource "-" = liftIO UTF8.getContents
788+readSource "-" = liftIO T.getContents
787readSource src = case parseURI src of
789readSource src = case parseURI src of
788 Just u | uriScheme u `elem` ["http:","https:"] ->
790 Just u | uriScheme u `elem` ["http:","https:"] ->
789 readURI src
791 readURI src
790 | uriScheme u == "file:" ->
792 | uriScheme u == "file:" ->
793+ liftIO $ UTF8.toText <$>
791− liftIO $ UTF8.readFile (uriPath u)
794+ BS.readFile (uriPath u)
795+ _ -> liftIO $ UTF8.toText <$>
792− _ -> liftIO $ UTF8.readFile src
796+ BS.readFile src
793
797
794−readURI :: FilePath -> PandocIO String
798+readURI :: FilePath -> PandocIO Text
795readURI src = do
799readURI src = do
796 res <- liftIO $ openURL src
800 res <- liftIO $ openURL src
797 case res of
801 case res of
798 Left e -> throwError $ PandocHttpError src e
802 Left e -> throwError $ PandocHttpError src e
799− Right (contents, _) -> return $ UTF8.toString contents
803+ Right (contents, _) -> return $ UTF8.toText contents
800
804
801readFile' :: MonadIO m => FilePath -> m B.ByteString
805readFile' :: MonadIO m => FilePath -> m B.ByteString
802readFile' "-" = liftIO B.getContents
806readFile' "-" = liftIO B.getContents