From 62b4b84bd571b72352b5cb7bba25c1a1747957b2 Mon Sep 17 00:00:00 2001 From: John MacFarlane <jgm@berkeley.edu> Date: Thu, 29 Nov 2018 11:11:44 -0800 Subject: [PATCH] LaTeX reader: Support \inputminted (closes #5103). --- src/Text/Pandoc/Readers/LaTeX.hs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 09c724f9c..42a0bc04c 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -1760,6 +1760,7 @@ blockCommands = M.fromList addMeta "bibliography" . splitBibs . toksToString)) -- includes , ("lstinputlisting", inputListing) + , ("inputminted", inputMinted) , ("graphicspath", graphicsPath) -- polyglossia , ("setdefaultlanguage", setDefaultLanguage) @@ -1918,6 +1919,11 @@ obeylines = minted :: PandocMonad m => LP m Blocks minted = do + attr <- mintedAttr + codeBlockWith attr <$> verbEnv "minted" + +mintedAttr :: PandocMonad m => LP m Attr +mintedAttr = do options <- option [] keyvals lang <- toksToString <$> braced let kvs = [ (if k == "firstnumber" @@ -1926,8 +1932,21 @@ minted = do let classes = [ lang | not (null lang) ] ++ [ "numberLines" | lookup "linenos" options == Just "true" ] - let attr = ("",classes,kvs) - codeBlockWith attr <$> verbEnv "minted" + return ("",classes,kvs) + +inputMinted :: PandocMonad m => LP m Blocks +inputMinted = do + pos <- getPosition + attr <- mintedAttr + f <- filter (/='"') . toksToString <$> braced + dirs <- (splitBy (==':') . fromMaybe ".") <$> lookupEnv "TEXINPUTS" + mbCode <- readFileFromDirs dirs f + rawcode <- case mbCode of + Just s -> return s + Nothing -> do + report $ CouldNotLoadIncludeFile f pos + return [] + return $ B.codeBlockWith attr rawcode letterContents :: PandocMonad m => LP m Blocks letterContents = do