summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-02-09 22:21:07 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-02-09 22:21:07 +0100
commit87507e1b9cf976aeb39a9308a2d050ea6e060585 (patch)
tree78cc07c7ca585beb2420a5b1b6145a5a4edb0af3
parent0a4ba91994c875b0eaf22b76a6153c0d1de0f018 (diff)
LaTeX reader: Issue warnings when skipping unknown latex commands.
See #3392.
-rw-r--r--src/Text/Pandoc/Class.hs2
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs14
2 files changed, 11 insertions, 5 deletions
diff --git a/src/Text/Pandoc/Class.hs b/src/Text/Pandoc/Class.hs
index 86158d632..df831c8b2 100644
--- a/src/Text/Pandoc/Class.hs
+++ b/src/Text/Pandoc/Class.hs
@@ -73,7 +73,7 @@ import qualified Text.Pandoc.Shared as IO ( readDataFile
import qualified Text.Pandoc.UTF8 as UTF8
import Text.Pandoc.Compat.Time (UTCTime)
import Text.Pandoc.Options (Verbosity(..))
-import Text.Parsec (ParsecT, SourcePos)
+import Text.Parsec (ParsecT, SourcePos, getPosition)
import qualified Text.Pandoc.Compat.Time as IO (getCurrentTime)
import Text.Pandoc.MIME (MimeType, getMimeType)
import Data.Time.Clock.POSIX ( utcTimeToPOSIXSeconds
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index 4fb3bb077..7233c05c5 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -296,7 +296,7 @@ inBrackets x = str "[" <> x <> str "]"
-- eat an optional argument and one or more arguments in braces
ignoreInlines :: PandocMonad m => String -> (String, LP m Inlines)
-ignoreInlines name = (name, doraw <|> (mempty <$ optargs))
+ignoreInlines name = (name, doraw <|> (optargs >> ignore name))
where optargs = skipopts *> skipMany (try $ optional sp *> braced)
contseq = '\\':name
doraw = (rawInline "latex" . (contseq ++) . snd) <$>
@@ -304,8 +304,14 @@ ignoreInlines name = (name, doraw <|> (mempty <$ optargs))
guard $ extensionEnabled Ext_raw_tex exts
withRaw optargs)
+ignore :: (Monoid a, PandocMonad m) => String -> LP m a
+ignore name = do
+ pos <- getPosition
+ warningWithPos pos $ "Skipped \\" ++ name ++ " and its arguments"
+ return mempty
+
ignoreBlocks :: PandocMonad m => String -> (String, LP m Blocks)
-ignoreBlocks name = (name, doraw <|> (mempty <$ optargs))
+ignoreBlocks name = (name, doraw <|> (optargs >> ignore name))
where optargs = skipopts *> skipMany (try $ optional sp *> braced)
contseq = '\\':name
doraw = (rawBlock "latex" . (contseq ++) . snd) <$>
@@ -438,7 +444,7 @@ inlineCommand = try $ do
then parseFromString inlines transformed
else if extensionEnabled Ext_raw_tex exts
then return $ rawInline "latex" rawcommand
- else return mempty
+ else ignore name
(lookupListDefault mzero [name',name] inlineCommands <*
optional (try (string "{}")))
<|> raw
@@ -489,7 +495,7 @@ inlineCommands = M.fromList $
, ("sim", lit "~")
, ("label", unlessParseRaw >> (inBrackets <$> tok))
, ("ref", unlessParseRaw >> (inBrackets <$> tok))
- , ("noindent", unlessParseRaw >> return mempty)
+ , ("noindent", unlessParseRaw >> ignore "noindent")
, ("textgreek", tok)
, ("sep", lit ",")
, ("cref", unlessParseRaw >> (inBrackets <$> tok)) -- from cleveref.sty