Put 'warn' in MonadIO. Add warnings for math conversions in docx.
This commit is contained in:
parent
77753747d1
commit
77912ddc56
3 changed files with 11 additions and 8 deletions
|
@ -127,6 +127,7 @@ import Text.Pandoc.MIME (MimeType, getMimeType)
|
|||
import System.FilePath ( (</>), takeExtension, dropExtension)
|
||||
import Data.Generics (Typeable, Data)
|
||||
import qualified Control.Monad.State as S
|
||||
import Control.Monad.Trans (MonadIO (..))
|
||||
import qualified Control.Exception as E
|
||||
import Control.Monad (msum, unless, MonadPlus(..))
|
||||
import Text.Pandoc.Pretty (charWidth)
|
||||
|
@ -974,7 +975,7 @@ openURL u
|
|||
UTF8.toString `fmap` lookup hContentType (responseHeaders resp))
|
||||
#else
|
||||
| otherwise = E.try $ getBodyAndMimeType `fmap` browse
|
||||
(do S.liftIO $ UTF8.hPutStrLn stderr $ "Fetching " ++ u ++ "..."
|
||||
(do liftIO $ UTF8.hPutStrLn stderr $ "Fetching " ++ u ++ "..."
|
||||
setOutHandler $ const (return ())
|
||||
setAllowRedirects True
|
||||
request (getRequest' u'))
|
||||
|
@ -997,10 +998,10 @@ err exitCode msg = do
|
|||
exitWith $ ExitFailure exitCode
|
||||
return undefined
|
||||
|
||||
warn :: String -> IO ()
|
||||
warn msg = do
|
||||
warn :: MonadIO m => String -> m ()
|
||||
warn msg = liftIO $ do
|
||||
name <- getProgName
|
||||
UTF8.hPutStrLn stderr $ name ++ ": " ++ msg
|
||||
UTF8.hPutStrLn stderr $ "[" ++ name ++ " warning] " ++ msg
|
||||
|
||||
mapLeft :: (a -> b) -> Either a c -> Either b c
|
||||
mapLeft f (Left x) = Left (f x)
|
||||
|
|
|
@ -1115,7 +1115,9 @@ inlineToOpenXML' opts (Math mathType str) = do
|
|||
when (displayType == DisplayBlock) setFirstPara
|
||||
case writeOMML displayType <$> readTeX str of
|
||||
Right r -> return [r]
|
||||
Left _ -> inlinesToOpenXML opts (texMathToInlines mathType str)
|
||||
Left e -> do
|
||||
warn $ "Cannot convert the following TeX math, skipping:\n" ++ str
|
||||
inlinesToOpenXML opts (texMathToInlines mathType str)
|
||||
inlineToOpenXML' opts (Cite _ lst) = inlinesToOpenXML opts lst
|
||||
inlineToOpenXML' opts (Code attrs str) = do
|
||||
let unhighlighted = intercalate [br] `fmap`
|
||||
|
@ -1180,7 +1182,7 @@ inlineToOpenXML' opts (Image attr alt (src, title)) = do
|
|||
fetchItem' (writerMediaBag opts) (writerSourceURL opts) src
|
||||
case res of
|
||||
Left (_ :: E.SomeException) -> do
|
||||
liftIO $ warn $ "Could not find image `" ++ src ++ "', skipping..."
|
||||
warn $ "Could not find image `" ++ src ++ "', skipping..."
|
||||
-- emit alt text
|
||||
inlinesToOpenXML opts alt
|
||||
Right (img, mt) -> do
|
||||
|
|
|
@ -534,13 +534,13 @@ imageICML opts style attr (src, _) = do
|
|||
res <- liftIO $ fetchItem (writerSourceURL opts) src
|
||||
imgS <- case res of
|
||||
Left (_) -> do
|
||||
liftIO $ warn $ "Could not find image `" ++ src ++ "', skipping..."
|
||||
warn $ "Could not find image `" ++ src ++ "', skipping..."
|
||||
return def
|
||||
Right (img, _) -> do
|
||||
case imageSize img of
|
||||
Right size -> return size
|
||||
Left msg -> do
|
||||
return $ warn $ "Could not determine image size in `" ++
|
||||
warn $ "Could not determine image size in `" ++
|
||||
src ++ "': " ++ msg
|
||||
return def
|
||||
let (ow, oh) = sizeInPoints imgS
|
||||
|
|
Loading…
Add table
Reference in a new issue