summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-02-05 22:22:42 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-02-05 22:22:42 +0100
commitc93ecfc3c5d7c9ed0b4b7bdab943a0fedd185601 (patch)
tree0a88e35cf9c16fd9f13ec7455132d4a4a8995403
parent0bbea0cc7650af61870b310ebbf6fb8a9fec09a7 (diff)
Handle language in inline code with --listings.
Closes #3422.
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs13
-rw-r--r--test/command/3422.md9
2 files changed, 18 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index 67318a549..9e987406a 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -523,9 +523,6 @@ blockToLaTeX (CodeBlock (identifier,classes,keyvalAttr) str) = do
else [ "label=" ++ ref ])
else []
- mbBraced x = if not (all isAlphaNum x)
- then "{" <> x <> "}"
- else x
printParams
| null params = empty
| otherwise = brackets $ hcat (intersperse ", "
@@ -937,12 +934,15 @@ inlineToLaTeX (Code (_,classes,_) str) = do
-> highlightCode
| otherwise -> rawCode
where listingsCode = do
+ let listingsopt = case getListingsLanguage classes of
+ Just l -> "[language=" ++ mbBraced l ++ "]"
+ Nothing -> ""
inNote <- gets stInNote
when inNote $ modify $ \s -> s{ stVerbInNote = True }
let chr = case "!\"&'()*,-./:;?@_" \\ str of
(c:_) -> c
[] -> '!'
- return $ text $ "\\lstinline" ++ [chr] ++ str ++ [chr]
+ return $ text $ "\\lstinline" ++ listingsopt ++ [chr] ++ str ++ [chr]
highlightCode = do
case highlight formatLaTeXInline ("",classes,[]) str of
Nothing -> rawCode
@@ -1167,6 +1167,11 @@ getListingsLanguage :: [String] -> Maybe String
getListingsLanguage [] = Nothing
getListingsLanguage (x:xs) = toListingsLanguage x <|> getListingsLanguage xs
+mbBraced :: String -> String
+mbBraced x = if not (all isAlphaNum x)
+ then "{" <> x <> "}"
+ else x
+
-- Extract a key from divs and spans
extract :: String -> Block -> [String]
extract key (Div attr _) = lookKey key attr
diff --git a/test/command/3422.md b/test/command/3422.md
new file mode 100644
index 000000000..a010320e9
--- /dev/null
+++ b/test/command/3422.md
@@ -0,0 +1,9 @@
+See #3422
+
+```
+% pandoc -t latex --listings
+`int main(int argc, const char *argv[]);`{.c}
+^D
+\lstinline[language=C]!int main(int argc, const char *argv[]);!
+```
+