summaryrefslogtreecommitdiff
path: root/Pancake.hs
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2017-10-31 15:50:18 +0300
committerdefanor <defanor@uberspace.net>2017-10-31 15:50:18 +0300
commit097ac68877acfa6d35ec3987b80ee1ae8da4ff62 (patch)
tree761975e4e2c45a830db726b687b41bc82483108f /Pancake.hs
parent964b28e363a4b1f93dd50cb330e2a6440048f4b4 (diff)
Update to pandoc 2
Diffstat (limited to 'Pancake.hs')
-rw-r--r--Pancake.hs17
1 files changed, 10 insertions, 7 deletions
diff --git a/Pancake.hs b/Pancake.hs
index 0526e6b..e78ab66 100644
--- a/Pancake.hs
+++ b/Pancake.hs
@@ -36,13 +36,14 @@ import qualified Data.Map as M
import System.Directory
import System.Exit
import GHC.IO.Handle
-import qualified Data.ByteString.UTF8 as BSUTF8
import Control.Exception
import Text.Pandoc.Readers.Plain
import Text.Pandoc.Readers.Gopher
import Control.Applicative
import qualified System.IO as SIO
import Data.Char
+import qualified Data.Text as T
+import Data.Text.Encoding (decodeUtf8')
-- | Prints a line into stderr.
@@ -131,20 +132,22 @@ readDoc cmd uri = do
(_, ext) -> byExtension ext
cols = maybe 80 id $ TI.getCapability term TI.termColumns
opts = def { P.readerColumns = cols }
- case reader of
- P.StringReader f -> f opts $ BSUTF8.toString out
- P.ByteStringReader f -> fmap fst <$> f opts (BL.fromStrict out)
+ P.runIO $ case reader of
+ (P.TextReader f, _) -> f opts $ case decodeUtf8' out of
+ Left _ -> T.empty
+ Right r -> r
+ (P.ByteStringReader f, _) -> f opts $ BL.fromStrict out
where
http ext = byExtension ext <|> html
html = P.getReader "html"
- plain = P.StringReader . const $ pure . readPlain
- gopher = pure . P.StringReader . const $ pure . readGopher
+ plain = (P.TextReader . const $ readPlain, P.emptyExtensions)
+ gopher = pure (P.TextReader . const $ readGopher, P.emptyExtensions)
byExtension "" = Left "No extension"
byExtension ".md" = P.getReader "markdown"
byExtension ".htm" = html
byExtension ".ltx" = P.getReader "latex"
byExtension ".tex" = P.getReader "latex"
- byExtension ".txt" = pure . P.StringReader . const $ pure . readPlain
+ byExtension ".txt" = pure plain
byExtension ext = P.getReader $ tail ext