From cc18291baf863a59fb17a63c5c09d69da8c86b01 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 23 Dec 2011 18:37:52 -0800 Subject: LaTeX writer: Support highlighting for inline code. --- src/Text/Pandoc/Writers/LaTeX.hs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'src/Text/Pandoc/Writers/LaTeX.hs') diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 28bffef2d..cb7df6b8a 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -395,14 +395,24 @@ inlineToLaTeX (Cite cits lst) = do Biblatex -> citationsToBiblatex cits _ -> inlineListToLaTeX lst -inlineToLaTeX (Code _ str) = do - st <- get - if writerListings (stOptions st) - then do - when (stInNote st) $ modify $ \s -> s{ stVerbInNote = True } - let chr = ((enumFromTo '!' '~') \\ str) !! 0 - return $ text $ "\\lstinline" ++ [chr] ++ str ++ [chr] - else return $ text $ "\\texttt{" ++ stringToLaTeX False str ++ "}" +inlineToLaTeX (Code (_,classes,_) str) = do + opts <- gets stOptions + case () of + _ | writerListings opts -> listingsCode + | writerHighlight opts && not (null classes) -> highlightCode + | otherwise -> rawCode + where listingsCode = do + inNote <- gets stInNote + when inNote $ modify $ \s -> s{ stVerbInNote = True } + let chr = ((enumFromTo '!' '~') \\ str) !! 0 + return $ text $ "\\lstinline" ++ [chr] ++ str ++ [chr] + highlightCode = do + case highlightLaTeX True ("",classes,[]) str of + Nothing -> rawCode + Just h -> modify (\st -> st{ stHighlighting = True }) >> + return (text h) + rawCode = return + $ text $ "\\texttt{" ++ stringToLaTeX False str ++ "}" inlineToLaTeX (Quoted SingleQuote lst) = do contents <- inlineListToLaTeX lst csquotes <- liftM stCsquotes get -- cgit v1.2.3