git.iko.soy/typeable/pandoc
on master help sign in
LaTeX writer: Support line numbering with `--listings`.

If "numberLines" class is present, we add "numbers=left"; if "startFrom" is present, we add "firstnumber=". Partially addresses #763.

commit0bbee1bcf68bfb7d19b1d4230292004670286ed2 authorJohn MacFarlane <fiddlosopher@gmail.com> dateMon 4 Mar 2013, 09:31 (14 years ago) parentb2b38a6
1 file changed+8−2
src/Text/Pandoc/Writers/LaTeX.hs+8−2
src/Text/Pandoc/Writers/LaTeX.hs+8−2
@@ -332,11 +332,17 @@ blockToLaTeX (CodeBlock (_,classes,keyvalAttr) str) = do
332332 then (case getListingsLanguage classes of
333333 Just l -> [ "language=" ++ l ]
334334 Nothing -> []) ++
335− [ key ++ "=" ++ attr | (key,attr) <- keyvalAttr ]
335+ [ "numbers=left" | "numberLines" `elem` classes
336+ || "number" `elem` classes
337+ || "number-lines" `elem` classes ] ++
338+ [ (if key == "startFrom"
339+ then "firstnumber"
340+ else key) ++ "=" ++ attr |
341+ (key,attr) <- keyvalAttr ]
336342 else []
337343 printParams
338344 | null params = empty
339− | otherwise = brackets $ hsep (intersperse "," (map text params))
345+ | otherwise = brackets $ hcat (intersperse ", " (map text params))
340346 return $ flush ("\\begin{lstlisting}" <> printParams $$ text str $$
341347 "\\end{lstlisting}") $$ cr
342348 highlightedCodeBlock =