git.iko.soy/typeable/pandoc
on master help sign in
Put 'warn' in MonadIO. Add warnings for math conversions in docx.
77912ddJohn MacFarlane
src/Text/Pandoc/Shared.hs+5−4
@@ -127,6 +127,7 @@ import Text.Pandoc.MIME (MimeType, getMimeType)
127import System.FilePath ( (</>), takeExtension, dropExtension)
127import System.FilePath ( (</>), takeExtension, dropExtension)
128import Data.Generics (Typeable, Data)
128import Data.Generics (Typeable, Data)
129import qualified Control.Monad.State as S
129import qualified Control.Monad.State as S
130+import Control.Monad.Trans (MonadIO (..))
130import qualified Control.Exception as E
131import qualified Control.Exception as E
131import Control.Monad (msum, unless, MonadPlus(..))
132import Control.Monad (msum, unless, MonadPlus(..))
132import Text.Pandoc.Pretty (charWidth)
133import Text.Pandoc.Pretty (charWidth)
@@ -974,7 +975,7 @@ openURL u
974 UTF8.toString `fmap` lookup hContentType (responseHeaders resp))
975 UTF8.toString `fmap` lookup hContentType (responseHeaders resp))
975#else
976#else
976 | otherwise = E.try $ getBodyAndMimeType `fmap` browse
977 | otherwise = E.try $ getBodyAndMimeType `fmap` browse
977− (do S.liftIO $ UTF8.hPutStrLn stderr $ "Fetching " ++ u ++ "..."
978+ (do liftIO $ UTF8.hPutStrLn stderr $ "Fetching " ++ u ++ "..."
978 setOutHandler $ const (return ())
979 setOutHandler $ const (return ())
979 setAllowRedirects True
980 setAllowRedirects True
980 request (getRequest' u'))
981 request (getRequest' u'))
@@ -997,10 +998,10 @@ err exitCode msg = do
997 exitWith $ ExitFailure exitCode
998 exitWith $ ExitFailure exitCode
998 return undefined
999 return undefined
999
1000
1000−warn :: String -> IO ()
1001+warn :: MonadIO m => String -> m ()
1001−warn msg = do
1002+warn msg = liftIO $ do
1002 name <- getProgName
1003 name <- getProgName
1003− UTF8.hPutStrLn stderr $ name ++ ": " ++ msg
1004+ UTF8.hPutStrLn stderr $ "[" ++ name ++ " warning] " ++ msg
1004
1005
1005mapLeft :: (a -> b) -> Either a c -> Either b c
1006mapLeft :: (a -> b) -> Either a c -> Either b c
1006mapLeft f (Left x) = Left (f x)
1007mapLeft f (Left x) = Left (f x)
src/Text/Pandoc/Writers/Docx.hs+4−2
@@ -1115,7 +1115,9 @@ inlineToOpenXML' opts (Math mathType str) = do
1115 when (displayType == DisplayBlock) setFirstPara
1115 when (displayType == DisplayBlock) setFirstPara
1116 case writeOMML displayType <$> readTeX str of
1116 case writeOMML displayType <$> readTeX str of
1117 Right r -> return [r]
1117 Right r -> return [r]
1118+ Left e -> do
1119+ warn $ "Cannot convert the following TeX math, skipping:\n" ++ str
1118− Left _ -> inlinesToOpenXML opts (texMathToInlines mathType str)
1120+ inlinesToOpenXML opts (texMathToInlines mathType str)
1119inlineToOpenXML' opts (Cite _ lst) = inlinesToOpenXML opts lst
1121inlineToOpenXML' opts (Cite _ lst) = inlinesToOpenXML opts lst
1120inlineToOpenXML' opts (Code attrs str) = do
1122inlineToOpenXML' opts (Code attrs str) = do
1121 let unhighlighted = intercalate [br] `fmap`
1123 let unhighlighted = intercalate [br] `fmap`
@@ -1180,7 +1182,7 @@ inlineToOpenXML' opts (Image attr alt (src, title)) = do
1180 fetchItem' (writerMediaBag opts) (writerSourceURL opts) src
1182 fetchItem' (writerMediaBag opts) (writerSourceURL opts) src
1181 case res of
1183 case res of
1182 Left (_ :: E.SomeException) -> do
1184 Left (_ :: E.SomeException) -> do
1183− liftIO $ warn $ "Could not find image `" ++ src ++ "', skipping..."
1185+ warn $ "Could not find image `" ++ src ++ "', skipping..."
1184 -- emit alt text
1186 -- emit alt text
1185 inlinesToOpenXML opts alt
1187 inlinesToOpenXML opts alt
1186 Right (img, mt) -> do
1188 Right (img, mt) -> do
src/Text/Pandoc/Writers/ICML.hs+2−2
@@ -534,13 +534,13 @@ imageICML opts style attr (src, _) = do
534 res <- liftIO $ fetchItem (writerSourceURL opts) src
534 res <- liftIO $ fetchItem (writerSourceURL opts) src
535 imgS <- case res of
535 imgS <- case res of
536 Left (_) -> do
536 Left (_) -> do
537− liftIO $ warn $ "Could not find image `" ++ src ++ "', skipping..."
537+ warn $ "Could not find image `" ++ src ++ "', skipping..."
538 return def
538 return def
539 Right (img, _) -> do
539 Right (img, _) -> do
540 case imageSize img of
540 case imageSize img of
541 Right size -> return size
541 Right size -> return size
542 Left msg -> do
542 Left msg -> do
543− return $ warn $ "Could not determine image size in `" ++
543+ warn $ "Could not determine image size in `" ++
544 src ++ "': " ++ msg
544 src ++ "': " ++ msg
545 return def
545 return def
546 let (ow, oh) = sizeInPoints imgS
546 let (ow, oh) = sizeInPoints imgS