git.iko.soy/typeable/pandoc
on master help sign in
Use new warnings throughout the code base.
76c5546John MacFarlane
src/Text/Pandoc/App.hs+1−2
@@ -348,8 +348,7 @@ convertWithOpts opts = do
348 x <- f
348 x <- f
349 rs <- getLog
349 rs <- getLog
350 return (x, rs)
350 return (x, rs)
351− let isWarning (WARNING, _) = True
351+ let isWarning msg = messageVerbosity msg == WARNING
352− isWarning _ = False
353 when (optFailIfWarnings opts && any isWarning reports) $
352 when (optFailIfWarnings opts && any isWarning reports) $
354 err 3 "Failing because there were warnings."
353 err 3 "Failing because there were warnings."
355 return res
354 return res
src/Text/Pandoc/Class.hs+21−32
@@ -41,8 +41,6 @@ module Text.Pandoc.Class ( PandocMonad(..)
41 , getPOSIXTime
41 , getPOSIXTime
42 , getZonedTime
42 , getZonedTime
43 , readFileFromDirs
43 , readFileFromDirs
44− , warning
45− , warningWithPos
46 , report
44 , report
47 , getLog
45 , getLog
48 , setVerbosity
46 , setVerbosity
@@ -73,7 +71,7 @@ import qualified Text.Pandoc.Shared as IO ( readDataFile
73import qualified Text.Pandoc.UTF8 as UTF8
71import qualified Text.Pandoc.UTF8 as UTF8
74import Text.Pandoc.Compat.Time (UTCTime)
72import Text.Pandoc.Compat.Time (UTCTime)
75import Text.Pandoc.Logging
73import Text.Pandoc.Logging
76−import Text.Parsec (ParsecT, SourcePos)
74+import Text.Parsec (ParsecT)
77import qualified Text.Pandoc.Compat.Time as IO (getCurrentTime)
75import qualified Text.Pandoc.Compat.Time as IO (getCurrentTime)
78import Text.Pandoc.MIME (MimeType, getMimeType)
76import Text.Pandoc.MIME (MimeType, getMimeType)
79import Data.Time.Clock.POSIX ( utcTimeToPOSIXSeconds
77import Data.Time.Clock.POSIX ( utcTimeToPOSIXSeconds
@@ -131,7 +129,7 @@ class (Functor m, Applicative m, Monad m, MonadError PandocError m)
131 modifyCommonState :: (CommonState -> CommonState) -> m ()
129 modifyCommonState :: (CommonState -> CommonState) -> m ()
132 modifyCommonState f = getCommonState >>= putCommonState . f
130 modifyCommonState f = getCommonState >>= putCommonState . f
133
131
134− logOutput :: Verbosity -> String -> m ()
132+ logOutput :: LogMessage -> m ()
135
133
136-- Functions defined for all PandocMonad instances
134-- Functions defined for all PandocMonad instances
137
135
@@ -139,25 +137,17 @@ setVerbosity :: PandocMonad m => Verbosity -> m ()
139setVerbosity verbosity =
137setVerbosity verbosity =
140 modifyCommonState $ \st -> st{ stVerbosity = verbosity }
138 modifyCommonState $ \st -> st{ stVerbosity = verbosity }
141
139
142−getLog :: PandocMonad m => m [(Verbosity, String)]
140+getLog :: PandocMonad m => m [LogMessage]
143getLog = reverse <$> getsCommonState stLog
141getLog = reverse <$> getsCommonState stLog
144
142
145−warning :: PandocMonad m => String -> m ()
146−warning msg = report WARNING msg
147−
148−warningWithPos :: PandocMonad m
143+report :: PandocMonad m => LogMessage -> 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
144+report msg = do
156 verbosity <- getsCommonState stVerbosity
145 verbosity <- getsCommonState stVerbosity
146+ let level = messageVerbosity msg
157 when (level <= verbosity) $ do
147 when (level <= verbosity) $ do
158− logOutput verbosity msg
148+ logOutput msg
159 unless (level == DEBUG) $
149 unless (level == DEBUG) $
160− modifyCommonState $ \st -> st{ stLog = (level, msg) : stLog st }
150+ modifyCommonState $ \st -> st{ stLog = msg : stLog st }
161
151
162setMediaBag :: PandocMonad m => MediaBag -> m ()
152setMediaBag :: PandocMonad m => MediaBag -> m ()
163setMediaBag mb = modifyCommonState $ \st -> st{stMediaBag = mb}
153setMediaBag mb = modifyCommonState $ \st -> st{stMediaBag = mb}
@@ -187,17 +177,15 @@ getZonedTime = do
187 return $ utcToZonedTime tz t
177 return $ utcToZonedTime tz t
188
178
189-- | Read file, checking in any number of directories.
179-- | Read file, checking in any number of directories.
190−readFileFromDirs :: PandocMonad m => [FilePath] -> FilePath -> m String
180+readFileFromDirs :: PandocMonad m => [FilePath] -> FilePath -> m (Maybe String)
191−readFileFromDirs [] f = do
181+readFileFromDirs [] _ = return Nothing
192− warning $ "Could not load include file " ++ f ++ ", skipping."
193− return ""
194readFileFromDirs (d:ds) f = catchError
182readFileFromDirs (d:ds) f = catchError
195− (UTF8.toStringLazy <$> readFileLazy (d </> f))
183+ ((Just . UTF8.toStringLazy) <$> readFileLazy (d </> f))
196 (\_ -> readFileFromDirs ds f)
184 (\_ -> readFileFromDirs ds f)
197
185
198--
186--
199
187
200−data CommonState = CommonState { stLog :: [(Verbosity, String)]
188+data CommonState = CommonState { stLog :: [LogMessage]
201 , stMediaBag :: MediaBag
189 , stMediaBag :: MediaBag
202 , stInputFiles :: Maybe [FilePath]
190 , stInputFiles :: Maybe [FilePath]
203 , stOutputFile :: Maybe FilePath
191 , stOutputFile :: Maybe FilePath
@@ -266,8 +254,9 @@ instance PandocMonad PandocIO where
266 Left _ -> throwError $ PandocFileReadError fp
254 Left _ -> throwError $ PandocFileReadError fp
267 getCommonState = PandocIO $ lift get
255 getCommonState = PandocIO $ lift get
268 putCommonState x = PandocIO $ lift $ put x
256 putCommonState x = PandocIO $ lift $ put x
269− logOutput level msg =
257+ logOutput msg =
270− liftIO $ UTF8.hPutStrLn stderr $ printf "%-7s %s" (show level) msg
258+ liftIO $ UTF8.hPutStrLn stderr $ printf "%-7s %s"
259+ (show (messageVerbosity msg)) (showLogMessage msg)
271
260
272-- | Specialized version of parseURIReference that disallows
261-- | Specialized version of parseURIReference that disallows
273-- single-letter schemes. Reason: these are usually windows absolute
262-- single-letter schemes. Reason: these are usually windows absolute
@@ -466,7 +455,7 @@ instance PandocMonad PandocPure where
466 getCommonState = PandocPure $ lift $ get
455 getCommonState = PandocPure $ lift $ get
467 putCommonState x = PandocPure $ lift $ put x
456 putCommonState x = PandocPure $ lift $ put x
468
457
469− logOutput _level _msg = return ()
458+ logOutput _msg = return ()
470
459
471instance PandocMonad m => PandocMonad (ParsecT s st m) where
460instance PandocMonad m => PandocMonad (ParsecT s st m) where
472 lookupEnv = lift . lookupEnv
461 lookupEnv = lift . lookupEnv
@@ -482,7 +471,7 @@ instance PandocMonad m => PandocMonad (ParsecT s st m) where
482 getModificationTime = lift . getModificationTime
471 getModificationTime = lift . getModificationTime
483 getCommonState = lift getCommonState
472 getCommonState = lift getCommonState
484 putCommonState = lift . putCommonState
473 putCommonState = lift . putCommonState
485− logOutput lvl = lift . logOutput lvl
474+ logOutput = lift . logOutput
486
475
487instance PandocMonad m => PandocMonad (ReaderT r m) where
476instance PandocMonad m => PandocMonad (ReaderT r m) where
488 lookupEnv = lift . lookupEnv
477 lookupEnv = lift . lookupEnv
@@ -498,7 +487,7 @@ instance PandocMonad m => PandocMonad (ReaderT r m) where
498 getModificationTime = lift . getModificationTime
487 getModificationTime = lift . getModificationTime
499 getCommonState = lift getCommonState
488 getCommonState = lift getCommonState
500 putCommonState = lift . putCommonState
489 putCommonState = lift . putCommonState
501− logOutput lvl = lift . logOutput lvl
490+ logOutput = lift . logOutput
502
491
503instance (PandocMonad m, Monoid w) => PandocMonad (WriterT w m) where
492instance (PandocMonad m, Monoid w) => PandocMonad (WriterT w m) where
504 lookupEnv = lift . lookupEnv
493 lookupEnv = lift . lookupEnv
@@ -514,7 +503,7 @@ instance (PandocMonad m, Monoid w) => PandocMonad (WriterT w m) where
514 getModificationTime = lift . getModificationTime
503 getModificationTime = lift . getModificationTime
515 getCommonState = lift getCommonState
504 getCommonState = lift getCommonState
516 putCommonState = lift . putCommonState
505 putCommonState = lift . putCommonState
517− logOutput lvl = lift . logOutput lvl
506+ logOutput = lift . logOutput
518
507
519instance (PandocMonad m, Monoid w) => PandocMonad (RWST r w st m) where
508instance (PandocMonad m, Monoid w) => PandocMonad (RWST r w st m) where
520 lookupEnv = lift . lookupEnv
509 lookupEnv = lift . lookupEnv
@@ -530,7 +519,7 @@ instance (PandocMonad m, Monoid w) => PandocMonad (RWST r w st m) where
530 getModificationTime = lift . getModificationTime
519 getModificationTime = lift . getModificationTime
531 getCommonState = lift getCommonState
520 getCommonState = lift getCommonState
532 putCommonState = lift . putCommonState
521 putCommonState = lift . putCommonState
533− logOutput lvl = lift . logOutput lvl
522+ logOutput = lift . logOutput
534
523
535instance PandocMonad m => PandocMonad (StateT st m) where
524instance PandocMonad m => PandocMonad (StateT st m) where
536 lookupEnv = lift . lookupEnv
525 lookupEnv = lift . lookupEnv
@@ -546,5 +535,5 @@ instance PandocMonad m => PandocMonad (StateT st m) where
546 getModificationTime = lift . getModificationTime
535 getModificationTime = lift . getModificationTime
547 getCommonState = lift getCommonState
536 getCommonState = lift getCommonState
548 putCommonState = lift . putCommonState
537 putCommonState = lift . putCommonState
549− logOutput lvl = lift . logOutput lvl
538+ logOutput = lift . logOutput
550
539
src/Text/Pandoc/Logging.hs+74−31
@@ -52,31 +52,35 @@ instance ToJSON Verbosity where
52 toJSON x = toJSON (show x)
52 toJSON x = toJSON (show x)
53
53
54data LogMessage =
54data LogMessage =
55− SkippedInput String SourcePos
55+ SkippedContent String SourcePos
56− | YamlSectionNotAnObject SourcePos
56+ | CouldNotParseYamlMetadata String SourcePos
57 | DuplicateLinkReference String SourcePos
57 | DuplicateLinkReference String SourcePos
58 | DuplicateNoteReference String SourcePos
58 | DuplicateNoteReference String SourcePos
59+ | ReferenceNotFound String SourcePos
59 | ParsingUnescaped String SourcePos
60 | ParsingUnescaped String SourcePos
61+ | CouldNotLoadIncludeFile String SourcePos
62+ | ParsingTrace String SourcePos
60 | InlineNotRendered Inline
63 | InlineNotRendered Inline
61 | BlockNotRendered Block
64 | BlockNotRendered Block
62− | DocxCommentWillNotRetainFormatting String
65+ | DocxParserWarning String
63 | CouldNotFetchResource String String
66 | CouldNotFetchResource String String
64− | CouldNotDetermineImageSize String
67+ | CouldNotDetermineImageSize String String
65 | CouldNotDetermineMimeType String
68 | CouldNotDetermineMimeType String
66− | CouldNotConvertTeXMath String
69+ | CouldNotConvertTeXMath String String
67 deriving (Show, Eq, Data, Ord, Typeable, Generic)
70 deriving (Show, Eq, Data, Ord, Typeable, Generic)
68
71
69instance ToJSON LogMessage where
72instance ToJSON LogMessage where
70 toJSON x = object $ "verbosity" .= toJSON (messageVerbosity x) :
73 toJSON x = object $ "verbosity" .= toJSON (messageVerbosity x) :
71 case x of
74 case x of
72− SkippedInput s pos ->
75+ SkippedContent s pos ->
73− ["type" .= String "SkippedInput",
76+ ["type" .= String "SkippedContent",
74 "contents" .= Text.pack s,
77 "contents" .= Text.pack s,
75 "source" .= Text.pack (sourceName pos),
78 "source" .= Text.pack (sourceName pos),
76 "line" .= sourceLine pos,
79 "line" .= sourceLine pos,
77 "column" .= sourceColumn pos]
80 "column" .= sourceColumn pos]
78− YamlSectionNotAnObject pos ->
81+ CouldNotParseYamlMetadata s pos ->
79 ["type" .= String "YamlSectionNotAnObject",
82 ["type" .= String "YamlSectionNotAnObject",
83+ "message" .= Text.pack s,
80 "source" .= Text.pack (sourceName pos),
84 "source" .= Text.pack (sourceName pos),
81 "line" .= toJSON (sourceLine pos),
85 "line" .= toJSON (sourceLine pos),
82 "column" .= toJSON (sourceColumn pos)]
86 "column" .= toJSON (sourceColumn pos)]
@@ -92,75 +96,114 @@ instance ToJSON LogMessage where
92 "source" .= Text.pack (sourceName pos),
96 "source" .= Text.pack (sourceName pos),
93 "line" .= toJSON (sourceLine pos),
97 "line" .= toJSON (sourceLine pos),
94 "column" .= toJSON (sourceColumn pos)]
98 "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)]
95 ParsingUnescaped s pos ->
105 ParsingUnescaped s pos ->
96 ["type" .= String "ParsingUnescaped",
106 ["type" .= String "ParsingUnescaped",
97 "contents" .= Text.pack s,
107 "contents" .= Text.pack s,
98 "source" .= Text.pack (sourceName pos),
108 "source" .= Text.pack (sourceName pos),
99 "line" .= toJSON (sourceLine pos),
109 "line" .= toJSON (sourceLine pos),
100 "column" .= toJSON (sourceColumn pos)]
110 "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]
101 InlineNotRendered il ->
123 InlineNotRendered il ->
102 ["type" .= String "InlineNotRendered",
124 ["type" .= String "InlineNotRendered",
103 "contents" .= toJSON il]
125 "contents" .= toJSON il]
104 BlockNotRendered bl ->
126 BlockNotRendered bl ->
105 ["type" .= String "BlockNotRendered",
127 ["type" .= String "BlockNotRendered",
106 "contents" .= toJSON bl]
128 "contents" .= toJSON bl]
107− DocxCommentWillNotRetainFormatting s ->
129+ DocxParserWarning s ->
108− ["type" .= String "DocxCommentWillNotRetainFormatting",
130+ ["type" .= String "DocxParserWarning",
109− "commentId" .= Text.pack s]
131+ "contents" .= Text.pack s]
110 CouldNotFetchResource fp s ->
132 CouldNotFetchResource fp s ->
111 ["type" .= String "CouldNotFetchResource",
133 ["type" .= String "CouldNotFetchResource",
112 "path" .= Text.pack fp,
134 "path" .= Text.pack fp,
113 "message" .= Text.pack s]
135 "message" .= Text.pack s]
114− CouldNotDetermineImageSize fp ->
136+ CouldNotDetermineImageSize fp s ->
115 ["type" .= String "CouldNotDetermineImageSize",
137 ["type" .= String "CouldNotDetermineImageSize",
116− "path" .= Text.pack fp]
138+ "path" .= Text.pack fp,
139+ "message" .= Text.pack s]
117 CouldNotDetermineMimeType fp ->
140 CouldNotDetermineMimeType fp ->
118 ["type" .= String "CouldNotDetermineMimeType",
141 ["type" .= String "CouldNotDetermineMimeType",
119 "path" .= Text.pack fp]
142 "path" .= Text.pack fp]
120− CouldNotConvertTeXMath s ->
143+ CouldNotConvertTeXMath s msg ->
121 ["type" .= String "CouldNotConvertTeXMath",
144 ["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 ++ " "
123
154
124showLogMessage :: LogMessage -> String
155showLogMessage :: LogMessage -> String
125showLogMessage msg =
156showLogMessage msg =
126 case msg of
157 case msg of
127− SkippedInput s pos ->
158+ SkippedContent s pos ->
128− "Skipped '" ++ s ++ "' at " ++ show pos
159+ "Skipped '" ++ s ++ "' at " ++ showPos pos
129− YamlSectionNotAnObject pos ->
160+ CouldNotParseYamlMetadata s pos ->
130− "YAML metadata section is not an object at " ++ show pos
161+ "Could not parse YAML metadata at " ++ showPos pos ++
162+ if null s then "" else (": " ++ s)
131 DuplicateLinkReference s pos ->
163 DuplicateLinkReference s pos ->
132− "Duplicate link reference '" ++ s ++ "' at " ++ show pos
164+ "Duplicate link reference '" ++ s ++ "' at " ++ showPos pos
133 DuplicateNoteReference s pos ->
165 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
135 ParsingUnescaped s pos ->
169 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
137 InlineNotRendered il ->
175 InlineNotRendered il ->
138 "Not rendering " ++ show il
176 "Not rendering " ++ show il
139 BlockNotRendered bl ->
177 BlockNotRendered bl ->
140 "Not rendering " ++ show bl
178 "Not rendering " ++ show bl
141− DocxCommentWillNotRetainFormatting s ->
179+ DocxParserWarning s ->
142− "Docx comment with id '" ++ s ++ "' will not retain formatting"
180+ "Docx parser warning: " ++ s
143 CouldNotFetchResource fp s ->
181 CouldNotFetchResource fp s ->
144 "Could not fetch resource '" ++ fp ++ "'" ++
182 "Could not fetch resource '" ++ fp ++ "'" ++
145 if null s then "" else (": " ++ s)
183 if null s then "" else (": " ++ s)
146− CouldNotDetermineImageSize fp ->
184+ CouldNotDetermineImageSize fp s ->
147− "Could not determine image size for '" ++ fp ++ "'"
185+ "Could not determine image size for '" ++ fp ++ "'" ++
186+ if null s then "" else (": " ++ s)
148 CouldNotDetermineMimeType fp ->
187 CouldNotDetermineMimeType fp ->
149 "Could not determine mime type for '" ++ fp ++ "'"
188 "Could not determine mime type for '" ++ fp ++ "'"
150− CouldNotConvertTeXMath s ->
189+ CouldNotConvertTeXMath s m ->
151− "Could not convert TeX math '" ++ s ++ "', rendering as TeX"
190+ "Could not convert TeX math '" ++ s ++ "', rendering as TeX" ++
191+ if null m then "" else (':':'\n':m)
152
192
153messageVerbosity:: LogMessage -> Verbosity
193messageVerbosity:: LogMessage -> Verbosity
154messageVerbosity msg =
194messageVerbosity msg =
155 case msg of
195 case msg of
156− SkippedInput{} -> INFO
196+ SkippedContent{} -> INFO
157− YamlSectionNotAnObject{} -> WARNING
197+ CouldNotParseYamlMetadata{} -> WARNING
158 DuplicateLinkReference{} -> WARNING
198 DuplicateLinkReference{} -> WARNING
159 DuplicateNoteReference{} -> WARNING
199 DuplicateNoteReference{} -> WARNING
200+ ReferenceNotFound{} -> WARNING
201+ CouldNotLoadIncludeFile{} -> WARNING
160 ParsingUnescaped{} -> INFO
202 ParsingUnescaped{} -> INFO
203+ ParsingTrace{} -> DEBUG
161 InlineNotRendered{} -> INFO
204 InlineNotRendered{} -> INFO
162 BlockNotRendered{} -> INFO
205 BlockNotRendered{} -> INFO
163− DocxCommentWillNotRetainFormatting{} -> INFO
206+ DocxParserWarning{} -> WARNING
164 CouldNotFetchResource{} -> WARNING
207 CouldNotFetchResource{} -> WARNING
165 CouldNotDetermineImageSize{} -> WARNING
208 CouldNotDetermineImageSize{} -> WARNING
166 CouldNotDetermineMimeType{} -> WARNING
209 CouldNotDetermineMimeType{} -> WARNING
src/Text/Pandoc/Parsing.hs+8−2
@@ -188,7 +188,8 @@ import Text.TeXMath.Readers.TeX.Macros (applyMacros, Macro,
188import Text.HTML.TagSoup.Entity ( lookupEntity )
188import Text.HTML.TagSoup.Entity ( lookupEntity )
189import Text.Pandoc.Asciify (toAsciiChar)
189import Text.Pandoc.Asciify (toAsciiChar)
190import Data.Monoid ((<>))
190import Data.Monoid ((<>))
191−import Text.Pandoc.Class (PandocMonad, readFileFromDirs)
191+import Text.Pandoc.Class (PandocMonad, readFileFromDirs, report)
192+import Text.Pandoc.Logging
192import Data.Default
193import Data.Default
193import qualified Data.Set as Set
194import qualified Data.Set as Set
194import Control.Monad.Reader
195import Control.Monad.Reader
@@ -1289,7 +1290,12 @@ insertIncludedFile blocks dirs f = do
1289 when (f `elem` containers) $
1290 when (f `elem` containers) $
1290 throwError $ PandocParseError $ "Include file loop at " ++ show oldPos
1291 throwError $ PandocParseError $ "Include file loop at " ++ show oldPos
1291 updateState $ \s -> s{ stateContainers = f : stateContainers s }
1292 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 ""
1293 setPosition $ newPos f 1 1
1299 setPosition $ newPos f 1 1
1294 setInput contents
1300 setInput contents
1295 bs <- blocks
1301 bs <- blocks
src/Text/Pandoc/Readers/Docx.hs+6−3
@@ -100,6 +100,7 @@ import Text.Pandoc.Error
100import Control.Monad.Except (throwError)
100import Control.Monad.Except (throwError)
101import Text.Pandoc.Class (PandocMonad)
101import Text.Pandoc.Class (PandocMonad)
102import qualified Text.Pandoc.Class as P
102import qualified Text.Pandoc.Class as P
103+import Text.Pandoc.Logging
103
104
104readDocx :: PandocMonad m
105readDocx :: PandocMonad m
105 => ReaderOptions
106 => ReaderOptions
@@ -108,12 +109,13 @@ readDocx :: PandocMonad m
108readDocx opts bytes
109readDocx opts bytes
109 | Right archive <- toArchiveOrFail bytes
110 | Right archive <- toArchiveOrFail bytes
110 , Right (docx, parserWarnings) <- archiveToDocxWithWarnings archive = do
111 , Right (docx, parserWarnings) <- archiveToDocxWithWarnings archive = do
111− mapM_ P.warning parserWarnings
112+ mapM_ (P.report . DocxParserWarning) parserWarnings
112 (meta, blks) <- docxToOutput opts docx
113 (meta, blks) <- docxToOutput opts docx
113 return $ Pandoc meta blks
114 return $ Pandoc meta blks
114readDocx _ _ =
115readDocx _ _ =
115 throwError $ PandocSomeError "couldn't parse docx file"
116 throwError $ PandocSomeError "couldn't parse docx file"
116
117
118+-- TODO remove this for 2.0:
117readDocxWithWarnings :: PandocMonad m
119readDocxWithWarnings :: PandocMonad m
118 => ReaderOptions
120 => ReaderOptions
119 -> B.ByteString
121 -> B.ByteString
@@ -333,8 +335,9 @@ blocksToInlinesWarn cmtId blks = do
333 notParaOrPlain (Para _) = False
335 notParaOrPlain (Para _) = False
334 notParaOrPlain (Plain _) = False
336 notParaOrPlain (Plain _) = False
335 notParaOrPlain _ = True
337 notParaOrPlain _ = True
336− when (not $ null $ filter notParaOrPlain blkList)
338+ when (not $ null $ filter notParaOrPlain blkList) $
339+ lift $ P.report $ DocxParserWarning $
337− ((lift . lift) $ P.warning $ "Docx comment " ++ cmtId ++ " will not retain formatting")
340+ "Docx comment " ++ cmtId ++ " will not retain formatting"
338 return $ fromList $ blocksToInlines blkList
341 return $ fromList $ blocksToInlines blkList
339
342
340parPartToInlines :: PandocMonad m => ParPart -> DocxContext m Inlines
343parPartToInlines :: PandocMonad m => ParPart -> DocxContext m Inlines
src/Text/Pandoc/Readers/EPUB.hs+1−3
@@ -13,7 +13,6 @@ import Text.Pandoc.Definition hiding (Attr)
13import Text.Pandoc.Readers.HTML (readHtml)
13import Text.Pandoc.Readers.HTML (readHtml)
14import Text.Pandoc.Walk (walk, query)
14import Text.Pandoc.Walk (walk, query)
15import Text.Pandoc.Options ( ReaderOptions(..))
15import Text.Pandoc.Options ( ReaderOptions(..))
16−import Text.Pandoc.Logging (Verbosity(..))
17import Text.Pandoc.Extensions (enableExtension, Extension(Ext_raw_html))
16import Text.Pandoc.Extensions (enableExtension, Extension(Ext_raw_html))
18import Text.Pandoc.Shared (escapeURI, collapseFilePath, addMetaField)
17import Text.Pandoc.Shared (escapeURI, collapseFilePath, addMetaField)
19import Network.URI (unEscapeString)
18import Network.URI (unEscapeString)
@@ -35,7 +34,7 @@ import qualified Data.Map as M (Map, lookup, fromList, elems)
35import Data.Monoid ((<>))
34import Data.Monoid ((<>))
36import Control.DeepSeq (deepseq, NFData)
35import Control.DeepSeq (deepseq, NFData)
37import Text.Pandoc.Error
36import Text.Pandoc.Error
38−import Text.Pandoc.Class (PandocMonad, report)
37+import Text.Pandoc.Class (PandocMonad)
39import qualified Text.Pandoc.Class as P
38import qualified Text.Pandoc.Class as P
40
39
41type Items = M.Map String (FilePath, MimeType)
40type Items = M.Map String (FilePath, MimeType)
@@ -71,7 +70,6 @@ archiveToEPUB os archive = do
71 os' = os {readerExtensions = enableExtension Ext_raw_html (readerExtensions os)}
70 os' = os {readerExtensions = enableExtension Ext_raw_html (readerExtensions os)}
72 parseSpineElem :: PandocMonad m => FilePath -> (FilePath, MimeType) -> m Pandoc
71 parseSpineElem :: PandocMonad m => FilePath -> (FilePath, MimeType) -> m Pandoc
73 parseSpineElem (normalise -> r) (normalise -> path, mime) = do
72 parseSpineElem (normalise -> r) (normalise -> path, mime) = do
74− report DEBUG ("parseSpineElem called with path " ++ show path)
75 doc <- mimeToReader mime r path
73 doc <- mimeToReader mime r path
76 let docSpan = B.doc $ B.para $ B.spanWith (takeFileName path, [], []) mempty
74 let docSpan = B.doc $ B.para $ B.spanWith (takeFileName path, [], []) mempty
77 return $ docSpan <> doc
75 return $ docSpan <> doc
src/Text/Pandoc/Readers/HTML.hs+4−6
@@ -48,7 +48,7 @@ import Text.Pandoc.Shared ( extractSpaces, renderTags', addMetaField
48import Text.Pandoc.Options (ReaderOptions(readerExtensions), extensionEnabled,
48import Text.Pandoc.Options (ReaderOptions(readerExtensions), extensionEnabled,
49 Extension (Ext_epub_html_exts,
49 Extension (Ext_epub_html_exts,
50 Ext_raw_html, Ext_native_divs, Ext_native_spans))
50 Ext_raw_html, Ext_native_divs, Ext_native_spans))
51−import Text.Pandoc.Logging (Verbosity(..))
51+import Text.Pandoc.Logging
52import Text.Pandoc.Parsing hiding ((<|>))
52import Text.Pandoc.Parsing hiding ((<|>))
53import Text.Pandoc.Walk
53import Text.Pandoc.Walk
54import qualified Data.Map as M
54import qualified Data.Map as M
@@ -59,7 +59,6 @@ import Control.Monad ( guard, mzero, void, unless )
59import Control.Arrow ((***))
59import Control.Arrow ((***))
60import Control.Applicative ( (<|>) )
60import Control.Applicative ( (<|>) )
61import Data.Monoid (First (..))
61import Data.Monoid (First (..))
62−import Text.Printf (printf)
63import Text.TeXMath (readMathML, writeTeX)
62import Text.TeXMath (readMathML, writeTeX)
64import Data.Default (Default (..), def)
63import Data.Default (Default (..), def)
65import Control.Monad.Reader (ask, asks, local, ReaderT, runReaderT, lift)
64import Control.Monad.Reader (ask, asks, local, ReaderT, runReaderT, lift)
@@ -69,7 +68,7 @@ import Data.Monoid ((<>))
69import Text.Parsec.Error
68import Text.Parsec.Error
70import qualified Data.Set as Set
69import qualified Data.Set as Set
71import Text.Pandoc.Error
70import Text.Pandoc.Error
72−import Text.Pandoc.Class (PandocMonad, report, warningWithPos)
71+import Text.Pandoc.Class (PandocMonad, report)
73import Control.Monad.Except (throwError)
72import Control.Monad.Except (throwError)
74
73
75-- | Convert HTML-formatted string to 'Pandoc' document.
74-- | Convert HTML-formatted string to 'Pandoc' document.
@@ -177,8 +176,7 @@ block = do
177 , pPlain
176 , pPlain
178 , pRawHtmlBlock
177 , pRawHtmlBlock
179 ]
178 ]
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
182 return res
180 return res
183
181
184namespaces :: PandocMonad m => [(String, TagParser m Inlines)]
182namespaces :: PandocMonad m => [(String, TagParser m Inlines)]
@@ -378,7 +376,7 @@ ignore raw = do
378 -- raw can be null for tags like <!DOCTYPE>; see paRawTag
376 -- raw can be null for tags like <!DOCTYPE>; see paRawTag
379 -- in this case we don't want a warning:
377 -- in this case we don't want a warning:
380 unless (null raw) $
378 unless (null raw) $
381− warningWithPos pos $ "Skipped " ++ raw
379+ report $ SkippedContent raw pos
382 return mempty
380 return mempty
383
381
384pHtmlBlock :: PandocMonad m => String -> TagParser m String
382pHtmlBlock :: PandocMonad m => String -> TagParser m String
src/Text/Pandoc/Readers/LaTeX.hs+13−6
@@ -38,6 +38,7 @@ import Text.Pandoc.Definition
38import Text.Pandoc.Walk
38import Text.Pandoc.Walk
39import Text.Pandoc.Shared
39import Text.Pandoc.Shared
40import Text.Pandoc.Options
40import Text.Pandoc.Options
41+import Text.Pandoc.Logging
41import Text.Pandoc.Parsing hiding ((<|>), many, optional, space,
42import Text.Pandoc.Parsing hiding ((<|>), many, optional, space,
42 mathDisplay, mathInline)
43 mathDisplay, mathInline)
43import Data.Char ( chr, ord, isLetter, isAlphaNum )
44import Data.Char ( chr, ord, isLetter, isAlphaNum )
@@ -51,7 +52,7 @@ import qualified Data.Map as M
51import Text.Pandoc.Highlighting (fromListingsLanguage, languagesByExtension)
52import Text.Pandoc.Highlighting (fromListingsLanguage, languagesByExtension)
52import Text.Pandoc.ImageSize (numUnit, showFl)
53import Text.Pandoc.ImageSize (numUnit, showFl)
53import Control.Monad.Except (throwError)
54import Control.Monad.Except (throwError)
54−import Text.Pandoc.Class (PandocMonad, PandocPure, lookupEnv, warningWithPos,
55+import Text.Pandoc.Class (PandocMonad, PandocPure, lookupEnv, report,
55 readFileFromDirs)
56 readFileFromDirs)
56
57
57-- | Parse LaTeX from string and return 'Pandoc' document.
58-- | Parse LaTeX from string and return 'Pandoc' document.
@@ -235,7 +236,7 @@ inline = (mempty <$ comment)
235 <|> (str . (:[]) <$> tildeEscape)
236 <|> (str . (:[]) <$> tildeEscape)
236 <|> (do res <- oneOf "#&~^'`\"[]"
237 <|> (do res <- oneOf "#&~^'`\"[]"
237 pos <- getPosition
238 pos <- getPosition
238− warningWithPos pos ("Parsing unescaped '" ++ [res] ++ "'")
239+ report $ ParsingUnescaped [res] pos
239 return $ str [res])
240 return $ str [res])
240
241
241inlines :: PandocMonad m => LP m Inlines
242inlines :: PandocMonad m => LP m Inlines
@@ -312,7 +313,7 @@ optargs = snd <$> withRaw (skipopts *> skipMany (try $ optional sp *> braced))
312ignore :: (Monoid a, PandocMonad m) => String -> ParserT s u m a
313ignore :: (Monoid a, PandocMonad m) => String -> ParserT s u m a
313ignore raw = do
314ignore raw = do
314 pos <- getPosition
315 pos <- getPosition
315− warningWithPos pos $ "Skipped " ++ raw
316+ report $ SkippedContent raw pos
316 return mempty
317 return mempty
317
318
318ignoreBlocks :: PandocMonad m => String -> (String, LP m Blocks)
319ignoreBlocks :: PandocMonad m => String -> (String, LP m Blocks)
@@ -943,14 +944,14 @@ rawEnv name = do
943 let beginCommand = "\\begin{" ++ name ++ "}" ++ rawOptions
944 let beginCommand = "\\begin{" ++ name ++ "}" ++ rawOptions
944 unless parseRaw $ do
945 unless parseRaw $ do
945 pos1 <- getPosition
946 pos1 <- getPosition
946− warningWithPos pos1 $ "Skipped " ++ beginCommand
947+ report $ SkippedContent beginCommand pos1
947 (bs, raw) <- withRaw $ env name blocks
948 (bs, raw) <- withRaw $ env name blocks
948 raw' <- applyMacros' raw
949 raw' <- applyMacros' raw
949 if parseRaw
950 if parseRaw
950 then return $ rawBlock "latex" $ beginCommand ++ raw'
951 then return $ rawBlock "latex" $ beginCommand ++ raw'
951 else do
952 else do
952 pos2 <- getPosition
953 pos2 <- getPosition
953− warningWithPos pos2 $ "Skipped \\end{" ++ name ++ "}"
954+ report $ SkippedContent ("\\end{" ++ name ++ "}") pos2
954 return bs
955 return bs
955
956
956----
957----
@@ -982,10 +983,16 @@ include = do
982
983
983inputListing :: PandocMonad m => LP m Blocks
984inputListing :: PandocMonad m => LP m Blocks
984inputListing = do
985inputListing = do
986+ pos <- getPosition
985 options <- option [] keyvals
987 options <- option [] keyvals
986 f <- filter (/='"') <$> braced
988 f <- filter (/='"') <$> braced
987 dirs <- (splitBy (==':') . fromMaybe ".") <$> lookupEnv "TEXINPUTS"
989 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 []
989 let (ident,classes,kvs) = parseListingsOptions options
996 let (ident,classes,kvs) = parseListingsOptions options
990 let language = case lookup "language" options >>= fromListingsLanguage of
997 let language = case lookup "language" options >>= fromListingsLanguage of
991 Just l -> [l]
998 Just l -> [l]
src/Text/Pandoc/Readers/Markdown.hs+11−14
@@ -51,7 +51,7 @@ import qualified Text.Pandoc.UTF8 as UTF8
51import qualified Data.Vector as V
51import qualified Data.Vector as V
52import Text.Pandoc.Builder (Inlines, Blocks, trimInlines)
52import Text.Pandoc.Builder (Inlines, Blocks, trimInlines)
53import Text.Pandoc.Options
53import Text.Pandoc.Options
54−import Text.Pandoc.Logging (Verbosity(..))
54+import Text.Pandoc.Logging
55import Text.Pandoc.Shared
55import Text.Pandoc.Shared
56import Text.Pandoc.Pretty (charWidth)
56import Text.Pandoc.Pretty (charWidth)
57import Text.Pandoc.XML (fromEntities)
57import Text.Pandoc.XML (fromEntities)
@@ -62,12 +62,10 @@ import Text.Pandoc.Readers.HTML ( htmlTag, htmlInBalanced, isInlineTag, isBlockT
62import Control.Monad
62import Control.Monad
63import System.FilePath (takeExtension, addExtension)
63import System.FilePath (takeExtension, addExtension)
64import Text.HTML.TagSoup
64import Text.HTML.TagSoup
65−import Text.Printf (printf)
66import Data.Monoid ((<>))
65import Data.Monoid ((<>))
67import Control.Monad.Trans (lift)
66import Control.Monad.Trans (lift)
68import Control.Monad.Except (throwError, catchError)
67import Control.Monad.Except (throwError, catchError)
69import Text.Pandoc.Class (PandocMonad, report)
68import Text.Pandoc.Class (PandocMonad, report)
70−import qualified Text.Pandoc.Class as P
71
69
72type MarkdownParser m = ParserT [Char] ParserState m
70type MarkdownParser m = ParserT [Char] ParserState m
73
71
@@ -270,7 +268,8 @@ yamlMetaBlock = try $ do
270 ) nullMeta hashmap
268 ) nullMeta hashmap
271 Right Yaml.Null -> return nullMeta
269 Right Yaml.Null -> return nullMeta
272 Right _ -> do
270 Right _ -> do
273− P.warningWithPos pos "YAML header is not an object"
271+ report $ CouldNotParseYamlMetadata "not an object"
272+ pos
274 return nullMeta
273 return nullMeta
275 Left err' -> do
274 Left err' -> do
276 case err' of
275 case err' of
@@ -281,15 +280,13 @@ yamlMetaBlock = try $ do
281 yamlLine = yline
280 yamlLine = yline
282 , yamlColumn = ycol
281 , yamlColumn = ycol
283 }}) ->
282 }}) ->
283+ report $ CouldNotParseYamlMetadata
284− P.warningWithPos (setSourceLine
284+ problem (setSourceLine
285 (setSourceColumn pos
285 (setSourceColumn pos
286 (sourceColumn pos + ycol))
286 (sourceColumn pos + ycol))
287 (sourceLine pos + 1 + yline))
287 (sourceLine pos + 1 + yline))
288− $ "Could not parse YAML header: " ++
288+ _ -> report $ CouldNotParseYamlMetadata
289− problem
290− _ -> P.warningWithPos pos
291− $ "Could not parse YAML header: " ++
292− show err'
289+ (show err') pos
293 return nullMeta
290 return nullMeta
294 updateState $ \st -> st{ stateMeta' = stateMeta' st <> (return meta') }
291 updateState $ \st -> st{ stateMeta' = stateMeta' st <> (return meta') }
295 return mempty
292 return mempty
@@ -406,7 +403,7 @@ referenceKey = try $ do
406 let oldkeys = stateKeys st
403 let oldkeys = stateKeys st
407 let key = toKey raw
404 let key = toKey raw
408 case M.lookup key oldkeys of
405 case M.lookup key oldkeys of
409− Just _ -> P.warningWithPos pos $ "Duplicate link reference `" ++ raw ++ "'"
406+ Just _ -> report $ DuplicateLinkReference raw pos
410 Nothing -> return ()
407 Nothing -> return ()
411 updateState $ \s -> s { stateKeys = M.insert key (target, attr') oldkeys }
408 updateState $ \s -> s { stateKeys = M.insert key (target, attr') oldkeys }
412 return $ return mempty
409 return $ return mempty
@@ -472,7 +469,7 @@ noteBlock = try $ do
472 let newnote = (ref, parsed)
469 let newnote = (ref, parsed)
473 oldnotes <- stateNotes' <$> getState
470 oldnotes <- stateNotes' <$> getState
474 case lookup ref oldnotes of
471 case lookup ref oldnotes of
475− Just _ -> P.warningWithPos pos $ "Duplicate note reference `" ++ ref ++ "'"
472+ Just _ -> report $ DuplicateNoteReference ref pos
476 Nothing -> return ()
473 Nothing -> return ()
477 updateState $ \s -> s { stateNotes' = newnote : oldnotes }
474 updateState $ \s -> s { stateNotes' = newnote : oldnotes }
478 return mempty
475 return mempty
@@ -512,8 +509,8 @@ block = do
512 , para
509 , para
513 , plain
510 , plain
514 ] <?> "block"
511 ] <?> "block"
515− report DEBUG $ printf "line %d: %s" (sourceLine pos)
512+ report $ ParsingTrace
516− (take 60 $ show $ B.toList $ runF res defaultParserState)
513+ (take 60 $ show $ B.toList $ runF res defaultParserState) pos
517 return res
514 return res
518
515
519--
516--
src/Text/Pandoc/Readers/MediaWiki.hs+2−4
@@ -41,7 +41,7 @@ import qualified Text.Pandoc.Builder as B
41import Text.Pandoc.Builder (Inlines, Blocks, trimInlines)
41import Text.Pandoc.Builder (Inlines, Blocks, trimInlines)
42import Data.Monoid ((<>))
42import Data.Monoid ((<>))
43import Text.Pandoc.Options
43import Text.Pandoc.Options
44−import Text.Pandoc.Logging (Verbosity(..))
44+import Text.Pandoc.Logging
45import Text.Pandoc.Readers.HTML ( htmlTag, isBlockTag, isCommentTag )
45import Text.Pandoc.Readers.HTML ( htmlTag, isBlockTag, isCommentTag )
46import Text.Pandoc.XML ( fromEntities )
46import Text.Pandoc.XML ( fromEntities )
47import Text.Pandoc.Parsing hiding ( nested )
47import Text.Pandoc.Parsing hiding ( nested )
@@ -56,7 +56,6 @@ import qualified Data.Map as M
56import qualified Data.Set as Set
56import qualified Data.Set as Set
57import Data.Char (isDigit, isSpace)
57import Data.Char (isDigit, isSpace)
58import Data.Maybe (fromMaybe)
58import Data.Maybe (fromMaybe)
59−import Text.Printf (printf)
60import Control.Monad.Except (throwError)
59import Control.Monad.Except (throwError)
61import Text.Pandoc.Class (PandocMonad, report)
60import Text.Pandoc.Class (PandocMonad, report)
62
61
@@ -207,8 +206,7 @@ block = do
207 <|> blockTag
206 <|> blockTag
208 <|> (B.rawBlock "mediawiki" <$> template)
207 <|> (B.rawBlock "mediawiki" <$> template)
209 <|> para
208 <|> 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
212 return res
210 return res
213
211
214para :: PandocMonad m => MWParser m Blocks
212para :: PandocMonad m => MWParser m Blocks
src/Text/Pandoc/Readers/RST.hs+28−33
@@ -36,6 +36,7 @@ import Text.Pandoc.Builder (setMeta, fromList)
36import Text.Pandoc.Shared
36import Text.Pandoc.Shared
37import Text.Pandoc.Parsing
37import Text.Pandoc.Parsing
38import Text.Pandoc.Options
38import Text.Pandoc.Options
39+import Text.Pandoc.Logging
39import Text.Pandoc.Error
40import Text.Pandoc.Error
40import Control.Monad ( when, liftM, guard, mzero )
41import Control.Monad ( when, liftM, guard, mzero )
41import Data.List ( findIndex, intercalate, isInfixOf,
42import Data.List ( findIndex, intercalate, isInfixOf,
@@ -49,8 +50,7 @@ import Data.Sequence (viewr, ViewR(..))
49import Data.Char (toLower, isHexDigit, isSpace, toUpper)
50import Data.Char (toLower, isHexDigit, isSpace, toUpper)
50import Data.Monoid ((<>))
51import Data.Monoid ((<>))
51import Control.Monad.Except (throwError)
52import Control.Monad.Except (throwError)
52−import Text.Pandoc.Class (PandocMonad, warning, readFileFromDirs,
53+import Text.Pandoc.Class (PandocMonad, report, readFileFromDirs)
53− warningWithPos)
54
54
55-- | Parse reStructuredText string and return Pandoc document.
55-- | Parse reStructuredText string and return Pandoc document.
56readRST :: PandocMonad m
56readRST :: PandocMonad m
@@ -421,8 +421,12 @@ include = try $ do
421 when (f `elem` containers) $
421 when (f `elem` containers) $
422 throwError $ PandocParseError $ "Include file loop at " ++ show oldPos
422 throwError $ PandocParseError $ "Include file loop at " ++ show oldPos
423 updateState $ \s -> s{ stateContainers = f : stateContainers s }
423 updateState $ \s -> s{ stateContainers = f : stateContainers s }
424− contents <- readFileFromDirs ["."] f
424+ mbContents <- readFileFromDirs ["."] f
425− let contentLines = lines contents
425+ contentLines <- case mbContents of
426+ Just s -> return $ lines s
427+ Nothing -> do
428+ report $ CouldNotLoadIncludeFile f oldPos
429+ return []
426 let numLines = length contentLines
430 let numLines = length contentLines
427 let startLine' = case startLine of
431 let startLine' = case startLine of
428 Nothing -> 1
432 Nothing -> 1
@@ -688,7 +692,7 @@ directive' = do
688 return $ B.divWith attrs children
692 return $ B.divWith attrs children
689 other -> do
693 other -> do
690 pos <- getPosition
694 pos <- getPosition
691− warningWithPos pos $ "ignoring unknown directive: " ++ other
695+ report $ SkippedContent (".. " ++ other) pos
692 return mempty
696 return mempty
693
697
694-- TODO:
698-- TODO:
@@ -696,6 +700,7 @@ directive' = do
696-- change Text.Pandoc.Definition.Format to fix
700-- change Text.Pandoc.Definition.Format to fix
697addNewRole :: PandocMonad m => String -> [(String, String)] -> RSTParser m Blocks
701addNewRole :: PandocMonad m => String -> [(String, String)] -> RSTParser m Blocks
698addNewRole roleString fields = do
702addNewRole roleString fields = do
703+ pos <- getPosition
699 (role, parentRole) <- parseFromString inheritedRole roleString
704 (role, parentRole) <- parseFromString inheritedRole roleString
700 customRoles <- stateRstCustomRoles <$> getState
705 customRoles <- stateRstCustomRoles <$> getState
701 let getBaseRole (r, f, a) roles =
706 let getBaseRole (r, f, a) roles =
@@ -716,22 +721,18 @@ addNewRole roleString fields = do
716
721
717 -- warn about syntax we ignore
722 -- warn about syntax we ignore
718 flip mapM_ fields $ \(key, _) -> case key of
723 flip mapM_ fields $ \(key, _) -> case key of
719− "language" -> when (baseRole /= "code") $ warning $
724+ "language" -> when (baseRole /= "code") $ report $
720− "ignoring :language: field because the parent of role :" ++
725+ SkippedContent ":language: [because parent of role is not :code:]"
721− role ++ ": is :" ++ baseRole ++ ": not :code:"
726+ pos
722− "format" -> when (baseRole /= "raw") $ warning $
727+ "format" -> when (baseRole /= "raw") $ report $
723− "ignoring :format: field because the parent of role :" ++
728+ SkippedContent ":format: [because parent of role is not :raw:]" pos
724− role ++ ": is :" ++ baseRole ++ ": not :raw:"
729+ _ -> report $ SkippedContent (":" ++ key ++ ":") pos
725− _ -> warning $ "ignoring unknown field :" ++ key ++
726− ": in definition of role :" ++ role ++ ": in"
727 when (parentRole == "raw" && countKeys "format" > 1) $
730 when (parentRole == "raw" && countKeys "format" > 1) $
728− warning $
729− "ignoring :format: fields after the first in the definition of role :"
731+ report $ SkippedContent ":format: [after first in definition of role]"
730− ++ role ++": in"
732+ pos
731 when (parentRole == "code" && countKeys "language" > 1) $
733 when (parentRole == "code" && countKeys "language" > 1) $
732− warning $
734+ report $ SkippedContent
733− "ignoring :language: fields after the first in the definition of role :"
735+ ":language: [after first in definition of role]" pos
734− ++ role ++": in"
735
736
736 updateState $ \s -> s {
737 updateState $ \s -> s {
737 stateRstCustomRoles =
738 stateRstCustomRoles =
@@ -1011,9 +1012,9 @@ simpleTable headless = do
1011 case B.toList tbl of
1012 case B.toList tbl of
1012 [Table c a _w h l] -> return $ B.singleton $
1013 [Table c a _w h l] -> return $ B.singleton $
1013 Table c a (replicate (length a) 0) h l
1014 Table c a (replicate (length a) 0) h l
1014− _ -> do
1015+ _ ->
1016+ throwError $ PandocShouldNeverHappenError
1015− warning "tableWith returned something unexpected"
1017+ "tableWith returned something unexpected"
1016− return tbl -- TODO error?
1017 where
1018 where
1018 sep = return () -- optional (simpleTableSep '-')
1019 sep = return () -- optional (simpleTableSep '-')
1019
1020
@@ -1132,7 +1133,7 @@ renderRole contents fmt role attr = case role of
1132 renderRole contents newFmt newRole newAttr
1133 renderRole contents newFmt newRole newAttr
1133 Nothing -> do
1134 Nothing -> do
1134 pos <- getPosition
1135 pos <- getPosition
1135− warningWithPos pos $ "ignoring unknown role :" ++ custom ++ ": in"
1136+ report $ SkippedContent (":" ++ custom ++ ":") pos
1136 return $ B.str contents -- Undefined role
1137 return $ B.str contents -- Undefined role
1137 where
1138 where
1138 titleRef ref = return $ B.str ref -- FIXME: Not a sensible behaviour
1139 titleRef ref = return $ B.str ref -- FIXME: Not a sensible behaviour
@@ -1217,9 +1218,7 @@ explicitLink = try $ do
1217 case M.lookup key keyTable of
1218 case M.lookup key keyTable of
1218 Nothing -> do
1219 Nothing -> do
1219 pos <- getPosition
1220 pos <- getPosition
1220− warningWithPos pos $
1221+ report $ ReferenceNotFound (show key) pos
1221− "Could not find reference for " ++
1222− show key
1223 return ("","",nullAttr)
1222 return ("","",nullAttr)
1224 Just ((s,t),a) -> return (s,t,a)
1223 Just ((s,t),a) -> return (s,t,a)
1225 _ -> return (src, "", nullAttr)
1224 _ -> return (src, "", nullAttr)
@@ -1242,9 +1241,7 @@ referenceLink = try $ do
1242 ((src,tit), attr) <- case M.lookup key keyTable of
1241 ((src,tit), attr) <- case M.lookup key keyTable of
1243 Nothing -> do
1242 Nothing -> do
1244 pos <- getPosition
1243 pos <- getPosition
1245− warningWithPos pos $
1244+ report $ ReferenceNotFound (show key) pos
1246− "Could not find reference for " ++
1247− show key
1248 return (("",""),nullAttr)
1245 return (("",""),nullAttr)
1249 Just val -> return val
1246 Just val -> return val
1250 -- if anonymous link, remove key so it won't be used again
1247 -- if anonymous link, remove key so it won't be used again
@@ -1273,8 +1270,7 @@ subst = try $ do
1273 case M.lookup key substTable of
1270 case M.lookup key substTable of
1274 Nothing -> do
1271 Nothing -> do
1275 pos <- getPosition
1272 pos <- getPosition
1276− warningWithPos pos $
1273+ report $ ReferenceNotFound (show key) pos
1277− "Could not find reference for " ++ show key
1278 return mempty
1274 return mempty
1279 Just target -> return target
1275 Just target -> return target
1280
1276
@@ -1288,8 +1284,7 @@ note = try $ do
1288 case lookup ref notes of
1284 case lookup ref notes of
1289 Nothing -> do
1285 Nothing -> do
1290 pos <- getPosition
1286 pos <- getPosition
1291− warningWithPos pos $
1287+ report $ ReferenceNotFound (show ref) pos
1292− "Could not find note for " ++ show ref
1293 return mempty
1288 return mempty
1294 Just raw -> do
1289 Just raw -> do
1295 -- We temporarily empty the note list while parsing the note,
1290 -- 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
35import Text.Pandoc.Definition
35import Text.Pandoc.Definition
36import qualified Text.Pandoc.Builder as B
36import qualified Text.Pandoc.Builder as B
37import Text.Pandoc.Options
37import Text.Pandoc.Options
38−import Text.Pandoc.Logging (Verbosity(..))
38+import Text.Pandoc.Logging
39import Text.Pandoc.Parsing hiding (enclosed, macro, nested)
39import Text.Pandoc.Parsing hiding (enclosed, macro, nested)
40import Text.Pandoc.Readers.HTML (htmlTag, isCommentTag)
40import Text.Pandoc.Readers.HTML (htmlTag, isCommentTag)
41import Control.Monad
41import Control.Monad
42−import Text.Printf (printf)
43import Text.Pandoc.XML (fromEntities)
42import Text.Pandoc.XML (fromEntities)
44import Data.Maybe (fromMaybe)
43import Data.Maybe (fromMaybe)
45import Text.HTML.TagSoup
44import Text.HTML.TagSoup
@@ -133,8 +132,7 @@ block = do
133 <|> blockElements
132 <|> blockElements
134 <|> para
133 <|> para
135 skipMany blankline
134 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
138 return res
136 return res
139
137
140blockElements :: PandocMonad m => TWParser m B.Blocks
138blockElements :: PandocMonad m => TWParser m B.Blocks
src/Text/Pandoc/Readers/Textile.hs+2−4
@@ -56,8 +56,8 @@ import Text.Pandoc.Definition
56import Text.Pandoc.Builder (Inlines, Blocks, trimInlines)
56import Text.Pandoc.Builder (Inlines, Blocks, trimInlines)
57import qualified Text.Pandoc.Builder as B
57import qualified Text.Pandoc.Builder as B
58import Text.Pandoc.Options
58import Text.Pandoc.Options
59−import Text.Pandoc.Logging (Verbosity(..))
60import Text.Pandoc.Parsing
59import Text.Pandoc.Parsing
60+import Text.Pandoc.Logging
61import Text.Pandoc.Readers.HTML ( htmlTag, isBlockTag, isInlineTag )
61import Text.Pandoc.Readers.HTML ( htmlTag, isBlockTag, isInlineTag )
62import Text.Pandoc.Shared (trim)
62import Text.Pandoc.Shared (trim)
63import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXBlock )
63import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXBlock )
@@ -67,7 +67,6 @@ import Data.List ( intercalate, transpose, intersperse )
67import Data.Char ( digitToInt, isUpper )
67import Data.Char ( digitToInt, isUpper )
68import Control.Monad ( guard, liftM )
68import Control.Monad ( guard, liftM )
69import Data.Monoid ((<>))
69import Data.Monoid ((<>))
70−import Text.Printf
71import Text.Pandoc.Class (PandocMonad, report)
70import Text.Pandoc.Class (PandocMonad, report)
72import Control.Monad.Except (throwError)
71import Control.Monad.Except (throwError)
73
72
@@ -141,8 +140,7 @@ block :: PandocMonad m => ParserT [Char] ParserState m Blocks
141block = do
140block = do
142 res <- choice blockParsers <?> "block"
141 res <- choice blockParsers <?> "block"
143 pos <- getPosition
142 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
146 return res
144 return res
147
145
148commentBlock :: PandocMonad m => ParserT [Char] ParserState m Blocks
146commentBlock :: 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,
65import Control.Applicative ((<|>))
65import Control.Applicative ((<|>))
66import Data.Maybe (fromMaybe, mapMaybe, maybeToList, isNothing)
66import Data.Maybe (fromMaybe, mapMaybe, maybeToList, isNothing)
67import Data.Char (ord, isSpace, toLower)
67import Data.Char (ord, isSpace, toLower)
68−import Text.Pandoc.Class (PandocMonad)
68+import Text.Pandoc.Class (PandocMonad, report)
69import qualified Text.Pandoc.Class as P
69import qualified Text.Pandoc.Class as P
70+import Text.Pandoc.Logging
70
71
71data ListMarker = NoMarker
72data ListMarker = NoMarker
72 | BulletMarker
73 | BulletMarker
@@ -1173,7 +1174,7 @@ inlineToOpenXML' opts (Image attr alt (src, title)) = do
1173 res <- runExceptT $ lift (P.fetchItem (writerSourceURL opts) src)
1174 res <- runExceptT $ lift (P.fetchItem (writerSourceURL opts) src)
1174 case res of
1175 case res of
1175 Left (_ :: PandocError) -> do
1176 Left (_ :: PandocError) -> do
1176− P.warning ("Could not find image `" ++ src ++ "', skipping...")
1177+ report $ CouldNotFetchResource src ""
1177 -- emit alt text
1178 -- emit alt text
1178 inlinesToOpenXML opts alt
1179 inlinesToOpenXML opts alt
1179 Right (img, mt) -> do
1180 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
29Conversion of 'Pandoc' documents to EPUB.
29Conversion of 'Pandoc' documents to EPUB.
30-}
30-}
31module Text.Pandoc.Writers.EPUB ( writeEPUB2, writeEPUB3 ) where
31module Text.Pandoc.Writers.EPUB ( writeEPUB2, writeEPUB3 ) where
32+import Text.Pandoc.Logging
32import qualified Data.Map as M
33import qualified Data.Map as M
33import qualified Data.Set as Set
34import qualified Data.Set as Set
34import Data.Maybe ( fromMaybe, catMaybes )
35import Data.Maybe ( fromMaybe, catMaybes )
@@ -65,7 +66,7 @@ import Text.Pandoc.MIME (MimeType, getMimeType, extensionFromMimeType)
65import Text.HTML.TagSoup (Tag(TagOpen), fromAttrib, parseTags)
66import Text.HTML.TagSoup (Tag(TagOpen), fromAttrib, parseTags)
66import Control.Monad.Except (throwError, catchError)
67import Control.Monad.Except (throwError, catchError)
67import Text.Pandoc.Error
68import Text.Pandoc.Error
68−import Text.Pandoc.Class (PandocMonad)
69+import Text.Pandoc.Class (PandocMonad, report)
69import qualified Text.Pandoc.Class as P
70import qualified Text.Pandoc.Class as P
70
71
71-- A Chapter includes a list of blocks and maybe a section
72-- A Chapter includes a list of blocks and maybe a section
@@ -415,7 +416,7 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
415 let matchingGlob f = do
416 let matchingGlob f = do
416 xs <- lift $ P.glob f
417 xs <- lift $ P.glob f
417 when (null xs) $
418 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"
419 return xs
420 return xs
420 let mkFontEntry f = mkEntry (takeFileName f) `fmap` (lift $ P.readFileLazy f)
421 let mkFontEntry f = mkEntry (takeFileName f) `fmap` (lift $ P.readFileLazy f)
421 fontFiles <- concat <$> mapM matchingGlob (writerEpubFonts opts')
422 fontFiles <- concat <$> mapM matchingGlob (writerEpubFonts opts')
@@ -883,8 +884,7 @@ modifyMediaRef opts oldsrc = do
883 (oldsrc, (new, Just entry)):media}
884 (oldsrc, (new, Just entry)):media}
884 return new)
885 return new)
885 (\e -> do
886 (\e -> do
886− P.warning $ "Could not find media `" ++ oldsrc ++
887+ report $ CouldNotFetchResource oldsrc (show e)
887− "', skipping...\n" ++ show e
888 return oldsrc)
888 return oldsrc)
889
889
890transformBlock :: PandocMonad m
890transformBlock :: PandocMonad m
src/Text/Pandoc/Writers/FB2.hs+4−6
@@ -41,13 +41,13 @@ import qualified Text.XML.Light.Cursor as XC
41import qualified Data.ByteString.Char8 as B8
41import qualified Data.ByteString.Char8 as B8
42import Control.Monad.Except (throwError, catchError)
42import Control.Monad.Except (throwError, catchError)
43
43
44−
44+import Text.Pandoc.Logging
45import Text.Pandoc.Definition
45import Text.Pandoc.Definition
46import Text.Pandoc.Options (WriterOptions(..), HTMLMathMethod(..), def)
46import Text.Pandoc.Options (WriterOptions(..), HTMLMathMethod(..), def)
47import Text.Pandoc.Shared (orderedListMarkers, isHeaderBlock, capitalize,
47import Text.Pandoc.Shared (orderedListMarkers, isHeaderBlock, capitalize,
48 linesToPara)
48 linesToPara)
49import Text.Pandoc.Error
49import Text.Pandoc.Error
50−import Text.Pandoc.Class (PandocMonad)
50+import Text.Pandoc.Class (PandocMonad, report)
51import qualified Text.Pandoc.Class as P
51import qualified Text.Pandoc.Class as P
52
52
53-- | Data to be written at the end of the document:
53-- | Data to be written at the end of the document:
@@ -244,14 +244,12 @@ fetchImage href link = do
244 catchError (do (bs, mbmime) <- P.fetchItem Nothing link
244 catchError (do (bs, mbmime) <- P.fetchItem Nothing link
245 case mbmime of
245 case mbmime of
246 Nothing -> do
246 Nothing -> do
247− P.warning ("Could not determine mime type for "
247+ report $ CouldNotDetermineMimeType link
248− ++ link)
249 return Nothing
248 return Nothing
250 Just mime -> return $ Just (mime,
249 Just mime -> return $ Just (mime,
251 B8.unpack $ encode bs))
250 B8.unpack $ encode bs))
252 (\e ->
251 (\e ->
253− do P.warning ("Could not fetch " ++ link ++
252+ do report $ CouldNotFetchResource link (show e)
254− ":\n" ++ show e)
255 return Nothing)
253 return Nothing)
256 case mbimg of
254 case mbimg of
257 Just (imgtype, imgdata) -> do
255 Just (imgtype, imgdata) -> do
src/Text/Pandoc/Writers/ICML.hs+4−4
@@ -30,7 +30,8 @@ import Control.Monad.State
30import Control.Monad.Except (runExceptT)
30import Control.Monad.Except (runExceptT)
31import Network.URI (isURI)
31import Network.URI (isURI)
32import qualified Data.Set as Set
32import qualified Data.Set as Set
33−import Text.Pandoc.Class (PandocMonad)
33+import Text.Pandoc.Class (PandocMonad, report)
34+import Text.Pandoc.Logging
34import qualified Text.Pandoc.Class as P
35import qualified Text.Pandoc.Class as P
35
36
36type Style = [String]
37type Style = [String]
@@ -538,14 +539,13 @@ imageICML opts style attr (src, _) = do
538 res <- runExceptT $ lift $ P.fetchItem (writerSourceURL opts) src
539 res <- runExceptT $ lift $ P.fetchItem (writerSourceURL opts) src
539 imgS <- case res of
540 imgS <- case res of
540 Left (_ :: PandocError) -> do
541 Left (_ :: PandocError) -> do
541− lift $ P.warning $ "Could not find image `" ++ src ++ "', skipping..."
542+ report $ CouldNotFetchResource src ""
542 return def
543 return def
543 Right (img, _) -> do
544 Right (img, _) -> do
544 case imageSize img of
545 case imageSize img of
545 Right size -> return size
546 Right size -> return size
546 Left msg -> do
547 Left msg -> do
547− lift $ P.warning $ "Could not determine image size in `" ++
548+ report $ CouldNotDetermineImageSize src msg
548− src ++ "': " ++ msg
549 return def
549 return def
550 let (ow, oh) = sizeInPoints imgS
550 let (ow, oh) = sizeInPoints imgS
551 (imgWidth, imgHeight) = desiredSizeInPoints opts attr imgS
551 (imgWidth, imgHeight) = desiredSizeInPoints opts attr imgS
src/Text/Pandoc/Writers/Math.hs+3−3
@@ -6,6 +6,7 @@ where
6
6
7import Text.Pandoc.Class
7import Text.Pandoc.Class
8import Text.Pandoc.Definition
8import Text.Pandoc.Definition
9+import Text.Pandoc.Logging
9import Text.TeXMath (Exp, writePandoc, DisplayType(..), readTeX)
10import Text.TeXMath (Exp, writePandoc, DisplayType(..), readTeX)
10
11
11-- | Converts a raw TeX math formula to a list of 'Pandoc' inlines.
12-- | Converts a raw TeX math formula to a list of 'Pandoc' inlines.
@@ -20,7 +21,7 @@ texMathToInlines mt inp = do
20 case res of
21 case res of
21 Right (Just ils) -> return ils
22 Right (Just ils) -> return ils
22 Right (Nothing) -> do
23 Right (Nothing) -> do
23− warning $ "Could not render TeX math as unicode, rendering as raw TeX:\n" ++ inp
24+ report $ CouldNotConvertTeXMath inp ""
24 return [mkFallback mt inp]
25 return [mkFallback mt inp]
25 Left il -> return [il]
26 Left il -> return [il]
26
27
@@ -40,8 +41,7 @@ convertMath writer mt str = do
40 case writer dt <$> readTeX str of
41 case writer dt <$> readTeX str of
41 Right r -> return (Right r)
42 Right r -> return (Right r)
42 Left e -> do
43 Left e -> do
43− warning $ "Could not convert TeX math, rendering as raw TeX:\n" ++
44+ report $ CouldNotConvertTeXMath str e
44− str ++ "\n" ++ e
45 return (Left $ mkFallback mt str)
45 return (Left $ mkFallback mt str)
46 where dt = case mt of
46 where dt = case mt of
47 DisplayMath -> DisplayBlock
47 DisplayMath -> DisplayBlock
src/Text/Pandoc/Writers/ODT.hs+4−4
@@ -50,8 +50,9 @@ import Text.Pandoc.Error (PandocError)
50import Text.Pandoc.XML
50import Text.Pandoc.XML
51import Text.Pandoc.Pretty
51import Text.Pandoc.Pretty
52import System.FilePath ( takeExtension, takeDirectory, (<.>))
52import System.FilePath ( takeExtension, takeDirectory, (<.>))
53−import Text.Pandoc.Class ( PandocMonad )
53+import Text.Pandoc.Class ( PandocMonad, report )
54import qualified Text.Pandoc.Class as P
54import qualified Text.Pandoc.Class as P
55+import Text.Pandoc.Logging
55
56
56data ODTState = ODTState { stEntries :: [Entry]
57data ODTState = ODTState { stEntries :: [Entry]
57 }
58 }
@@ -149,14 +150,13 @@ transformPicMath opts (Image attr@(id', cls, _) lab (src,t)) = do
149 res <- runExceptT $ lift $ P.fetchItem (writerSourceURL opts) src
150 res <- runExceptT $ lift $ P.fetchItem (writerSourceURL opts) src
150 case res of
151 case res of
151 Left (_ :: PandocError) -> do
152 Left (_ :: PandocError) -> do
152− lift $ P.warning $ "Could not find image `" ++ src ++ "', skipping..."
153+ report $ CouldNotFetchResource src ""
153 return $ Emph lab
154 return $ Emph lab
154 Right (img, mbMimeType) -> do
155 Right (img, mbMimeType) -> do
155 (ptX, ptY) <- case imageSize img of
156 (ptX, ptY) <- case imageSize img of
156 Right s -> return $ sizeInPoints s
157 Right s -> return $ sizeInPoints s
157 Left msg -> do
158 Left msg -> do
158− lift $ P.warning $ "Could not determine image size in `" ++
159+ report $ CouldNotDetermineImageSize src msg
159− src ++ "': " ++ msg
160 return (100, 100)
160 return (100, 100)
161 let dims =
161 let dims =
162 case (getDim Width, getDim Height) of
162 case (getDim Width, getDim Height) of
src/Text/Pandoc/Writers/RTF.hs+7−8
@@ -37,7 +37,7 @@ import Text.Pandoc.Writers.Shared
37import Text.Pandoc.Writers.Math
37import Text.Pandoc.Writers.Math
38import Text.Pandoc.Templates (renderTemplate')
38import Text.Pandoc.Templates (renderTemplate')
39import Text.Pandoc.Walk
39import Text.Pandoc.Walk
40−import Text.Pandoc.Class (warning)
40+import Text.Pandoc.Logging
41import Data.List ( isSuffixOf, intercalate )
41import Data.List ( isSuffixOf, intercalate )
42import Data.Char ( ord, chr, isDigit )
42import Data.Char ( ord, chr, isDigit )
43import qualified Data.ByteString as B
43import qualified Data.ByteString as B
@@ -46,7 +46,7 @@ import Text.Printf ( printf )
46import Text.Pandoc.ImageSize
46import Text.Pandoc.ImageSize
47import Control.Monad.Except (throwError, runExceptT, lift)
47import Control.Monad.Except (throwError, runExceptT, lift)
48import Text.Pandoc.Error
48import Text.Pandoc.Error
49−import Text.Pandoc.Class (PandocMonad)
49+import Text.Pandoc.Class (PandocMonad, report)
50import qualified Text.Pandoc.Class as P
50import qualified Text.Pandoc.Class as P
51
51
52-- | Convert Image inlines into a raw RTF embedded image, read from a file,
52-- | Convert Image inlines into a raw RTF embedded image, read from a file,
@@ -65,8 +65,7 @@ rtfEmbedImage opts x@(Image attr _ (src,_)) = do
65 _ -> throwError $ PandocSomeError "Unknown file type"
65 _ -> throwError $ PandocSomeError "Unknown file type"
66 sizeSpec <- case imageSize imgdata of
66 sizeSpec <- case imageSize imgdata of
67 Left msg -> do
67 Left msg -> do
68− warning $ "Could not determine image size in `" ++
68+ report $ CouldNotDetermineImageSize src msg
69− src ++ "': " ++ msg
70 return ""
69 return ""
71 Right sz -> return $ "\\picw" ++ show xpx ++
70 Right sz -> return $ "\\picw" ++ show xpx ++
72 "\\pich" ++ show ypx ++
71 "\\pich" ++ show ypx ++
@@ -79,17 +78,17 @@ rtfEmbedImage opts x@(Image attr _ (src,_)) = do
79 concat bytes ++ "}"
78 concat bytes ++ "}"
80 if B.null imgdata
79 if B.null imgdata
81 then do
80 then do
82− warning $ "Image " ++ src ++ " contained no data, skipping."
81+ report $ CouldNotFetchResource src "image contained no data"
83 return x
82 return x
84 else return $ RawInline (Format "rtf") raw
83 else return $ RawInline (Format "rtf") raw
85 | otherwise -> do
84 | otherwise -> do
86− warning $ "Image " ++ src ++ " is not a jpeg or png, skipping."
85+ report $ CouldNotFetchResource src "image is not a jpeg or png"
87 return x
86 return x
88 Right (_, Nothing) -> do
87 Right (_, Nothing) -> do
89− warning $ "Could not determine image type for " ++ src ++ ", skipping."
88+ report $ CouldNotDetermineMimeType src
90 return x
89 return x
91 Left ( e :: PandocError ) -> do
90 Left ( e :: PandocError ) -> do
92− warning $ "Could not fetch image " ++ src ++ "\n" ++ show e
91+ report $ CouldNotFetchResource src (show e)
93 return x
92 return x
94rtfEmbedImage _ x = return x
93rtfEmbedImage _ x = return x
95
94
test/Tests/Readers/Docx.hs+1−1
@@ -61,7 +61,7 @@ testForWarningsWithOptsIO :: ReaderOptions -> String -> FilePath -> [String] ->
61testForWarningsWithOptsIO opts name docxFile expected = do
61testForWarningsWithOptsIO opts name docxFile expected = do
62 df <- B.readFile docxFile
62 df <- B.readFile docxFile
63 logs <- runIOorExplode (readDocx opts df >> P.getLog)
63 logs <- runIOorExplode (readDocx opts df >> P.getLog)
64− let warns = [s | (WARNING, s) <- logs]
64+ let warns = [m | DocxParserWarning m <- logs]
65 return $ test id name (unlines warns, unlines expected)
65 return $ test id name (unlines warns, unlines expected)
66
66
67testForWarningsWithOpts :: ReaderOptions -> String -> FilePath -> [String] -> Test
67testForWarningsWithOpts :: ReaderOptions -> String -> FilePath -> [String] -> Test