Skip to content

Commit

Permalink
Fixed repeated log messages in RST reader.
Browse files Browse the repository at this point in the history
See #3447.  To complete fixes on this issue, we need to
do the same for the other readers.  Note that the changes
required are minimal -- add reportLogMessages to the end
of the main parser, and replace report with logMessage.
(except for trace)
  • Loading branch information
jgm committed Feb 17, 2017
1 parent 38daf9d commit a341235
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/Text/Pandoc/Readers/RST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import Data.Sequence (viewr, ViewR(..))
import Data.Char (toLower, isHexDigit, isSpace, toUpper)
import Data.Monoid ((<>))
import Control.Monad.Except (throwError)
import Text.Pandoc.Class (PandocMonad, report, readFileFromDirs)
import Text.Pandoc.Class (PandocMonad, readFileFromDirs)

-- TODO:
-- [ ] .. parsed-literal
Expand Down Expand Up @@ -171,6 +171,7 @@ parseRST = do
let (blocks', meta') = if standalone
then titleTransform (blocks, meta)
else (blocks, meta)
reportLogMessages
return $ Pandoc meta' blocks'

--
Expand Down Expand Up @@ -436,7 +437,7 @@ include = try $ do
contentLines <- case mbContents of
Just s -> return $ lines s
Nothing -> do
report $ CouldNotLoadIncludeFile f oldPos
logMessage $ CouldNotLoadIncludeFile f oldPos
return []
let numLines = length contentLines
let startLine' = case startLine of
Expand Down Expand Up @@ -700,7 +701,7 @@ directive' = do
return $ B.divWith attrs children
other -> do
pos <- getPosition
report $ SkippedContent (".. " ++ other) pos
logMessage $ SkippedContent (".. " ++ other) pos
return mempty

tableDirective :: PandocMonad m
Expand Down Expand Up @@ -742,17 +743,17 @@ addNewRole roleString fields = do

-- warn about syntax we ignore
flip mapM_ fields $ \(key, _) -> case key of
"language" -> when (baseRole /= "code") $ report $
"language" -> when (baseRole /= "code") $ logMessage $
SkippedContent ":language: [because parent of role is not :code:]"
pos
"format" -> when (baseRole /= "raw") $ report $
"format" -> when (baseRole /= "raw") $ logMessage $
SkippedContent ":format: [because parent of role is not :raw:]" pos
_ -> report $ SkippedContent (":" ++ key ++ ":") pos
_ -> logMessage $ SkippedContent (":" ++ key ++ ":") pos
when (parentRole == "raw" && countKeys "format" > 1) $
report $ SkippedContent ":format: [after first in definition of role]"
logMessage $ SkippedContent ":format: [after first in definition of role]"
pos
when (parentRole == "code" && countKeys "language" > 1) $
report $ SkippedContent
logMessage $ SkippedContent
":language: [after first in definition of role]" pos

updateState $ \s -> s {
Expand Down Expand Up @@ -1154,7 +1155,7 @@ renderRole contents fmt role attr = case role of
renderRole contents newFmt newRole newAttr
Nothing -> do
pos <- getPosition
report $ SkippedContent (":" ++ custom ++ ":") pos
logMessage $ SkippedContent (":" ++ custom ++ ":") pos
return $ B.str contents -- Undefined role
where
titleRef ref = return $ B.str ref -- FIXME: Not a sensible behaviour
Expand Down Expand Up @@ -1266,15 +1267,15 @@ lookupKey oldkeys key = do
case M.lookup key keyTable of
Nothing -> do
let Key key' = key
report $ ReferenceNotFound key' pos
logMessage $ ReferenceNotFound key' pos
return (("",""),nullAttr)
-- check for keys of the form link_, which need to be resolved:
Just ((u@(_:_),""),_) | last u == '_' -> do
let rawkey = init u
let newkey = toKey rawkey
if newkey `elem` oldkeys
then do
report $ CircularReference rawkey pos
logMessage $ CircularReference rawkey pos
return (("",""),nullAttr)
else lookupKey (key:oldkeys) newkey
Just val -> return val
Expand All @@ -1301,7 +1302,7 @@ subst = try $ do
case M.lookup key substTable of
Nothing -> do
pos <- getPosition
report $ ReferenceNotFound (show key) pos
logMessage $ ReferenceNotFound (show key) pos
return mempty
Just target -> return target

Expand All @@ -1315,7 +1316,7 @@ note = try $ do
case lookup ref notes of
Nothing -> do
pos <- getPosition
report $ ReferenceNotFound ref pos
logMessage $ ReferenceNotFound ref pos
return mempty
Just raw -> do
-- We temporarily empty the note list while parsing the note,
Expand Down

0 comments on commit a341235

Please sign in to comment.