mirror of
https://github.com/jgm/pandoc.git
synced 2026-08-25 01:36:45 +00:00
Use throwError instead of fail when appropriate.
This commit is contained in:
@@ -258,10 +258,11 @@ yamlBsToMeta bstr = do
|
||||
err' pos
|
||||
return . return $ mempty
|
||||
|
||||
nodeToKey :: Monad m => YAML.Node YE.Pos -> m Text
|
||||
nodeToKey :: PandocMonad m => YAML.Node YE.Pos -> m Text
|
||||
nodeToKey (YAML.Scalar _ (YAML.SStr t)) = return t
|
||||
nodeToKey (YAML.Scalar _ (YAML.SUnknown _ t)) = return t
|
||||
nodeToKey _ = Prelude.fail "Non-string key in YAML mapping"
|
||||
nodeToKey _ = throwError $ PandocParseError
|
||||
"Non-string key in YAML mapping"
|
||||
|
||||
toMetaValue :: PandocMonad m
|
||||
=> Text -> MarkdownParser m (F MetaValue)
|
||||
|
||||
@@ -26,6 +26,7 @@ even though it is supported only in Emacs Muse.
|
||||
-}
|
||||
module Text.Pandoc.Writers.Muse (writeMuse) where
|
||||
import Prelude
|
||||
import Control.Monad.Except (throwError)
|
||||
import Control.Monad.Reader
|
||||
import Control.Monad.State.Strict
|
||||
import Data.Char (isAlphaNum, isAsciiLower, isAsciiUpper, isDigit, isSpace)
|
||||
@@ -37,6 +38,7 @@ import Data.Text (Text)
|
||||
import System.FilePath (takeExtension)
|
||||
import Text.Pandoc.Class (PandocMonad)
|
||||
import Text.Pandoc.Definition
|
||||
import Text.Pandoc.Error
|
||||
import Text.Pandoc.ImageSize
|
||||
import Text.Pandoc.Options
|
||||
import Text.DocLayout
|
||||
@@ -607,7 +609,8 @@ inlineToMuse (Subscript lst) = do
|
||||
modify $ \st -> st { stUseTags = False }
|
||||
return $ "<sub>" <> contents <> "</sub>"
|
||||
inlineToMuse SmallCaps {} =
|
||||
Prelude.fail "SmallCaps should be expanded before normalization"
|
||||
throwError $ PandocShouldNeverHappenError
|
||||
"SmallCaps should be expanded before normalization"
|
||||
inlineToMuse (Quoted SingleQuote lst) = do
|
||||
contents <- inlineListToMuse lst
|
||||
modify $ \st -> st { stUseTags = False }
|
||||
|
||||
@@ -25,6 +25,8 @@ module Text.Pandoc.Writers.OOXML ( mknode
|
||||
import Prelude
|
||||
import Codec.Archive.Zip
|
||||
import Control.Monad.Reader
|
||||
import Control.Monad.Except (throwError)
|
||||
import Text.Pandoc.Error
|
||||
import qualified Data.ByteString as B
|
||||
import qualified Data.ByteString.Lazy as BL
|
||||
import qualified Data.ByteString.Lazy.Char8 as BL8
|
||||
@@ -50,13 +52,15 @@ renderXml :: Element -> BL.ByteString
|
||||
renderXml elt = BL8.pack "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" <>
|
||||
UTF8.fromStringLazy (showElement elt)
|
||||
|
||||
parseXml :: (PandocMonad m) => Archive -> Archive -> String -> m Element
|
||||
parseXml :: PandocMonad m => Archive -> Archive -> String -> m Element
|
||||
parseXml refArchive distArchive relpath =
|
||||
case findEntryByPath relpath refArchive `mplus`
|
||||
findEntryByPath relpath distArchive of
|
||||
Nothing -> Prelude.fail $ relpath ++ " missing in reference file"
|
||||
Nothing -> throwError $ PandocSomeError $
|
||||
relpath ++ " missing in reference file"
|
||||
Just e -> case parseXMLDoc . UTF8.toStringLazy . fromEntry $ e of
|
||||
Nothing -> Prelude.fail $ relpath ++ " corrupt in reference file"
|
||||
Nothing -> throwError $ PandocSomeError $
|
||||
relpath ++ " corrupt in reference file"
|
||||
Just d -> return d
|
||||
|
||||
-- Copied from Util
|
||||
|
||||
Reference in New Issue
Block a user