aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-03-04 09:50:11 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-03-04 09:50:11 -0800
commit3692e371a75483398b6844cb289b09f311b4c2c1 (patch)
tree498cc17f3dc9563087532ec195bc2c9eb13cdff9
parent0bbee1bcf68bfb7d19b1d4230292004670286ed2 (diff)
downloadpandoc-3692e371a75483398b6844cb289b09f311b4c2c1.tar.gz
LaTeX reader: Read optional attributes in lstlisting environment.
We convert these to pandoc standard names, e.g. "numberLines" for "numbers=left", "startFrom=100" from "firstnumber=100". Still need to add code to convert the language names.
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index da21b67ea..887b17068 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -768,6 +768,20 @@ verbCmd = do
rest <- getInput
return (r, rest)
+keyval :: LP (String, String)
+keyval = try $ do
+ key <- many1 alphaNum
+ char '='
+ val <- many1 alphaNum
+ skipMany spaceChar
+ optional (char ',')
+ skipMany spaceChar
+ return (key, val)
+
+
+keyvals :: LP [(String, String)]
+keyvals = try $ char '[' *> manyTill keyval (char ']')
+
verbatimEnv :: LP (String, String)
verbatimEnv = do
(_,r) <- withRaw $ do
@@ -804,7 +818,14 @@ environments = M.fromList
verbEnv "code"))
, ("verbatim", codeBlock <$> (verbEnv "verbatim"))
, ("Verbatim", codeBlock <$> (verbEnv "Verbatim"))
- , ("lstlisting", codeBlock <$> (verbEnv "lstlisting"))
+ , ("lstlisting", do options <- option [] keyvals
+ let classes = [ "numberLines" |
+ lookup "numbers" options == Just "left" ]
+ let kvs = [ (if k == "firstnumber"
+ then "startFrom"
+ else k, v) | (k,v) <- options ]
+ let attr = ("",classes,kvs)
+ codeBlockWith attr <$> (verbEnv "lstlisting"))
, ("minted", liftA2 (\l c -> codeBlockWith ("",[l],[]) c)
(grouped (many1 $ satisfy (/= '}'))) (verbEnv "minted"))
, ("obeylines", parseFromString