RST Reader: Warn about skipped directives
move `addWarning` to Parsing.hs, so it can be used by Markdown & RST readers.
This commit is contained in:
parent
1a130fa48e
commit
87e536b438
3 changed files with 12 additions and 7 deletions
|
@ -162,6 +162,7 @@ module Text.Pandoc.Parsing ( anyLine,
|
|||
setSourceColumn,
|
||||
setSourceLine,
|
||||
newPos,
|
||||
addWarning
|
||||
)
|
||||
where
|
||||
|
||||
|
@ -1245,3 +1246,10 @@ applyMacros' target = do
|
|||
then do macros <- extractMacros <$> getState
|
||||
return $ applyMacros macros target
|
||||
else return target
|
||||
|
||||
-- | Append a warning to the log.
|
||||
addWarning :: Maybe SourcePos -> String -> Parser [Char] ParserState ()
|
||||
addWarning mbpos msg =
|
||||
updateState $ \st -> st{
|
||||
stateWarnings = (msg ++ maybe "" (\pos -> " " ++ show pos) mbpos) :
|
||||
stateWarnings st }
|
||||
|
|
|
@ -343,12 +343,6 @@ parseMarkdown = do
|
|||
let Pandoc _ bs = B.doc $ runF blocks st
|
||||
return $ Pandoc meta bs
|
||||
|
||||
addWarning :: Maybe SourcePos -> String -> MarkdownParser ()
|
||||
addWarning mbpos msg =
|
||||
updateState $ \st -> st{
|
||||
stateWarnings = (msg ++ maybe "" (\pos -> " " ++ show pos) mbpos) :
|
||||
stateWarnings st }
|
||||
|
||||
referenceKey :: MarkdownParser (F Blocks)
|
||||
referenceKey = try $ do
|
||||
pos <- getPosition
|
||||
|
|
|
@ -608,7 +608,10 @@ directive' = do
|
|||
"" -> block
|
||||
_ -> parseFromString parseBlocks body'
|
||||
return $ B.divWith attrs children
|
||||
_ -> return mempty
|
||||
other -> do
|
||||
pos <- getPosition
|
||||
addWarning (Just pos) $ "ignoring unknown directive: " ++ other
|
||||
return mempty
|
||||
|
||||
-- TODO:
|
||||
-- - Silently ignores illegal fields
|
||||
|
|
Loading…
Add table
Reference in a new issue