summaryrefslogtreecommitdiff
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
parent964b28e363a4b1f93dd50cb330e2a6440048f4b4 (diff)
Update to pandoc 2
-rw-r--r--Pancake.hs17
-rw-r--r--Text/Pandoc/Readers/Gopher.hs12
-rw-r--r--Text/Pandoc/Readers/Plain.hs9
-rw-r--r--pancake.cabal33
4 files changed, 39 insertions, 32 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
diff --git a/Text/Pandoc/Readers/Gopher.hs b/Text/Pandoc/Readers/Gopher.hs
index de346f5..7ece808 100644
--- a/Text/Pandoc/Readers/Gopher.hs
+++ b/Text/Pandoc/Readers/Gopher.hs
@@ -13,10 +13,11 @@ that, there are some adjustments.
module Text.Pandoc.Readers.Gopher ( readGopher ) where
import Text.Pandoc.Definition
-import Text.Pandoc.Error
import Text.Parsec
-import Text.Parsec.String
+import Text.Parsec.Text
import Text.Pandoc.Readers.Plain
+import Text.Pandoc.Class
+import qualified Data.Text as T
-- | UNASCII ::= ASCII - [Tab CR-LF NUL].
@@ -75,9 +76,10 @@ pDirEntries = concat <$> manyTill (choice [pInfo, pLink] <* pEOL) pLastLine
-- | Reads Gopher directory entries, falls back to plain text on
-- failure.
-readGopher :: String -> Either PandocError Pandoc
-readGopher s = Right . Pandoc mempty . pure . Plain $
+readGopher :: PandocMonad m => T.Text -> m Pandoc
+readGopher s = pure . Pandoc mempty . pure . Plain $
case parse pDirEntries "directory entry" s of
-- fallback to plain text
- Left _ -> concatMap (\l -> (lineToInlines l) ++ [LineBreak]) $ lines s
+ Left _ ->
+ concatMap (\l -> (lineToInlines $ T.unpack l) ++ [LineBreak]) $ T.lines s
Right r -> r
diff --git a/Text/Pandoc/Readers/Plain.hs b/Text/Pandoc/Readers/Plain.hs
index cb8fb9b..0f07feb 100644
--- a/Text/Pandoc/Readers/Plain.hs
+++ b/Text/Pandoc/Readers/Plain.hs
@@ -11,7 +11,8 @@ module Text.Pandoc.Readers.Plain ( readPlain
) where
import Text.Pandoc.Definition
-import Text.Pandoc.Error
+import Text.Pandoc.Class
+import qualified Data.Text as T
-- | Translates a text line into a list of 'Inline' elements suitable
@@ -24,6 +25,6 @@ lineToInlines s = let (cur, next) = break (== ' ') s
-- | Reads plain text, always succeeding and producing a single
-- 'Plain' block.
-readPlain :: String -> Either PandocError Pandoc
-readPlain = Right . Pandoc mempty . pure . Plain .
- concatMap (\l -> (lineToInlines l) ++ [LineBreak]) . lines
+readPlain :: PandocMonad m => T.Text -> m Pandoc
+readPlain = pure . Pandoc mempty . pure . Plain .
+ concatMap (\l -> (lineToInlines $ T.unpack l) ++ [LineBreak]) . T.lines
diff --git a/pancake.cabal b/pancake.cabal
index 329fe14..e00e835 100644
--- a/pancake.cabal
+++ b/pancake.cabal
@@ -27,22 +27,23 @@ executable pancake
main-is: Pancake.hs
other-modules: Text.Pandoc.Readers.Plain
, Text.Pandoc.Readers.Gopher
- build-depends: base >=4.9 && <5,
- bytestring >= 0.10.8.1,
- colorful-monoids >= 0.2.1.0,
- containers >= 0.5.7.1,
- data-default >= 0.7.1.1,
- directory >= 1.2.6.2,
- filepath >= 1.4.1.0,
- mtl >= 2.2.1,
- network-uri >= 2.6.1.0,
- pandoc >= 1.19.2.2,
- pandoc-types >= 1.17.0.5,
- parsec >= 3.1.11,
- process >= 1.6,
- terminfo >= 0.4.0.2,
- utf8-string >= 1.0.1.1,
- yaml >= 0.8.23.3
+ build-depends: base >= 4.9 && < 5
+ , bytestring >= 0.10.8.1 && < 1
+ , colorful-monoids >= 0.2.1.0 && < 1
+ , containers >= 0.5.7.1 && < 1
+ , data-default >= 0.7.1.1 && < 1
+ , directory >= 1.2.6.2 && < 2
+ , filepath >= 1.4.1.0 && < 2
+ , mtl >= 2.2.1 && < 3
+ , network-uri >= 2.6.1.0 && < 3
+ , pandoc >= 2 && < 3
+ , pandoc-types >= 1.17.0.5 && < 2
+ , parsec >= 3.1.11 && < 4
+ , process >= 1.6 && < 2
+ , terminfo >= 0.4.0.2 && < 1
+ , text >= 1.2.2.2 && < 2
+ , utf8-string >= 1.0.1.1 && < 2
+ , yaml >= 0.8.23.3 && < 1
-- hs-source-dirs:
default-language: Haskell2010
ghc-options: -Wall