aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-11-29 11:11:44 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2018-11-29 11:11:44 -0800
commit62b4b84bd571b72352b5cb7bba25c1a1747957b2 (patch)
tree599e31da089f1aaa10063e6dcf26a6e8d558927f /src
parent049a773b5b4a65b3a726c4bc20071b825720aaa6 (diff)
downloadpandoc-62b4b84bd571b72352b5cb7bba25c1a1747957b2.tar.gz
LaTeX reader: Support \inputminted (closes #5103).
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs23
1 files 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