git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: Parse inside arguments when ignoring commands.
e126ab9John MacFarlane
src/Text/Pandoc/Readers/LaTeX.hs+11−9
@@ -39,8 +39,8 @@ import Text.Pandoc.Shared
39import Text.Pandoc.Parsing
39import Text.Pandoc.Parsing
40import Data.Maybe ( fromMaybe )
40import Data.Maybe ( fromMaybe )
41import Data.Char ( chr, toUpper )
41import Data.Char ( chr, toUpper )
42−import Data.List ( isPrefixOf, isSuffixOf )
42+import Data.List ( intercalate, isPrefixOf, isSuffixOf )
43−import Control.Monad ( when, guard )
43+import Control.Monad
44
44
45-- | Parse LaTeX from string and return 'Pandoc' document.
45-- | Parse LaTeX from string and return 'Pandoc' document.
46readLaTeX :: ParserState -- ^ Parser state, including options for parser
46readLaTeX :: ParserState -- ^ Parser state, including options for parser
@@ -430,9 +430,11 @@ unknownCommand = try $ do
430 else do
430 else do
431 (name, _, args) <- command
431 (name, _, args) <- command
432 spaces
432 spaces
433− if name `elem` commandsToIgnore
433+ unless (name `elem` commandsToIgnore) $ do
434− then return Null
434+ -- put arguments back in input to be parsed
435− else return $ Plain [Str $ concat args]
435+ inp <- getInput
436+ setInput $ intercalate " " args ++ inp
437+ return Null
436
438
437commandsToIgnore :: [String]
439commandsToIgnore :: [String]
438commandsToIgnore = ["special","pdfannot","pdfstringdef", "index","bibliography"]
440commandsToIgnore = ["special","pdfannot","pdfstringdef", "index","bibliography"]
@@ -922,7 +924,7 @@ rawLaTeXInline = try $ do
922 return $ TeX ("\\" ++ name ++ star ++ concat args)
924 return $ TeX ("\\" ++ name ++ star ++ concat args)
923 else do
925 else do
924 (name, _, args) <- command
926 (name, _, args) <- command
925− spaces
926− if name `elem` commandsToIgnore
927+ unless (name `elem` commandsToIgnore) $ do
927− then return $ Str ""
928+ inp <- getInput
928− else return $ Str (concat args)
929+ setInput $ intercalate " " args ++ inp
930+ return $ Str ""