git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: pass through unknown listings language as class.
d1df2b2John MacFarlane
src/Text/Pandoc/Readers/LaTeX.hs+13−7
@@ -530,10 +530,16 @@ verbTok stopchar = do
530 : totoks (incSourceColumn pos (i + 1)) (T.drop 1 t2) ++ inp
530 : totoks (incSourceColumn pos (i + 1)) (T.drop 1 t2) ++ inp
531 return $ Tok pos toktype t1
531 return $ Tok pos toktype t1
532
532
533+listingsLanguage :: [(String, String)] -> Maybe String
534+listingsLanguage opts =
535+ case lookup "language" opts of
536+ Nothing -> Nothing
537+ Just l -> fromListingsLanguage l `mplus` Just l
538+
533dolstinline :: PandocMonad m => LP m Inlines
539dolstinline :: PandocMonad m => LP m Inlines
534dolstinline = do
540dolstinline = do
535 options <- option [] keyvals
541 options <- option [] keyvals
536− let classes = maybeToList $ lookup "language" options >>= fromListingsLanguage
542+ let classes = maybeToList $ listingsLanguage options
537 doinlinecode classes
543 doinlinecode classes
538
544
539domintinline :: PandocMonad m => LP m Inlines
545domintinline :: PandocMonad m => LP m Inlines
@@ -2041,8 +2047,7 @@ parseListingsOptions options =
2041 else k, v) | (k,v) <- options ]
2047 else k, v) | (k,v) <- options ]
2042 classes = [ "numberLines" |
2048 classes = [ "numberLines" |
2043 lookup "numbers" options == Just "left" ]
2049 lookup "numbers" options == Just "left" ]
2044− ++ maybeToList (lookup "language" options
2050+ ++ maybeToList (listingsLanguage options)
2045− >>= fromListingsLanguage)
2046 in (fromMaybe "" (lookup "label" options), classes, kvs)
2051 in (fromMaybe "" (lookup "label" options), classes, kvs)
2047
2052
2048inputListing :: PandocMonad m => LP m Blocks
2053inputListing :: PandocMonad m => LP m Blocks
@@ -2058,15 +2063,16 @@ inputListing = do
2058 report $ CouldNotLoadIncludeFile f pos
2063 report $ CouldNotLoadIncludeFile f pos
2059 return []
2064 return []
2060 let (ident,classes,kvs) = parseListingsOptions options
2065 let (ident,classes,kvs) = parseListingsOptions options
2061− let language = case lookup "language" options >>= fromListingsLanguage of
2066+ let classes' =
2062− Just l -> [l]
2067+ (case listingsLanguage options of
2063− Nothing -> take 1 $ languagesByExtension (takeExtension f)
2068+ Nothing -> (take 1 (languagesByExtension (takeExtension f)) ++)
2069+ Just _ -> id) classes
2064 let firstline = fromMaybe 1 $ lookup "firstline" options >>= safeRead
2070 let firstline = fromMaybe 1 $ lookup "firstline" options >>= safeRead
2065 let lastline = fromMaybe (length codeLines) $
2071 let lastline = fromMaybe (length codeLines) $
2066 lookup "lastline" options >>= safeRead
2072 lookup "lastline" options >>= safeRead
2067 let codeContents = intercalate "\n" $ take (1 + lastline - firstline) $
2073 let codeContents = intercalate "\n" $ take (1 + lastline - firstline) $
2068 drop (firstline - 1) codeLines
2074 drop (firstline - 1) codeLines
2069− return $ codeBlockWith (ident,ordNub (classes ++ language),kvs) codeContents
2075+ return $ codeBlockWith (ident,classes',kvs) codeContents
2070
2076
2071-- lists
2077-- lists
2072
2078
test/command/5540.mdnew file+8
@@ -0,0 +1,8 @@
1+```
2+% pandoc -f latex -t native
3+\begin{lstlisting}[language=myfunnylanguage]
4+Stay pure!
5+\end{lstlisting}
6+^D
7+[CodeBlock ("",["myfunnylanguage"],[("language","myfunnylanguage")]) "Stay pure!"]
8+```