git.iko.soy/typeable/pandoc
on master help sign in
Put 'warn' in MonadIO. Add warnings for math conversions in docx.
commit77912ddc56650aacc47a4e6fe722e758a77b06e2 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 22 Nov 2016, 10:56 (10 years ago) parent7775374
3 files changed+11−8
src/Text/Pandoc/Shared.hs+5−4 src/Text/Pandoc/Writers/Docx.hs+4−2 src/Text/Pandoc/Writers/ICML.hs+2−2
src/Text/Pandoc/Shared.hs+5−4
@@ -127,6 +127,7 @@ import Text.Pandoc.MIME (MimeType, getMimeType)
127127import System.FilePath ( (</>), takeExtension, dropExtension)
128128import Data.Generics (Typeable, Data)
129129import qualified Control.Monad.State as S
130+import Control.Monad.Trans (MonadIO (..))
130131import qualified Control.Exception as E
131132import Control.Monad (msum, unless, MonadPlus(..))
132133import Text.Pandoc.Pretty (charWidth)
@@ -974,7 +975,7 @@ openURL u
974975 UTF8.toString `fmap` lookup hContentType (responseHeaders resp))
975976#else
976977 | otherwise = E.try $ getBodyAndMimeType `fmap` browse
977− (do S.liftIO $ UTF8.hPutStrLn stderr $ "Fetching " ++ u ++ "..."
978+ (do liftIO $ UTF8.hPutStrLn stderr $ "Fetching " ++ u ++ "..."
978979 setOutHandler $ const (return ())
979980 setAllowRedirects True
980981 request (getRequest' u'))
@@ -997,10 +998,10 @@ err exitCode msg = do
997998 exitWith $ ExitFailure exitCode
998999 return undefined
9991000
1000−warn :: String -> IO ()
1001−warn msg = do
1001+warn :: MonadIO m => String -> m ()
1002+warn msg = liftIO $ do
10021003 name <- getProgName
1003− UTF8.hPutStrLn stderr $ name ++ ": " ++ msg
1004+ UTF8.hPutStrLn stderr $ "[" ++ name ++ " warning] " ++ msg
10041005
10051006mapLeft :: (a -> b) -> Either a c -> Either b c
10061007mapLeft f (Left x) = Left (f x)
src/Text/Pandoc/Writers/Docx.hs+4−2
@@ -1115,7 +1115,9 @@ inlineToOpenXML' opts (Math mathType str) = do
11151115 when (displayType == DisplayBlock) setFirstPara
11161116 case writeOMML displayType <$> readTeX str of
11171117 Right r -> return [r]
1118− Left _ -> inlinesToOpenXML opts (texMathToInlines mathType str)
1118+ Left e -> do
1119+ warn $ "Cannot convert the following TeX math, skipping:\n" ++ str
1120+ inlinesToOpenXML opts (texMathToInlines mathType str)
11191121inlineToOpenXML' opts (Cite _ lst) = inlinesToOpenXML opts lst
11201122inlineToOpenXML' opts (Code attrs str) = do
11211123 let unhighlighted = intercalate [br] `fmap`
@@ -1180,7 +1182,7 @@ inlineToOpenXML' opts (Image attr alt (src, title)) = do
11801182 fetchItem' (writerMediaBag opts) (writerSourceURL opts) src
11811183 case res of
11821184 Left (_ :: E.SomeException) -> do
1183− liftIO $ warn $ "Could not find image `" ++ src ++ "', skipping..."
1185+ warn $ "Could not find image `" ++ src ++ "', skipping..."
11841186 -- emit alt text
11851187 inlinesToOpenXML opts alt
11861188 Right (img, mt) -> do
src/Text/Pandoc/Writers/ICML.hs+2−2
@@ -534,13 +534,13 @@ imageICML opts style attr (src, _) = do
534534 res <- liftIO $ fetchItem (writerSourceURL opts) src
535535 imgS <- case res of
536536 Left (_) -> do
537− liftIO $ warn $ "Could not find image `" ++ src ++ "', skipping..."
537+ warn $ "Could not find image `" ++ src ++ "', skipping..."
538538 return def
539539 Right (img, _) -> do
540540 case imageSize img of
541541 Right size -> return size
542542 Left msg -> do
543− return $ warn $ "Could not determine image size in `" ++
543+ warn $ "Could not determine image size in `" ++
544544 src ++ "': " ++ msg
545545 return def
546546 let (ow, oh) = sizeInPoints imgS