diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-02-05 22:22:42 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-02-05 22:22:42 +0100 |
commit | c93ecfc3c5d7c9ed0b4b7bdab943a0fedd185601 (patch) | |
tree | 0a88e35cf9c16fd9f13ec7455132d4a4a8995403 /src | |
parent | 0bbea0cc7650af61870b310ebbf6fb8a9fec09a7 (diff) | |
download | pandoc-c93ecfc3c5d7c9ed0b4b7bdab943a0fedd185601.tar.gz |
Handle language in inline code with --listings.
Closes #3422.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 13 |
1 files changed, 9 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 |