git.iko.soy/typeable/pandoc
on master help sign in
Handle language in inline code with --listings.

Closes #3422.

commitc93ecfc3c5d7c9ed0b4b7bdab943a0fedd185601 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 5 Feb 2017, 22:22 (10 years ago) parent0bbea0c
2 files changed+18−4
src/Text/Pandoc/Writers/LaTeX.hs+9−4 test/command/3422.md+9
src/Text/Pandoc/Writers/LaTeX.hs+9−4
@@ -523,9 +523,6 @@ blockToLaTeX (CodeBlock (identifier,classes,keyvalAttr) str) = do
523523 else [ "label=" ++ ref ])
524524
525525 else []
526− mbBraced x = if not (all isAlphaNum x)
527− then "{" <> x <> "}"
528− else x
529526 printParams
530527 | null params = empty
531528 | otherwise = brackets $ hcat (intersperse ", "
@@ -937,12 +934,15 @@ inlineToLaTeX (Code (_,classes,_) str) = do
937934 -> highlightCode
938935 | otherwise -> rawCode
939936 where listingsCode = do
937+ let listingsopt = case getListingsLanguage classes of
938+ Just l -> "[language=" ++ mbBraced l ++ "]"
939+ Nothing -> ""
940940 inNote <- gets stInNote
941941 when inNote $ modify $ \s -> s{ stVerbInNote = True }
942942 let chr = case "!\"&'()*,-./:;?@_" \\ str of
943943 (c:_) -> c
944944 [] -> '!'
945− return $ text $ "\\lstinline" ++ [chr] ++ str ++ [chr]
945+ return $ text $ "\\lstinline" ++ listingsopt ++ [chr] ++ str ++ [chr]
946946 highlightCode = do
947947 case highlight formatLaTeXInline ("",classes,[]) str of
948948 Nothing -> rawCode
@@ -1167,6 +1167,11 @@ getListingsLanguage :: [String] -> Maybe String
11671167getListingsLanguage [] = Nothing
11681168getListingsLanguage (x:xs) = toListingsLanguage x <|> getListingsLanguage xs
11691169
1170+mbBraced :: String -> String
1171+mbBraced x = if not (all isAlphaNum x)
1172+ then "{" <> x <> "}"
1173+ else x
1174+
11701175-- Extract a key from divs and spans
11711176extract :: String -> Block -> [String]
11721177extract key (Div attr _) = lookKey key attr
test/command/3422.mdnew file+9
@@ -0,0 +1,9 @@
1+See #3422
2+
3+```
4+% pandoc -t latex --listings
5+`int main(int argc, const char *argv[]);`{.c}
6+^D
7+\lstinline[language=C]!int main(int argc, const char *argv[]);!
8+```
9+