git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: Include inline code attributes with `--listings`.

Closes #5420.

commitd8b4e45be0b22aa5939add501339b64252d802ea authorJohn MacFarlane <jgm@berkeley.edu> dateFri 7 Jun 2019, 10:03 (7 years ago) parent2050389
2 files changed+18−4
src/Text/Pandoc/Writers/LaTeX.hs+12−4 test/command/5420.md+6
src/Text/Pandoc/Writers/LaTeX.hs+12−4
@@ -1148,14 +1148,22 @@ inlineToLaTeX (Cite cits lst) = do
11481148 Biblatex -> citationsToBiblatex cits
11491149 _ -> inlineListToLaTeX lst
11501150
1151−inlineToLaTeX (Code (_,classes,_) str) = do
1151+inlineToLaTeX (Code (_,classes,kvs) str) = do
11521152 opts <- gets stOptions
11531153 inHeading <- gets stInHeading
11541154 inItem <- gets stInItem
11551155 let listingsCode = do
1156− let listingsopt = case getListingsLanguage classes of
1157− Just l -> "[language=" ++ mbBraced l ++ "]"
1158− Nothing -> ""
1156+ let listingsopts = (case getListingsLanguage classes of
1157+ Just l -> (("language", mbBraced l):)
1158+ Nothing -> id) $
1159+ [(k,v) | (k,v) <- kvs
1160+ , k `notElem` ["exports","tangle","results"]]
1161+ let listingsopt = if null listingsopts
1162+ then ""
1163+ else "[" ++
1164+ intercalate ", "
1165+ (map (\(k,v) -> k ++ "=" ++ v)
1166+ listingsopts) ++ "]"
11591167 inNote <- gets stInNote
11601168 when inNote $ modify $ \s -> s{ stVerbInNote = True }
11611169 let chr = case "!\"'()*,-./:;?@" \\ str of
test/command/5420.mdnew file+6
@@ -0,0 +1,6 @@
1+```
2+% pandoc --listings -t latex
3+`int a = 1;`{.cpp style=cpp}
4+^D
5+\passthrough{\lstinline[language={C++}, style=cpp]!int a = 1;!}
6+```