git.iko.soy/typeable/pandoc
on master help sign in
Move utility error functions to Text.Pandoc.Shared
ad39bc7Matthew Pickering
src/Text/Pandoc.hs+1−1
@@ -164,7 +164,7 @@ import Text.Pandoc.Writers.Haddock
164import Text.Pandoc.Writers.Custom
164import Text.Pandoc.Writers.Custom
165import Text.Pandoc.Templates
165import Text.Pandoc.Templates
166import Text.Pandoc.Options
166import Text.Pandoc.Options
167−import Text.Pandoc.Shared (safeRead, warn)
167+import Text.Pandoc.Shared (safeRead, warn, mapLeft)
168import Text.Pandoc.MediaBag (MediaBag)
168import Text.Pandoc.MediaBag (MediaBag)
169import Text.Pandoc.Error
169import Text.Pandoc.Error
170import Data.Aeson
170import Data.Aeson
src/Text/Pandoc/Error.hs+1−8
@@ -28,7 +28,7 @@ This module provides a standard way to deal with possible errors encounted
28during parsing.
28during parsing.
29
29
30-}
30-}
31−module Text.Pandoc.Error (PandocError(..), handleError,hush, mapLeft) where
31+module Text.Pandoc.Error (PandocError(..), handleError) where
32
32
33import Text.Parsec.Error
33import Text.Parsec.Error
34import Text.Parsec.Pos hiding (Line)
34import Text.Parsec.Pos hiding (Line)
@@ -46,13 +46,6 @@ data PandocError = -- | Generic parse failure
46instance Error PandocError where
46instance Error PandocError where
47 strMsg = ParseFailure
47 strMsg = ParseFailure
48
48
49−mapLeft :: (a -> b) -> Either a c -> Either b c
50−mapLeft f (Left x) = Left (f x)
51−mapLeft _ (Right x) = Right x
52−
53−hush :: Either a b -> Maybe b
54−hush (Left _) = Nothing
55−hush (Right x) = Just x
56
49
57-- | An unsafe method to handle `PandocError`s.
50-- | An unsafe method to handle `PandocError`s.
58handleError :: Either PandocError a -> a
51handleError :: Either PandocError a -> a
src/Text/Pandoc/ImageSize.hs+1−2
@@ -39,10 +39,9 @@ import Control.Monad
39import Data.Bits
39import Data.Bits
40import Data.Binary
40import Data.Binary
41import Data.Binary.Get
41import Data.Binary.Get
42−import Text.Pandoc.Shared (safeRead)
42+import Text.Pandoc.Shared (safeRead, hush)
43import qualified Data.Map as M
43import qualified Data.Map as M
44import Text.Pandoc.Compat.Except
44import Text.Pandoc.Compat.Except
45−import Text.Pandoc.Error
46import Control.Monad.Trans
45import Control.Monad.Trans
47import Data.Maybe (fromMaybe)
46import Data.Maybe (fromMaybe)
48
47
src/Text/Pandoc/Readers/HTML.hs+1−1
@@ -44,7 +44,7 @@ import Text.Pandoc.Definition
44import qualified Text.Pandoc.Builder as B
44import qualified Text.Pandoc.Builder as B
45import Text.Pandoc.Builder (Blocks, Inlines, trimInlines, HasMeta(..))
45import Text.Pandoc.Builder (Blocks, Inlines, trimInlines, HasMeta(..))
46import Text.Pandoc.Shared ( extractSpaces, renderTags'
46import Text.Pandoc.Shared ( extractSpaces, renderTags'
47− , escapeURI, safeRead )
47+ , escapeURI, safeRead, mapLeft )
48import Text.Pandoc.Options (ReaderOptions(readerParseRaw, readerTrace)
48import Text.Pandoc.Options (ReaderOptions(readerParseRaw, readerTrace)
49 , Extension (Ext_epub_html_exts,
49 , Extension (Ext_epub_html_exts,
50 Ext_native_divs, Ext_native_spans))
50 Ext_native_divs, Ext_native_spans))
src/Text/Pandoc/Shared.hs+10
@@ -85,6 +85,8 @@ module Text.Pandoc.Shared (
85 -- * Error handling
85 -- * Error handling
86 err,
86 err,
87 warn,
87 warn,
88+ mapLeft,
89+ hush,
88 -- * Safe read
90 -- * Safe read
89 safeRead,
91 safeRead,
90 -- * Temp directory
92 -- * Temp directory
@@ -855,6 +857,14 @@ warn msg = do
855 name <- getProgName
857 name <- getProgName
856 UTF8.hPutStrLn stderr $ name ++ ": " ++ msg
858 UTF8.hPutStrLn stderr $ name ++ ": " ++ msg
857
859
860+mapLeft :: (a -> b) -> Either a c -> Either b c
861+mapLeft f (Left x) = Left (f x)
862+mapLeft _ (Right x) = Right x
863+
864+hush :: Either a b -> Maybe b
865+hush (Left _) = Nothing
866+hush (Right x) = Just x
867+
858-- | Remove intermediate "." and ".." directories from a path.
868-- | Remove intermediate "." and ".." directories from a path.
859--
869--
860-- > collapseFilePath "./foo" == "foo"
870-- > collapseFilePath "./foo" == "foo"