git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: Issue warnings when skipping unknown latex commands.
87507e1John MacFarlane
src/Text/Pandoc/Class.hs+1−1
@@ -73,7 +73,7 @@ import qualified Text.Pandoc.Shared as IO ( readDataFile
73import qualified Text.Pandoc.UTF8 as UTF8
73import qualified Text.Pandoc.UTF8 as UTF8
74import Text.Pandoc.Compat.Time (UTCTime)
74import Text.Pandoc.Compat.Time (UTCTime)
75import Text.Pandoc.Options (Verbosity(..))
75import Text.Pandoc.Options (Verbosity(..))
76−import Text.Parsec (ParsecT, SourcePos)
76+import Text.Parsec (ParsecT, SourcePos, getPosition)
77import qualified Text.Pandoc.Compat.Time as IO (getCurrentTime)
77import qualified Text.Pandoc.Compat.Time as IO (getCurrentTime)
78import Text.Pandoc.MIME (MimeType, getMimeType)
78import Text.Pandoc.MIME (MimeType, getMimeType)
79import Data.Time.Clock.POSIX ( utcTimeToPOSIXSeconds
79import Data.Time.Clock.POSIX ( utcTimeToPOSIXSeconds
src/Text/Pandoc/Readers/LaTeX.hs+10−4
@@ -296,7 +296,7 @@ inBrackets x = str "[" <> x <> str "]"
296
296
297-- eat an optional argument and one or more arguments in braces
297-- eat an optional argument and one or more arguments in braces
298ignoreInlines :: PandocMonad m => String -> (String, LP m Inlines)
298ignoreInlines :: PandocMonad m => String -> (String, LP m Inlines)
299−ignoreInlines name = (name, doraw <|> (mempty <$ optargs))
299+ignoreInlines name = (name, doraw <|> (optargs >> ignore name))
300 where optargs = skipopts *> skipMany (try $ optional sp *> braced)
300 where optargs = skipopts *> skipMany (try $ optional sp *> braced)
301 contseq = '\\':name
301 contseq = '\\':name
302 doraw = (rawInline "latex" . (contseq ++) . snd) <$>
302 doraw = (rawInline "latex" . (contseq ++) . snd) <$>
@@ -304,8 +304,14 @@ ignoreInlines name = (name, doraw <|> (mempty <$ optargs))
304 guard $ extensionEnabled Ext_raw_tex exts
304 guard $ extensionEnabled Ext_raw_tex exts
305 withRaw optargs)
305 withRaw optargs)
306
306
307+ignore :: (Monoid a, PandocMonad m) => String -> LP m a
308+ignore name = do
309+ pos <- getPosition
310+ warningWithPos pos $ "Skipped \\" ++ name ++ " and its arguments"
311+ return mempty
312+
307ignoreBlocks :: PandocMonad m => String -> (String, LP m Blocks)
313ignoreBlocks :: PandocMonad m => String -> (String, LP m Blocks)
308−ignoreBlocks name = (name, doraw <|> (mempty <$ optargs))
314+ignoreBlocks name = (name, doraw <|> (optargs >> ignore name))
309 where optargs = skipopts *> skipMany (try $ optional sp *> braced)
315 where optargs = skipopts *> skipMany (try $ optional sp *> braced)
310 contseq = '\\':name
316 contseq = '\\':name
311 doraw = (rawBlock "latex" . (contseq ++) . snd) <$>
317 doraw = (rawBlock "latex" . (contseq ++) . snd) <$>
@@ -438,7 +444,7 @@ inlineCommand = try $ do
438 then parseFromString inlines transformed
444 then parseFromString inlines transformed
439 else if extensionEnabled Ext_raw_tex exts
445 else if extensionEnabled Ext_raw_tex exts
440 then return $ rawInline "latex" rawcommand
446 then return $ rawInline "latex" rawcommand
441− else return mempty
447+ else ignore name
442 (lookupListDefault mzero [name',name] inlineCommands <*
448 (lookupListDefault mzero [name',name] inlineCommands <*
443 optional (try (string "{}")))
449 optional (try (string "{}")))
444 <|> raw
450 <|> raw
@@ -489,7 +495,7 @@ inlineCommands = M.fromList $
489 , ("sim", lit "~")
495 , ("sim", lit "~")
490 , ("label", unlessParseRaw >> (inBrackets <$> tok))
496 , ("label", unlessParseRaw >> (inBrackets <$> tok))
491 , ("ref", unlessParseRaw >> (inBrackets <$> tok))
497 , ("ref", unlessParseRaw >> (inBrackets <$> tok))
492− , ("noindent", unlessParseRaw >> return mempty)
498+ , ("noindent", unlessParseRaw >> ignore "noindent")
493 , ("textgreek", tok)
499 , ("textgreek", tok)
494 , ("sep", lit ",")
500 , ("sep", lit ",")
495 , ("cref", unlessParseRaw >> (inBrackets <$> tok)) -- from cleveref.sty
501 , ("cref", unlessParseRaw >> (inBrackets <$> tok)) -- from cleveref.sty