git.iko.soy/typeable/pandoc
on master help sign in
Use new warnings throughout the code base.
commit76c55466d3087224eccdc47c804ab2904be50df5 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 10 Feb 2017, 23:59 (10 years ago) parent8ad7e2c
21 files changed+203−176
src/Text/Pandoc/App.hs+1−2 src/Text/Pandoc/Class.hs+21−32 src/Text/Pandoc/Logging.hs+74−31 src/Text/Pandoc/Parsing.hs+8−2 src/Text/Pandoc/Readers/Docx.hs+6−3 src/Text/Pandoc/Readers/EPUB.hs+1−3 src/Text/Pandoc/Readers/HTML.hs+4−6 src/Text/Pandoc/Readers/LaTeX.hs+13−6 src/Text/Pandoc/Readers/Markdown.hs+11−14 src/Text/Pandoc/Readers/MediaWiki.hs+2−4 src/Text/Pandoc/Readers/RST.hs+28−33 src/Text/Pandoc/Readers/TWiki.hs+2−4 src/Text/Pandoc/Readers/Textile.hs+2−4 src/Text/Pandoc/Writers/Docx.hs+3−2 src/Text/Pandoc/Writers/EPUB.hs+4−4 src/Text/Pandoc/Writers/FB2.hs+4−6 src/Text/Pandoc/Writers/ICML.hs+4−4 src/Text/Pandoc/Writers/Math.hs+3−3 src/Text/Pandoc/Writers/ODT.hs+4−4 src/Text/Pandoc/Writers/RTF.hs+7−8 test/Tests/Readers/Docx.hs+1−1
src/Text/Pandoc/App.hs+1−2
@@ -348,8 +348,7 @@ convertWithOpts opts = do
348348 x <- f
349349 rs <- getLog
350350 return (x, rs)
351− let isWarning (WARNING, _) = True
352− isWarning _ = False
351+ let isWarning msg = messageVerbosity msg == WARNING
353352 when (optFailIfWarnings opts && any isWarning reports) $
354353 err 3 "Failing because there were warnings."
355354 return res
src/Text/Pandoc/Class.hs+21−32
@@ -41,8 +41,6 @@ module Text.Pandoc.Class ( PandocMonad(..)
4141 , getPOSIXTime
4242 , getZonedTime
4343 , readFileFromDirs
44− , warning
45− , warningWithPos
4644 , report
4745 , getLog
4846 , setVerbosity
@@ -73,7 +71,7 @@ import qualified Text.Pandoc.Shared as IO ( readDataFile
7371import qualified Text.Pandoc.UTF8 as UTF8
7472import Text.Pandoc.Compat.Time (UTCTime)
7573import Text.Pandoc.Logging
76−import Text.Parsec (ParsecT, SourcePos)
74+import Text.Parsec (ParsecT)
7775import qualified Text.Pandoc.Compat.Time as IO (getCurrentTime)
7876import Text.Pandoc.MIME (MimeType, getMimeType)
7977import Data.Time.Clock.POSIX ( utcTimeToPOSIXSeconds
@@ -131,7 +129,7 @@ class (Functor m, Applicative m, Monad m, MonadError PandocError m)
131129 modifyCommonState :: (CommonState -> CommonState) -> m ()
132130 modifyCommonState f = getCommonState >>= putCommonState . f
133131
134− logOutput :: Verbosity -> String -> m ()
132+ logOutput :: LogMessage -> m ()
135133
136134-- Functions defined for all PandocMonad instances
137135
@@ -139,25 +137,17 @@ setVerbosity :: PandocMonad m => Verbosity -> m ()
139137setVerbosity verbosity =
140138 modifyCommonState $ \st -> st{ stVerbosity = verbosity }
141139
142−getLog :: PandocMonad m => m [(Verbosity, String)]
140+getLog :: PandocMonad m => m [LogMessage]
143141getLog = reverse <$> getsCommonState stLog
144142
145−warning :: PandocMonad m => String -> m ()
146−warning msg = report WARNING msg
147−
148−warningWithPos :: PandocMonad m
149− => SourcePos
150− -> String
151− -> ParsecT s st m ()
152−warningWithPos pos msg = lift $ warning $ msg ++ " " ++ show pos
153−
154−report :: PandocMonad m => Verbosity -> String -> m ()
155−report level msg = do
143+report :: PandocMonad m => LogMessage -> m ()
144+report msg = do
156145 verbosity <- getsCommonState stVerbosity
146+ let level = messageVerbosity msg
157147 when (level <= verbosity) $ do
158− logOutput verbosity msg
148+ logOutput msg
159149 unless (level == DEBUG) $
160− modifyCommonState $ \st -> st{ stLog = (level, msg) : stLog st }
150+ modifyCommonState $ \st -> st{ stLog = msg : stLog st }
161151
162152setMediaBag :: PandocMonad m => MediaBag -> m ()
163153setMediaBag mb = modifyCommonState $ \st -> st{stMediaBag = mb}
@@ -187,17 +177,15 @@ getZonedTime = do
187177 return $ utcToZonedTime tz t
188178
189179-- | Read file, checking in any number of directories.
190−readFileFromDirs :: PandocMonad m => [FilePath] -> FilePath -> m String
191−readFileFromDirs [] f = do
192− warning $ "Could not load include file " ++ f ++ ", skipping."
193− return ""
180+readFileFromDirs :: PandocMonad m => [FilePath] -> FilePath -> m (Maybe String)
181+readFileFromDirs [] _ = return Nothing
194182readFileFromDirs (d:ds) f = catchError
195− (UTF8.toStringLazy <$> readFileLazy (d </> f))
183+ ((Just . UTF8.toStringLazy) <$> readFileLazy (d </> f))
196184 (\_ -> readFileFromDirs ds f)
197185
198186--
199187
200−data CommonState = CommonState { stLog :: [(Verbosity, String)]
188+data CommonState = CommonState { stLog :: [LogMessage]
201189 , stMediaBag :: MediaBag
202190 , stInputFiles :: Maybe [FilePath]
203191 , stOutputFile :: Maybe FilePath
@@ -266,8 +254,9 @@ instance PandocMonad PandocIO where
266254 Left _ -> throwError $ PandocFileReadError fp
267255 getCommonState = PandocIO $ lift get
268256 putCommonState x = PandocIO $ lift $ put x
269− logOutput level msg =
270− liftIO $ UTF8.hPutStrLn stderr $ printf "%-7s %s" (show level) msg
257+ logOutput msg =
258+ liftIO $ UTF8.hPutStrLn stderr $ printf "%-7s %s"
259+ (show (messageVerbosity msg)) (showLogMessage msg)
271260
272261-- | Specialized version of parseURIReference that disallows
273262-- single-letter schemes. Reason: these are usually windows absolute
@@ -466,7 +455,7 @@ instance PandocMonad PandocPure where
466455 getCommonState = PandocPure $ lift $ get
467456 putCommonState x = PandocPure $ lift $ put x
468457
469− logOutput _level _msg = return ()
458+ logOutput _msg = return ()
470459
471460instance PandocMonad m => PandocMonad (ParsecT s st m) where
472461 lookupEnv = lift . lookupEnv
@@ -482,7 +471,7 @@ instance PandocMonad m => PandocMonad (ParsecT s st m) where
482471 getModificationTime = lift . getModificationTime
483472 getCommonState = lift getCommonState
484473 putCommonState = lift . putCommonState
485− logOutput lvl = lift . logOutput lvl
474+ logOutput = lift . logOutput
486475
487476instance PandocMonad m => PandocMonad (ReaderT r m) where
488477 lookupEnv = lift . lookupEnv
@@ -498,7 +487,7 @@ instance PandocMonad m => PandocMonad (ReaderT r m) where
498487 getModificationTime = lift . getModificationTime
499488 getCommonState = lift getCommonState
500489 putCommonState = lift . putCommonState
501− logOutput lvl = lift . logOutput lvl
490+ logOutput = lift . logOutput
502491
503492instance (PandocMonad m, Monoid w) => PandocMonad (WriterT w m) where
504493 lookupEnv = lift . lookupEnv
@@ -514,7 +503,7 @@ instance (PandocMonad m, Monoid w) => PandocMonad (WriterT w m) where
514503 getModificationTime = lift . getModificationTime
515504 getCommonState = lift getCommonState
516505 putCommonState = lift . putCommonState
517− logOutput lvl = lift . logOutput lvl
506+ logOutput = lift . logOutput
518507
519508instance (PandocMonad m, Monoid w) => PandocMonad (RWST r w st m) where
520509 lookupEnv = lift . lookupEnv
@@ -530,7 +519,7 @@ instance (PandocMonad m, Monoid w) => PandocMonad (RWST r w st m) where
530519 getModificationTime = lift . getModificationTime
531520 getCommonState = lift getCommonState
532521 putCommonState = lift . putCommonState
533− logOutput lvl = lift . logOutput lvl
522+ logOutput = lift . logOutput
534523
535524instance PandocMonad m => PandocMonad (StateT st m) where
536525 lookupEnv = lift . lookupEnv
@@ -546,5 +535,5 @@ instance PandocMonad m => PandocMonad (StateT st m) where
546535 getModificationTime = lift . getModificationTime
547536 getCommonState = lift getCommonState
548537 putCommonState = lift . putCommonState
549− logOutput lvl = lift . logOutput lvl
538+ logOutput = lift . logOutput
550539
src/Text/Pandoc/Logging.hs+74−31
@@ -52,31 +52,35 @@ instance ToJSON Verbosity where
5252 toJSON x = toJSON (show x)
5353
5454data LogMessage =
55− SkippedInput String SourcePos
56− | YamlSectionNotAnObject SourcePos
55+ SkippedContent String SourcePos
56+ | CouldNotParseYamlMetadata String SourcePos
5757 | DuplicateLinkReference String SourcePos
5858 | DuplicateNoteReference String SourcePos
59+ | ReferenceNotFound String SourcePos
5960 | ParsingUnescaped String SourcePos
61+ | CouldNotLoadIncludeFile String SourcePos
62+ | ParsingTrace String SourcePos
6063 | InlineNotRendered Inline
6164 | BlockNotRendered Block
62− | DocxCommentWillNotRetainFormatting String
65+ | DocxParserWarning String
6366 | CouldNotFetchResource String String
64− | CouldNotDetermineImageSize String
67+ | CouldNotDetermineImageSize String String
6568 | CouldNotDetermineMimeType String
66− | CouldNotConvertTeXMath String
69+ | CouldNotConvertTeXMath String String
6770 deriving (Show, Eq, Data, Ord, Typeable, Generic)
6871
6972instance ToJSON LogMessage where
7073 toJSON x = object $ "verbosity" .= toJSON (messageVerbosity x) :
7174 case x of
72− SkippedInput s pos ->
73− ["type" .= String "SkippedInput",
75+ SkippedContent s pos ->
76+ ["type" .= String "SkippedContent",
7477 "contents" .= Text.pack s,
7578 "source" .= Text.pack (sourceName pos),
7679 "line" .= sourceLine pos,
7780 "column" .= sourceColumn pos]
78− YamlSectionNotAnObject pos ->
81+ CouldNotParseYamlMetadata s pos ->
7982 ["type" .= String "YamlSectionNotAnObject",
83+ "message" .= Text.pack s,
8084 "source" .= Text.pack (sourceName pos),
8185 "line" .= toJSON (sourceLine pos),
8286 "column" .= toJSON (sourceColumn pos)]
@@ -92,75 +96,114 @@ instance ToJSON LogMessage where
9296 "source" .= Text.pack (sourceName pos),
9397 "line" .= toJSON (sourceLine pos),
9498 "column" .= toJSON (sourceColumn pos)]
99+ ReferenceNotFound s pos ->
100+ ["type" .= String "ReferenceNotFound",
101+ "contents" .= Text.pack s,
102+ "source" .= Text.pack (sourceName pos),
103+ "line" .= toJSON (sourceLine pos),
104+ "column" .= toJSON (sourceColumn pos)]
95105 ParsingUnescaped s pos ->
96106 ["type" .= String "ParsingUnescaped",
97107 "contents" .= Text.pack s,
98108 "source" .= Text.pack (sourceName pos),
99109 "line" .= toJSON (sourceLine pos),
100110 "column" .= toJSON (sourceColumn pos)]
111+ CouldNotLoadIncludeFile fp pos ->
112+ ["type" .= String "CouldNotLoadIncludeFile",
113+ "path" .= Text.pack fp,
114+ "source" .= Text.pack (sourceName pos),
115+ "line" .= toJSON (sourceLine pos),
116+ "column" .= toJSON (sourceColumn pos)]
117+ ParsingTrace s pos ->
118+ ["type" .= String "ParsingTrace",
119+ "contents" .= Text.pack s,
120+ "source" .= Text.pack (sourceName pos),
121+ "line" .= sourceLine pos,
122+ "column" .= sourceColumn pos]
101123 InlineNotRendered il ->
102124 ["type" .= String "InlineNotRendered",
103125 "contents" .= toJSON il]
104126 BlockNotRendered bl ->
105127 ["type" .= String "BlockNotRendered",
106128 "contents" .= toJSON bl]
107− DocxCommentWillNotRetainFormatting s ->
108− ["type" .= String "DocxCommentWillNotRetainFormatting",
109− "commentId" .= Text.pack s]
129+ DocxParserWarning s ->
130+ ["type" .= String "DocxParserWarning",
131+ "contents" .= Text.pack s]
110132 CouldNotFetchResource fp s ->
111133 ["type" .= String "CouldNotFetchResource",
112134 "path" .= Text.pack fp,
113135 "message" .= Text.pack s]
114− CouldNotDetermineImageSize fp ->
136+ CouldNotDetermineImageSize fp s ->
115137 ["type" .= String "CouldNotDetermineImageSize",
116− "path" .= Text.pack fp]
138+ "path" .= Text.pack fp,
139+ "message" .= Text.pack s]
117140 CouldNotDetermineMimeType fp ->
118141 ["type" .= String "CouldNotDetermineMimeType",
119142 "path" .= Text.pack fp]
120− CouldNotConvertTeXMath s ->
143+ CouldNotConvertTeXMath s msg ->
121144 ["type" .= String "CouldNotConvertTeXMath",
122− "contents" .= Text.pack s]
145+ "contents" .= Text.pack s,
146+ "message" .= Text.pack msg]
147+
148+showPos :: SourcePos -> String
149+showPos pos = sn ++ "line " ++
150+ show (sourceLine pos) ++ " column " ++ show (sourceColumn pos)
151+ where sn = if sourceName pos == "source" || sourceName pos == ""
152+ then ""
153+ else sourceName pos ++ " "
123154
124155showLogMessage :: LogMessage -> String
125156showLogMessage msg =
126157 case msg of
127− SkippedInput s pos ->
128− "Skipped '" ++ s ++ "' at " ++ show pos
129− YamlSectionNotAnObject pos ->
130− "YAML metadata section is not an object at " ++ show pos
158+ SkippedContent s pos ->
159+ "Skipped '" ++ s ++ "' at " ++ showPos pos
160+ CouldNotParseYamlMetadata s pos ->
161+ "Could not parse YAML metadata at " ++ showPos pos ++
162+ if null s then "" else (": " ++ s)
131163 DuplicateLinkReference s pos ->
132− "Duplicate link reference '" ++ s ++ "' at " ++ show pos
164+ "Duplicate link reference '" ++ s ++ "' at " ++ showPos pos
133165 DuplicateNoteReference s pos ->
134− "Duplicate note reference '" ++ s ++ "' at " ++ show pos
166+ "Duplicate note reference '" ++ s ++ "' at " ++ showPos pos
167+ ReferenceNotFound s pos ->
168+ "Reference not found for '" ++ s ++ "' at " ++ showPos pos
135169 ParsingUnescaped s pos ->
136− "Parsing unescaped '" ++ s ++ "' at " ++ show pos
170+ "Parsing unescaped '" ++ s ++ "' at " ++ showPos pos
171+ CouldNotLoadIncludeFile fp pos ->
172+ "Could not load include file '" ++ fp ++ "' at " ++ showPos pos
173+ ParsingTrace s pos ->
174+ "Parsing trace at " ++ showPos pos ++ ": " ++ s
137175 InlineNotRendered il ->
138176 "Not rendering " ++ show il
139177 BlockNotRendered bl ->
140178 "Not rendering " ++ show bl
141− DocxCommentWillNotRetainFormatting s ->
142− "Docx comment with id '" ++ s ++ "' will not retain formatting"
179+ DocxParserWarning s ->
180+ "Docx parser warning: " ++ s
143181 CouldNotFetchResource fp s ->
144182 "Could not fetch resource '" ++ fp ++ "'" ++
145183 if null s then "" else (": " ++ s)
146− CouldNotDetermineImageSize fp ->
147− "Could not determine image size for '" ++ fp ++ "'"
184+ CouldNotDetermineImageSize fp s ->
185+ "Could not determine image size for '" ++ fp ++ "'" ++
186+ if null s then "" else (": " ++ s)
148187 CouldNotDetermineMimeType fp ->
149188 "Could not determine mime type for '" ++ fp ++ "'"
150− CouldNotConvertTeXMath s ->
151− "Could not convert TeX math '" ++ s ++ "', rendering as TeX"
189+ CouldNotConvertTeXMath s m ->
190+ "Could not convert TeX math '" ++ s ++ "', rendering as TeX" ++
191+ if null m then "" else (':':'\n':m)
152192
153193messageVerbosity:: LogMessage -> Verbosity
154194messageVerbosity msg =
155195 case msg of
156− SkippedInput{} -> INFO
157− YamlSectionNotAnObject{} -> WARNING
196+ SkippedContent{} -> INFO
197+ CouldNotParseYamlMetadata{} -> WARNING
158198 DuplicateLinkReference{} -> WARNING
159199 DuplicateNoteReference{} -> WARNING
200+ ReferenceNotFound{} -> WARNING
201+ CouldNotLoadIncludeFile{} -> WARNING
160202 ParsingUnescaped{} -> INFO
203+ ParsingTrace{} -> DEBUG
161204 InlineNotRendered{} -> INFO
162205 BlockNotRendered{} -> INFO
163− DocxCommentWillNotRetainFormatting{} -> INFO
206+ DocxParserWarning{} -> WARNING
164207 CouldNotFetchResource{} -> WARNING
165208 CouldNotDetermineImageSize{} -> WARNING
166209 CouldNotDetermineMimeType{} -> WARNING
src/Text/Pandoc/Parsing.hs+8−2
@@ -188,7 +188,8 @@ import Text.TeXMath.Readers.TeX.Macros (applyMacros, Macro,
188188import Text.HTML.TagSoup.Entity ( lookupEntity )
189189import Text.Pandoc.Asciify (toAsciiChar)
190190import Data.Monoid ((<>))
191−import Text.Pandoc.Class (PandocMonad, readFileFromDirs)
191+import Text.Pandoc.Class (PandocMonad, readFileFromDirs, report)
192+import Text.Pandoc.Logging
192193import Data.Default
193194import qualified Data.Set as Set
194195import Control.Monad.Reader
@@ -1289,7 +1290,12 @@ insertIncludedFile blocks dirs f = do
12891290 when (f `elem` containers) $
12901291 throwError $ PandocParseError $ "Include file loop at " ++ show oldPos
12911292 updateState $ \s -> s{ stateContainers = f : stateContainers s }
1292− contents <- readFileFromDirs dirs f
1293+ mbcontents <- readFileFromDirs dirs f
1294+ contents <- case mbcontents of
1295+ Just s -> return s
1296+ Nothing -> do
1297+ report $ CouldNotLoadIncludeFile f oldPos
1298+ return ""
12931299 setPosition $ newPos f 1 1
12941300 setInput contents
12951301 bs <- blocks
src/Text/Pandoc/Readers/Docx.hs+6−3
@@ -100,6 +100,7 @@ import Text.Pandoc.Error
100100import Control.Monad.Except (throwError)
101101import Text.Pandoc.Class (PandocMonad)
102102import qualified Text.Pandoc.Class as P
103+import Text.Pandoc.Logging
103104
104105readDocx :: PandocMonad m
105106 => ReaderOptions
@@ -108,12 +109,13 @@ readDocx :: PandocMonad m
108109readDocx opts bytes
109110 | Right archive <- toArchiveOrFail bytes
110111 , Right (docx, parserWarnings) <- archiveToDocxWithWarnings archive = do
111− mapM_ P.warning parserWarnings
112+ mapM_ (P.report . DocxParserWarning) parserWarnings
112113 (meta, blks) <- docxToOutput opts docx
113114 return $ Pandoc meta blks
114115readDocx _ _ =
115116 throwError $ PandocSomeError "couldn't parse docx file"
116117
118+-- TODO remove this for 2.0:
117119readDocxWithWarnings :: PandocMonad m
118120 => ReaderOptions
119121 -> B.ByteString
@@ -333,8 +335,9 @@ blocksToInlinesWarn cmtId blks = do
333335 notParaOrPlain (Para _) = False
334336 notParaOrPlain (Plain _) = False
335337 notParaOrPlain _ = True
336− when (not $ null $ filter notParaOrPlain blkList)
337− ((lift . lift) $ P.warning $ "Docx comment " ++ cmtId ++ " will not retain formatting")
338+ when (not $ null $ filter notParaOrPlain blkList) $
339+ lift $ P.report $ DocxParserWarning $
340+ "Docx comment " ++ cmtId ++ " will not retain formatting"
338341 return $ fromList $ blocksToInlines blkList
339342
340343parPartToInlines :: PandocMonad m => ParPart -> DocxContext m Inlines
src/Text/Pandoc/Readers/EPUB.hs+1−3
@@ -13,7 +13,6 @@ import Text.Pandoc.Definition hiding (Attr)
1313import Text.Pandoc.Readers.HTML (readHtml)
1414import Text.Pandoc.Walk (walk, query)
1515import Text.Pandoc.Options ( ReaderOptions(..))
16−import Text.Pandoc.Logging (Verbosity(..))
1716import Text.Pandoc.Extensions (enableExtension, Extension(Ext_raw_html))
1817import Text.Pandoc.Shared (escapeURI, collapseFilePath, addMetaField)
1918import Network.URI (unEscapeString)
@@ -35,7 +34,7 @@ import qualified Data.Map as M (Map, lookup, fromList, elems)
3534import Data.Monoid ((<>))
3635import Control.DeepSeq (deepseq, NFData)
3736import Text.Pandoc.Error
38−import Text.Pandoc.Class (PandocMonad, report)
37+import Text.Pandoc.Class (PandocMonad)
3938import qualified Text.Pandoc.Class as P
4039
4140type Items = M.Map String (FilePath, MimeType)
@@ -71,7 +70,6 @@ archiveToEPUB os archive = do
7170 os' = os {readerExtensions = enableExtension Ext_raw_html (readerExtensions os)}
7271 parseSpineElem :: PandocMonad m => FilePath -> (FilePath, MimeType) -> m Pandoc
7372 parseSpineElem (normalise -> r) (normalise -> path, mime) = do
74− report DEBUG ("parseSpineElem called with path " ++ show path)
7573 doc <- mimeToReader mime r path
7674 let docSpan = B.doc $ B.para $ B.spanWith (takeFileName path, [], []) mempty
7775 return $ docSpan <> doc
src/Text/Pandoc/Readers/HTML.hs+4−6
@@ -48,7 +48,7 @@ import Text.Pandoc.Shared ( extractSpaces, renderTags', addMetaField
4848import Text.Pandoc.Options (ReaderOptions(readerExtensions), extensionEnabled,
4949 Extension (Ext_epub_html_exts,
5050 Ext_raw_html, Ext_native_divs, Ext_native_spans))
51−import Text.Pandoc.Logging (Verbosity(..))
51+import Text.Pandoc.Logging
5252import Text.Pandoc.Parsing hiding ((<|>))
5353import Text.Pandoc.Walk
5454import qualified Data.Map as M
@@ -59,7 +59,6 @@ import Control.Monad ( guard, mzero, void, unless )
5959import Control.Arrow ((***))
6060import Control.Applicative ( (<|>) )
6161import Data.Monoid (First (..))
62−import Text.Printf (printf)
6362import Text.TeXMath (readMathML, writeTeX)
6463import Data.Default (Default (..), def)
6564import Control.Monad.Reader (ask, asks, local, ReaderT, runReaderT, lift)
@@ -69,7 +68,7 @@ import Data.Monoid ((<>))
6968import Text.Parsec.Error
7069import qualified Data.Set as Set
7170import Text.Pandoc.Error
72−import Text.Pandoc.Class (PandocMonad, report, warningWithPos)
71+import Text.Pandoc.Class (PandocMonad, report)
7372import Control.Monad.Except (throwError)
7473
7574-- | Convert HTML-formatted string to 'Pandoc' document.
@@ -177,8 +176,7 @@ block = do
177176 , pPlain
178177 , pRawHtmlBlock
179178 ]
180− report DEBUG $ printf "line %d: %s"
181− (sourceLine pos) (take 60 $ show $ B.toList res)
179+ report $ ParsingTrace (take 60 $ show $ B.toList res) pos
182180 return res
183181
184182namespaces :: PandocMonad m => [(String, TagParser m Inlines)]
@@ -378,7 +376,7 @@ ignore raw = do
378376 -- raw can be null for tags like <!DOCTYPE>; see paRawTag
379377 -- in this case we don't want a warning:
380378 unless (null raw) $
381− warningWithPos pos $ "Skipped " ++ raw
379+ report $ SkippedContent raw pos
382380 return mempty
383381
384382pHtmlBlock :: PandocMonad m => String -> TagParser m String
src/Text/Pandoc/Readers/LaTeX.hs+13−6
@@ -38,6 +38,7 @@ import Text.Pandoc.Definition
3838import Text.Pandoc.Walk
3939import Text.Pandoc.Shared
4040import Text.Pandoc.Options
41+import Text.Pandoc.Logging
4142import Text.Pandoc.Parsing hiding ((<|>), many, optional, space,
4243 mathDisplay, mathInline)
4344import Data.Char ( chr, ord, isLetter, isAlphaNum )
@@ -51,7 +52,7 @@ import qualified Data.Map as M
5152import Text.Pandoc.Highlighting (fromListingsLanguage, languagesByExtension)
5253import Text.Pandoc.ImageSize (numUnit, showFl)
5354import Control.Monad.Except (throwError)
54−import Text.Pandoc.Class (PandocMonad, PandocPure, lookupEnv, warningWithPos,
55+import Text.Pandoc.Class (PandocMonad, PandocPure, lookupEnv, report,
5556 readFileFromDirs)
5657
5758-- | Parse LaTeX from string and return 'Pandoc' document.
@@ -235,7 +236,7 @@ inline = (mempty <$ comment)
235236 <|> (str . (:[]) <$> tildeEscape)
236237 <|> (do res <- oneOf "#&~^'`\"[]"
237238 pos <- getPosition
238− warningWithPos pos ("Parsing unescaped '" ++ [res] ++ "'")
239+ report $ ParsingUnescaped [res] pos
239240 return $ str [res])
240241
241242inlines :: PandocMonad m => LP m Inlines
@@ -312,7 +313,7 @@ optargs = snd <$> withRaw (skipopts *> skipMany (try $ optional sp *> braced))
312313ignore :: (Monoid a, PandocMonad m) => String -> ParserT s u m a
313314ignore raw = do
314315 pos <- getPosition
315− warningWithPos pos $ "Skipped " ++ raw
316+ report $ SkippedContent raw pos
316317 return mempty
317318
318319ignoreBlocks :: PandocMonad m => String -> (String, LP m Blocks)
@@ -943,14 +944,14 @@ rawEnv name = do
943944 let beginCommand = "\\begin{" ++ name ++ "}" ++ rawOptions
944945 unless parseRaw $ do
945946 pos1 <- getPosition
946− warningWithPos pos1 $ "Skipped " ++ beginCommand
947+ report $ SkippedContent beginCommand pos1
947948 (bs, raw) <- withRaw $ env name blocks
948949 raw' <- applyMacros' raw
949950 if parseRaw
950951 then return $ rawBlock "latex" $ beginCommand ++ raw'
951952 else do
952953 pos2 <- getPosition
953− warningWithPos pos2 $ "Skipped \\end{" ++ name ++ "}"
954+ report $ SkippedContent ("\\end{" ++ name ++ "}") pos2
954955 return bs
955956
956957----
@@ -982,10 +983,16 @@ include = do
982983
983984inputListing :: PandocMonad m => LP m Blocks
984985inputListing = do
986+ pos <- getPosition
985987 options <- option [] keyvals
986988 f <- filter (/='"') <$> braced
987989 dirs <- (splitBy (==':') . fromMaybe ".") <$> lookupEnv "TEXINPUTS"
988− codeLines <- lines <$> readFileFromDirs dirs f
990+ mbCode <- readFileFromDirs dirs f
991+ codeLines <- case mbCode of
992+ Just s -> return $ lines s
993+ Nothing -> do
994+ report $ CouldNotLoadIncludeFile f pos
995+ return []
989996 let (ident,classes,kvs) = parseListingsOptions options
990997 let language = case lookup "language" options >>= fromListingsLanguage of
991998 Just l -> [l]
src/Text/Pandoc/Readers/Markdown.hs+11−14
@@ -51,7 +51,7 @@ import qualified Text.Pandoc.UTF8 as UTF8
5151import qualified Data.Vector as V
5252import Text.Pandoc.Builder (Inlines, Blocks, trimInlines)
5353import Text.Pandoc.Options
54−import Text.Pandoc.Logging (Verbosity(..))
54+import Text.Pandoc.Logging
5555import Text.Pandoc.Shared
5656import Text.Pandoc.Pretty (charWidth)
5757import Text.Pandoc.XML (fromEntities)
@@ -62,12 +62,10 @@ import Text.Pandoc.Readers.HTML ( htmlTag, htmlInBalanced, isInlineTag, isBlockT
6262import Control.Monad
6363import System.FilePath (takeExtension, addExtension)
6464import Text.HTML.TagSoup
65−import Text.Printf (printf)
6665import Data.Monoid ((<>))
6766import Control.Monad.Trans (lift)
6867import Control.Monad.Except (throwError, catchError)
6968import Text.Pandoc.Class (PandocMonad, report)
70−import qualified Text.Pandoc.Class as P
7169
7270type MarkdownParser m = ParserT [Char] ParserState m
7371
@@ -270,7 +268,8 @@ yamlMetaBlock = try $ do
270268 ) nullMeta hashmap
271269 Right Yaml.Null -> return nullMeta
272270 Right _ -> do
273− P.warningWithPos pos "YAML header is not an object"
271+ report $ CouldNotParseYamlMetadata "not an object"
272+ pos
274273 return nullMeta
275274 Left err' -> do
276275 case err' of
@@ -281,15 +280,13 @@ yamlMetaBlock = try $ do
281280 yamlLine = yline
282281 , yamlColumn = ycol
283282 }}) ->
284− P.warningWithPos (setSourceLine
283+ report $ CouldNotParseYamlMetadata
284+ problem (setSourceLine
285285 (setSourceColumn pos
286286 (sourceColumn pos + ycol))
287287 (sourceLine pos + 1 + yline))
288− $ "Could not parse YAML header: " ++
289− problem
290− _ -> P.warningWithPos pos
291− $ "Could not parse YAML header: " ++
292− show err'
288+ _ -> report $ CouldNotParseYamlMetadata
289+ (show err') pos
293290 return nullMeta
294291 updateState $ \st -> st{ stateMeta' = stateMeta' st <> (return meta') }
295292 return mempty
@@ -406,7 +403,7 @@ referenceKey = try $ do
406403 let oldkeys = stateKeys st
407404 let key = toKey raw
408405 case M.lookup key oldkeys of
409− Just _ -> P.warningWithPos pos $ "Duplicate link reference `" ++ raw ++ "'"
406+ Just _ -> report $ DuplicateLinkReference raw pos
410407 Nothing -> return ()
411408 updateState $ \s -> s { stateKeys = M.insert key (target, attr') oldkeys }
412409 return $ return mempty
@@ -472,7 +469,7 @@ noteBlock = try $ do
472469 let newnote = (ref, parsed)
473470 oldnotes <- stateNotes' <$> getState
474471 case lookup ref oldnotes of
475− Just _ -> P.warningWithPos pos $ "Duplicate note reference `" ++ ref ++ "'"
472+ Just _ -> report $ DuplicateNoteReference ref pos
476473 Nothing -> return ()
477474 updateState $ \s -> s { stateNotes' = newnote : oldnotes }
478475 return mempty
@@ -512,8 +509,8 @@ block = do
512509 , para
513510 , plain
514511 ] <?> "block"
515− report DEBUG $ printf "line %d: %s" (sourceLine pos)
516− (take 60 $ show $ B.toList $ runF res defaultParserState)
512+ report $ ParsingTrace
513+ (take 60 $ show $ B.toList $ runF res defaultParserState) pos
517514 return res
518515
519516--
src/Text/Pandoc/Readers/MediaWiki.hs+2−4
@@ -41,7 +41,7 @@ import qualified Text.Pandoc.Builder as B
4141import Text.Pandoc.Builder (Inlines, Blocks, trimInlines)
4242import Data.Monoid ((<>))
4343import Text.Pandoc.Options
44−import Text.Pandoc.Logging (Verbosity(..))
44+import Text.Pandoc.Logging
4545import Text.Pandoc.Readers.HTML ( htmlTag, isBlockTag, isCommentTag )
4646import Text.Pandoc.XML ( fromEntities )
4747import Text.Pandoc.Parsing hiding ( nested )
@@ -56,7 +56,6 @@ import qualified Data.Map as M
5656import qualified Data.Set as Set
5757import Data.Char (isDigit, isSpace)
5858import Data.Maybe (fromMaybe)
59−import Text.Printf (printf)
6059import Control.Monad.Except (throwError)
6160import Text.Pandoc.Class (PandocMonad, report)
6261
@@ -207,8 +206,7 @@ block = do
207206 <|> blockTag
208207 <|> (B.rawBlock "mediawiki" <$> template)
209208 <|> para
210− report DEBUG $ printf "line %d: %s" (sourceLine pos)
211− (take 60 $ show $ B.toList res)
209+ report $ ParsingTrace (take 60 $ show $ B.toList res) pos
212210 return res
213211
214212para :: PandocMonad m => MWParser m Blocks
src/Text/Pandoc/Readers/RST.hs+28−33
@@ -36,6 +36,7 @@ import Text.Pandoc.Builder (setMeta, fromList)
3636import Text.Pandoc.Shared
3737import Text.Pandoc.Parsing
3838import Text.Pandoc.Options
39+import Text.Pandoc.Logging
3940import Text.Pandoc.Error
4041import Control.Monad ( when, liftM, guard, mzero )
4142import Data.List ( findIndex, intercalate, isInfixOf,
@@ -49,8 +50,7 @@ import Data.Sequence (viewr, ViewR(..))
4950import Data.Char (toLower, isHexDigit, isSpace, toUpper)
5051import Data.Monoid ((<>))
5152import Control.Monad.Except (throwError)
52−import Text.Pandoc.Class (PandocMonad, warning, readFileFromDirs,
53− warningWithPos)
53+import Text.Pandoc.Class (PandocMonad, report, readFileFromDirs)
5454
5555-- | Parse reStructuredText string and return Pandoc document.
5656readRST :: PandocMonad m
@@ -421,8 +421,12 @@ include = try $ do
421421 when (f `elem` containers) $
422422 throwError $ PandocParseError $ "Include file loop at " ++ show oldPos
423423 updateState $ \s -> s{ stateContainers = f : stateContainers s }
424− contents <- readFileFromDirs ["."] f
425− let contentLines = lines contents
424+ mbContents <- readFileFromDirs ["."] f
425+ contentLines <- case mbContents of
426+ Just s -> return $ lines s
427+ Nothing -> do
428+ report $ CouldNotLoadIncludeFile f oldPos
429+ return []
426430 let numLines = length contentLines
427431 let startLine' = case startLine of
428432 Nothing -> 1
@@ -688,7 +692,7 @@ directive' = do
688692 return $ B.divWith attrs children
689693 other -> do
690694 pos <- getPosition
691− warningWithPos pos $ "ignoring unknown directive: " ++ other
695+ report $ SkippedContent (".. " ++ other) pos
692696 return mempty
693697
694698-- TODO:
@@ -696,6 +700,7 @@ directive' = do
696700-- change Text.Pandoc.Definition.Format to fix
697701addNewRole :: PandocMonad m => String -> [(String, String)] -> RSTParser m Blocks
698702addNewRole roleString fields = do
703+ pos <- getPosition
699704 (role, parentRole) <- parseFromString inheritedRole roleString
700705 customRoles <- stateRstCustomRoles <$> getState
701706 let getBaseRole (r, f, a) roles =
@@ -716,22 +721,18 @@ addNewRole roleString fields = do
716721
717722 -- warn about syntax we ignore
718723 flip mapM_ fields $ \(key, _) -> case key of
719− "language" -> when (baseRole /= "code") $ warning $
720− "ignoring :language: field because the parent of role :" ++
721− role ++ ": is :" ++ baseRole ++ ": not :code:"
722− "format" -> when (baseRole /= "raw") $ warning $
723− "ignoring :format: field because the parent of role :" ++
724− role ++ ": is :" ++ baseRole ++ ": not :raw:"
725− _ -> warning $ "ignoring unknown field :" ++ key ++
726− ": in definition of role :" ++ role ++ ": in"
724+ "language" -> when (baseRole /= "code") $ report $
725+ SkippedContent ":language: [because parent of role is not :code:]"
726+ pos
727+ "format" -> when (baseRole /= "raw") $ report $
728+ SkippedContent ":format: [because parent of role is not :raw:]" pos
729+ _ -> report $ SkippedContent (":" ++ key ++ ":") pos
727730 when (parentRole == "raw" && countKeys "format" > 1) $
728− warning $
729− "ignoring :format: fields after the first in the definition of role :"
730− ++ role ++": in"
731+ report $ SkippedContent ":format: [after first in definition of role]"
732+ pos
731733 when (parentRole == "code" && countKeys "language" > 1) $
732− warning $
733− "ignoring :language: fields after the first in the definition of role :"
734− ++ role ++": in"
734+ report $ SkippedContent
735+ ":language: [after first in definition of role]" pos
735736
736737 updateState $ \s -> s {
737738 stateRstCustomRoles =
@@ -1011,9 +1012,9 @@ simpleTable headless = do
10111012 case B.toList tbl of
10121013 [Table c a _w h l] -> return $ B.singleton $
10131014 Table c a (replicate (length a) 0) h l
1014− _ -> do
1015− warning "tableWith returned something unexpected"
1016− return tbl -- TODO error?
1015+ _ ->
1016+ throwError $ PandocShouldNeverHappenError
1017+ "tableWith returned something unexpected"
10171018 where
10181019 sep = return () -- optional (simpleTableSep '-')
10191020
@@ -1132,7 +1133,7 @@ renderRole contents fmt role attr = case role of
11321133 renderRole contents newFmt newRole newAttr
11331134 Nothing -> do
11341135 pos <- getPosition
1135− warningWithPos pos $ "ignoring unknown role :" ++ custom ++ ": in"
1136+ report $ SkippedContent (":" ++ custom ++ ":") pos
11361137 return $ B.str contents -- Undefined role
11371138 where
11381139 titleRef ref = return $ B.str ref -- FIXME: Not a sensible behaviour
@@ -1217,9 +1218,7 @@ explicitLink = try $ do
12171218 case M.lookup key keyTable of
12181219 Nothing -> do
12191220 pos <- getPosition
1220− warningWithPos pos $
1221− "Could not find reference for " ++
1222− show key
1221+ report $ ReferenceNotFound (show key) pos
12231222 return ("","",nullAttr)
12241223 Just ((s,t),a) -> return (s,t,a)
12251224 _ -> return (src, "", nullAttr)
@@ -1242,9 +1241,7 @@ referenceLink = try $ do
12421241 ((src,tit), attr) <- case M.lookup key keyTable of
12431242 Nothing -> do
12441243 pos <- getPosition
1245− warningWithPos pos $
1246− "Could not find reference for " ++
1247− show key
1244+ report $ ReferenceNotFound (show key) pos
12481245 return (("",""),nullAttr)
12491246 Just val -> return val
12501247 -- if anonymous link, remove key so it won't be used again
@@ -1273,8 +1270,7 @@ subst = try $ do
12731270 case M.lookup key substTable of
12741271 Nothing -> do
12751272 pos <- getPosition
1276− warningWithPos pos $
1277− "Could not find reference for " ++ show key
1273+ report $ ReferenceNotFound (show key) pos
12781274 return mempty
12791275 Just target -> return target
12801276
@@ -1288,8 +1284,7 @@ note = try $ do
12881284 case lookup ref notes of
12891285 Nothing -> do
12901286 pos <- getPosition
1291− warningWithPos pos $
1292− "Could not find note for " ++ show ref
1287+ report $ ReferenceNotFound (show ref) pos
12931288 return mempty
12941289 Just raw -> do
12951290 -- We temporarily empty the note list while parsing the note,
src/Text/Pandoc/Readers/TWiki.hs+2−4
@@ -35,11 +35,10 @@ module Text.Pandoc.Readers.TWiki ( readTWiki
3535import Text.Pandoc.Definition
3636import qualified Text.Pandoc.Builder as B
3737import Text.Pandoc.Options
38−import Text.Pandoc.Logging (Verbosity(..))
38+import Text.Pandoc.Logging
3939import Text.Pandoc.Parsing hiding (enclosed, macro, nested)
4040import Text.Pandoc.Readers.HTML (htmlTag, isCommentTag)
4141import Control.Monad
42−import Text.Printf (printf)
4342import Text.Pandoc.XML (fromEntities)
4443import Data.Maybe (fromMaybe)
4544import Text.HTML.TagSoup
@@ -133,8 +132,7 @@ block = do
133132 <|> blockElements
134133 <|> para
135134 skipMany blankline
136− report DEBUG $ printf "line %d: %s" (sourceLine pos)
137− (take 60 $ show $ B.toList res)
135+ report $ ParsingTrace (take 60 $ show $ B.toList res) pos
138136 return res
139137
140138blockElements :: PandocMonad m => TWParser m B.Blocks
src/Text/Pandoc/Readers/Textile.hs+2−4
@@ -56,8 +56,8 @@ import Text.Pandoc.Definition
5656import Text.Pandoc.Builder (Inlines, Blocks, trimInlines)
5757import qualified Text.Pandoc.Builder as B
5858import Text.Pandoc.Options
59−import Text.Pandoc.Logging (Verbosity(..))
6059import Text.Pandoc.Parsing
60+import Text.Pandoc.Logging
6161import Text.Pandoc.Readers.HTML ( htmlTag, isBlockTag, isInlineTag )
6262import Text.Pandoc.Shared (trim)
6363import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXBlock )
@@ -67,7 +67,6 @@ import Data.List ( intercalate, transpose, intersperse )
6767import Data.Char ( digitToInt, isUpper )
6868import Control.Monad ( guard, liftM )
6969import Data.Monoid ((<>))
70−import Text.Printf
7170import Text.Pandoc.Class (PandocMonad, report)
7271import Control.Monad.Except (throwError)
7372
@@ -141,8 +140,7 @@ block :: PandocMonad m => ParserT [Char] ParserState m Blocks
141140block = do
142141 res <- choice blockParsers <?> "block"
143142 pos <- getPosition
144− report DEBUG $ printf "line %d: %s" (sourceLine pos)
145− (take 60 $ show $ B.toList res)
143+ report $ ParsingTrace (take 60 $ show $ B.toList res) pos
146144 return res
147145
148146commentBlock :: PandocMonad m => ParserT [Char] ParserState m Blocks
src/Text/Pandoc/Writers/Docx.hs+3−2
@@ -65,8 +65,9 @@ import Text.Pandoc.MIME (MimeType, getMimeType, getMimeTypeDef,
6565import Control.Applicative ((<|>))
6666import Data.Maybe (fromMaybe, mapMaybe, maybeToList, isNothing)
6767import Data.Char (ord, isSpace, toLower)
68−import Text.Pandoc.Class (PandocMonad)
68+import Text.Pandoc.Class (PandocMonad, report)
6969import qualified Text.Pandoc.Class as P
70+import Text.Pandoc.Logging
7071
7172data ListMarker = NoMarker
7273 | BulletMarker
@@ -1173,7 +1174,7 @@ inlineToOpenXML' opts (Image attr alt (src, title)) = do
11731174 res <- runExceptT $ lift (P.fetchItem (writerSourceURL opts) src)
11741175 case res of
11751176 Left (_ :: PandocError) -> do
1176− P.warning ("Could not find image `" ++ src ++ "', skipping...")
1177+ report $ CouldNotFetchResource src ""
11771178 -- emit alt text
11781179 inlinesToOpenXML opts alt
11791180 Right (img, mt) -> do
src/Text/Pandoc/Writers/EPUB.hs+4−4
@@ -29,6 +29,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2929Conversion of 'Pandoc' documents to EPUB.
3030-}
3131module Text.Pandoc.Writers.EPUB ( writeEPUB2, writeEPUB3 ) where
32+import Text.Pandoc.Logging
3233import qualified Data.Map as M
3334import qualified Data.Set as Set
3435import Data.Maybe ( fromMaybe, catMaybes )
@@ -65,7 +66,7 @@ import Text.Pandoc.MIME (MimeType, getMimeType, extensionFromMimeType)
6566import Text.HTML.TagSoup (Tag(TagOpen), fromAttrib, parseTags)
6667import Control.Monad.Except (throwError, catchError)
6768import Text.Pandoc.Error
68−import Text.Pandoc.Class (PandocMonad)
69+import Text.Pandoc.Class (PandocMonad, report)
6970import qualified Text.Pandoc.Class as P
7071
7172-- A Chapter includes a list of blocks and maybe a section
@@ -415,7 +416,7 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
415416 let matchingGlob f = do
416417 xs <- lift $ P.glob f
417418 when (null xs) $
418− lift $ P.warning $ f ++ " did not match any font files."
419+ report $ CouldNotFetchResource f "glob did not match any font files"
419420 return xs
420421 let mkFontEntry f = mkEntry (takeFileName f) `fmap` (lift $ P.readFileLazy f)
421422 fontFiles <- concat <$> mapM matchingGlob (writerEpubFonts opts')
@@ -883,8 +884,7 @@ modifyMediaRef opts oldsrc = do
883884 (oldsrc, (new, Just entry)):media}
884885 return new)
885886 (\e -> do
886− P.warning $ "Could not find media `" ++ oldsrc ++
887− "', skipping...\n" ++ show e
887+ report $ CouldNotFetchResource oldsrc (show e)
888888 return oldsrc)
889889
890890transformBlock :: PandocMonad m
src/Text/Pandoc/Writers/FB2.hs+4−6
@@ -41,13 +41,13 @@ import qualified Text.XML.Light.Cursor as XC
4141import qualified Data.ByteString.Char8 as B8
4242import Control.Monad.Except (throwError, catchError)
4343
44−
44+import Text.Pandoc.Logging
4545import Text.Pandoc.Definition
4646import Text.Pandoc.Options (WriterOptions(..), HTMLMathMethod(..), def)
4747import Text.Pandoc.Shared (orderedListMarkers, isHeaderBlock, capitalize,
4848 linesToPara)
4949import Text.Pandoc.Error
50−import Text.Pandoc.Class (PandocMonad)
50+import Text.Pandoc.Class (PandocMonad, report)
5151import qualified Text.Pandoc.Class as P
5252
5353-- | Data to be written at the end of the document:
@@ -244,14 +244,12 @@ fetchImage href link = do
244244 catchError (do (bs, mbmime) <- P.fetchItem Nothing link
245245 case mbmime of
246246 Nothing -> do
247− P.warning ("Could not determine mime type for "
248− ++ link)
247+ report $ CouldNotDetermineMimeType link
249248 return Nothing
250249 Just mime -> return $ Just (mime,
251250 B8.unpack $ encode bs))
252251 (\e ->
253− do P.warning ("Could not fetch " ++ link ++
254− ":\n" ++ show e)
252+ do report $ CouldNotFetchResource link (show e)
255253 return Nothing)
256254 case mbimg of
257255 Just (imgtype, imgdata) -> do
src/Text/Pandoc/Writers/ICML.hs+4−4
@@ -30,7 +30,8 @@ import Control.Monad.State
3030import Control.Monad.Except (runExceptT)
3131import Network.URI (isURI)
3232import qualified Data.Set as Set
33−import Text.Pandoc.Class (PandocMonad)
33+import Text.Pandoc.Class (PandocMonad, report)
34+import Text.Pandoc.Logging
3435import qualified Text.Pandoc.Class as P
3536
3637type Style = [String]
@@ -538,14 +539,13 @@ imageICML opts style attr (src, _) = do
538539 res <- runExceptT $ lift $ P.fetchItem (writerSourceURL opts) src
539540 imgS <- case res of
540541 Left (_ :: PandocError) -> do
541− lift $ P.warning $ "Could not find image `" ++ src ++ "', skipping..."
542+ report $ CouldNotFetchResource src ""
542543 return def
543544 Right (img, _) -> do
544545 case imageSize img of
545546 Right size -> return size
546547 Left msg -> do
547− lift $ P.warning $ "Could not determine image size in `" ++
548− src ++ "': " ++ msg
548+ report $ CouldNotDetermineImageSize src msg
549549 return def
550550 let (ow, oh) = sizeInPoints imgS
551551 (imgWidth, imgHeight) = desiredSizeInPoints opts attr imgS
src/Text/Pandoc/Writers/Math.hs+3−3
@@ -6,6 +6,7 @@ where
66
77import Text.Pandoc.Class
88import Text.Pandoc.Definition
9+import Text.Pandoc.Logging
910import Text.TeXMath (Exp, writePandoc, DisplayType(..), readTeX)
1011
1112-- | Converts a raw TeX math formula to a list of 'Pandoc' inlines.
@@ -20,7 +21,7 @@ texMathToInlines mt inp = do
2021 case res of
2122 Right (Just ils) -> return ils
2223 Right (Nothing) -> do
23− warning $ "Could not render TeX math as unicode, rendering as raw TeX:\n" ++ inp
24+ report $ CouldNotConvertTeXMath inp ""
2425 return [mkFallback mt inp]
2526 Left il -> return [il]
2627
@@ -40,8 +41,7 @@ convertMath writer mt str = do
4041 case writer dt <$> readTeX str of
4142 Right r -> return (Right r)
4243 Left e -> do
43− warning $ "Could not convert TeX math, rendering as raw TeX:\n" ++
44− str ++ "\n" ++ e
44+ report $ CouldNotConvertTeXMath str e
4545 return (Left $ mkFallback mt str)
4646 where dt = case mt of
4747 DisplayMath -> DisplayBlock
src/Text/Pandoc/Writers/ODT.hs+4−4
@@ -50,8 +50,9 @@ import Text.Pandoc.Error (PandocError)
5050import Text.Pandoc.XML
5151import Text.Pandoc.Pretty
5252import System.FilePath ( takeExtension, takeDirectory, (<.>))
53−import Text.Pandoc.Class ( PandocMonad )
53+import Text.Pandoc.Class ( PandocMonad, report )
5454import qualified Text.Pandoc.Class as P
55+import Text.Pandoc.Logging
5556
5657data ODTState = ODTState { stEntries :: [Entry]
5758 }
@@ -149,14 +150,13 @@ transformPicMath opts (Image attr@(id', cls, _) lab (src,t)) = do
149150 res <- runExceptT $ lift $ P.fetchItem (writerSourceURL opts) src
150151 case res of
151152 Left (_ :: PandocError) -> do
152− lift $ P.warning $ "Could not find image `" ++ src ++ "', skipping..."
153+ report $ CouldNotFetchResource src ""
153154 return $ Emph lab
154155 Right (img, mbMimeType) -> do
155156 (ptX, ptY) <- case imageSize img of
156157 Right s -> return $ sizeInPoints s
157158 Left msg -> do
158− lift $ P.warning $ "Could not determine image size in `" ++
159− src ++ "': " ++ msg
159+ report $ CouldNotDetermineImageSize src msg
160160 return (100, 100)
161161 let dims =
162162 case (getDim Width, getDim Height) of
src/Text/Pandoc/Writers/RTF.hs+7−8
@@ -37,7 +37,7 @@ import Text.Pandoc.Writers.Shared
3737import Text.Pandoc.Writers.Math
3838import Text.Pandoc.Templates (renderTemplate')
3939import Text.Pandoc.Walk
40−import Text.Pandoc.Class (warning)
40+import Text.Pandoc.Logging
4141import Data.List ( isSuffixOf, intercalate )
4242import Data.Char ( ord, chr, isDigit )
4343import qualified Data.ByteString as B
@@ -46,7 +46,7 @@ import Text.Printf ( printf )
4646import Text.Pandoc.ImageSize
4747import Control.Monad.Except (throwError, runExceptT, lift)
4848import Text.Pandoc.Error
49−import Text.Pandoc.Class (PandocMonad)
49+import Text.Pandoc.Class (PandocMonad, report)
5050import qualified Text.Pandoc.Class as P
5151
5252-- | Convert Image inlines into a raw RTF embedded image, read from a file,
@@ -65,8 +65,7 @@ rtfEmbedImage opts x@(Image attr _ (src,_)) = do
6565 _ -> throwError $ PandocSomeError "Unknown file type"
6666 sizeSpec <- case imageSize imgdata of
6767 Left msg -> do
68− warning $ "Could not determine image size in `" ++
69− src ++ "': " ++ msg
68+ report $ CouldNotDetermineImageSize src msg
7069 return ""
7170 Right sz -> return $ "\\picw" ++ show xpx ++
7271 "\\pich" ++ show ypx ++
@@ -79,17 +78,17 @@ rtfEmbedImage opts x@(Image attr _ (src,_)) = do
7978 concat bytes ++ "}"
8079 if B.null imgdata
8180 then do
82− warning $ "Image " ++ src ++ " contained no data, skipping."
81+ report $ CouldNotFetchResource src "image contained no data"
8382 return x
8483 else return $ RawInline (Format "rtf") raw
8584 | otherwise -> do
86− warning $ "Image " ++ src ++ " is not a jpeg or png, skipping."
85+ report $ CouldNotFetchResource src "image is not a jpeg or png"
8786 return x
8887 Right (_, Nothing) -> do
89− warning $ "Could not determine image type for " ++ src ++ ", skipping."
88+ report $ CouldNotDetermineMimeType src
9089 return x
9190 Left ( e :: PandocError ) -> do
92− warning $ "Could not fetch image " ++ src ++ "\n" ++ show e
91+ report $ CouldNotFetchResource src (show e)
9392 return x
9493rtfEmbedImage _ x = return x
9594
test/Tests/Readers/Docx.hs+1−1
@@ -61,7 +61,7 @@ testForWarningsWithOptsIO :: ReaderOptions -> String -> FilePath -> [String] ->
6161testForWarningsWithOptsIO opts name docxFile expected = do
6262 df <- B.readFile docxFile
6363 logs <- runIOorExplode (readDocx opts df >> P.getLog)
64− let warns = [s | (WARNING, s) <- logs]
64+ let warns = [m | DocxParserWarning m <- logs]
6565 return $ test id name (unlines warns, unlines expected)
6666
6767testForWarningsWithOpts :: ReaderOptions -> String -> FilePath -> [String] -> Test