git.iko.soy/typeable/pandoc
on master help sign in
Changed readNative to use PandocMonad.
commit18e85f8dfbf9323945969cdf831c9a16f90299a0 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 27 Nov 2016, 16:38 (10 years ago) parentbf8fb78
6 files changed+22−11
src/Text/Pandoc.hs+2−2 src/Text/Pandoc/Readers/Native.hs+6−3 tests/Tests/Old.hs+3−1 tests/Tests/Readers/Docx.hs+3−1 tests/Tests/Readers/Odt.hs+3−1 tests/Tests/Writers/Docx.hs+5−3
src/Text/Pandoc.hs+2−2
@@ -183,7 +183,7 @@ import Text.Pandoc.Options
183183import Text.Pandoc.Shared (safeRead, warn, mapLeft, pandocVersion)
184184import Text.Pandoc.MediaBag (MediaBag)
185185import Text.Pandoc.Error
186−import Text.Pandoc.Class (PandocMonad)
186+import Text.Pandoc.Class (PandocMonad, runIOorExplode)
187187import Data.Aeson
188188import qualified Data.ByteString.Lazy as BL
189189import Data.List (intercalate)
@@ -243,7 +243,7 @@ mkBSReaderWithWarnings r = ByteStringReader $ \o s ->
243243
244244-- | Association list of formats and readers.
245245readers :: [(String, Reader IO)]
246−readers = [ ("native" , StringReader $ \_ s -> return $ readNative s)
246+readers = [ ("native" , StringReader $ \_ s -> runIOorExplode (readNative s))
247247 ,("json" , mkStringReader readJSON )
248248 ,("markdown" , mkStringReaderWithWarnings readMarkdownWithWarnings)
249249 ,("markdown_strict" , mkStringReaderWithWarnings readMarkdownWithWarnings)
src/Text/Pandoc/Readers/Native.hs+6−3
@@ -34,6 +34,7 @@ import Text.Pandoc.Definition
3434import Text.Pandoc.Shared (safeRead)
3535
3636import Text.Pandoc.Error
37+import Text.Pandoc.Class
3738
3839-- | Read native formatted text and return a Pandoc document.
3940-- The input may be a full pandoc document, a block list, a block,
@@ -45,9 +46,11 @@ import Text.Pandoc.Error
4546--
4647-- > Pandoc nullMeta [Plain [Str "hi"]]
4748--
48−readNative :: String -- ^ String to parse (assuming @'\n'@ line endings)
49− -> Either PandocError Pandoc
50−readNative s = maybe (Pandoc nullMeta <$> readBlocks s) Right (safeRead s)
49+readNative :: PandocMonad m
50+ => String -- ^ String to parse (assuming @'\n'@ line endings)
51+ -> m (Either PandocError Pandoc)
52+readNative s =
53+ return $ maybe (Pandoc nullMeta <$> readBlocks s) Right (safeRead s)
5154
5255readBlocks :: String -> Either PandocError [Block]
5356readBlocks s = maybe ((:[]) <$> readBlock s) Right (safeRead s)
tests/Tests/Old.hs+3−1
@@ -196,7 +196,9 @@ lhsReaderTest :: String -> Test
196196lhsReaderTest format =
197197 testWithNormalize normalizer "lhs" ["-r", format, "-w", "native"]
198198 ("lhs-test" <.> format) norm
199− where normalizer = purely $ writeNative def . normalize . handleError . readNative
199+ where normalizer = purely $ \nat -> do
200+ d <- handleError <$> readNative nat
201+ writeNative def $ normalize d
200202 norm = if format == "markdown+lhs"
201203 then "lhs-test-markdown.native"
202204 else "lhs-test.native"
tests/Tests/Readers/Docx.hs+3−1
@@ -14,6 +14,7 @@ import qualified Data.Map as M
1414import Text.Pandoc.MediaBag (MediaBag, lookupMedia, mediaDirectory)
1515import Codec.Archive.Zip
1616import Text.Pandoc.Error
17+import Text.Pandoc.Class (runIOorExplode)
1718
1819-- We define a wrapper around pandoc that doesn't normalize in the
1920-- tests. Since we do our own normalization, we want to make sure
@@ -43,7 +44,8 @@ compareOutput opts docxFile nativeFile = do
4344 df <- B.readFile docxFile
4445 nf <- Prelude.readFile nativeFile
4546 let (p, _) = handleError $ readDocx opts df
46− return $ (noNorm p, noNorm (handleError $ readNative nf))
47+ df' <- runIOorExplode $ readNative nf
48+ return $ (noNorm p, noNorm $ handleError df')
4749
4850testCompareWithOptsIO :: ReaderOptions -> String -> FilePath -> FilePath -> IO Test
4951testCompareWithOptsIO opts name docxFile nativeFile = do
tests/Tests/Readers/Odt.hs+3−1
@@ -5,6 +5,7 @@ import Text.Pandoc.Options
55import Text.Pandoc.Readers.Native
66import Text.Pandoc.Readers.Markdown
77import Text.Pandoc.Definition
8+import Text.Pandoc.Class (runIOorExplode)
89import Tests.Helpers
910import Test.Framework
1011import qualified Data.ByteString.Lazy as B
@@ -62,7 +63,8 @@ compareOdtToNative :: TestCreator
6263compareOdtToNative opts odtPath nativePath = do
6364 nativeFile <- Prelude.readFile nativePath
6465 odtFile <- B.readFile odtPath
65− let native = getNoNormVia id "native" $ readNative nativeFile
66+ native <- getNoNormVia id "native" <$>
67+ runIOorExplode (readNative nativeFile)
6668 let odt = getNoNormVia fst "odt" $ readOdt opts odtFile
6769 return (odt,native)
6870
tests/Tests/Writers/Docx.hs+5−3
@@ -21,10 +21,12 @@ compareOutput opts nativeFileIn nativeFileOut = do
2121 nf <- Prelude.readFile nativeFileIn
2222 nf' <- Prelude.readFile nativeFileOut
2323 let wopts = fst opts
24− df <- runIOorExplode $ writeDocx wopts{writerUserDataDir = Just (".." </> "data")}
25− (handleError $ readNative nf)
24+ df <- runIOorExplode $ do
25+ d <- handleError <$> readNative nf
26+ writeDocx wopts{writerUserDataDir = Just (".." </> "data")} d
27+ df' <- handleError <$> runIOorExplode (readNative nf')
2628 let (p, _) = handleError $ readDocx (snd opts) df
27− return (p, handleError $ readNative nf')
29+ return (p, df')
2830
2931testCompareWithOptsIO :: Options -> String -> FilePath -> FilePath -> IO Test
3032testCompareWithOptsIO opts name nativeFileIn nativeFileOut = do