git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: pass through unknown listings language as class.

Previously if the language was not in the list of listings- supported languages, it would not be added as a class, so custom syntax highlighting could not be used. Closes #5540.

commitd1df2b2783a6fdbe0315cf69d2306271254960f3 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 8 Jun 2019, 12:25 (7 years ago) parent931030d
2 files changed+21−7
src/Text/Pandoc/Readers/LaTeX.hs+13−7 test/command/5540.md+8
src/Text/Pandoc/Readers/LaTeX.hs+13−7
@@ -530,10 +530,16 @@ verbTok stopchar = do
530530 : totoks (incSourceColumn pos (i + 1)) (T.drop 1 t2) ++ inp
531531 return $ Tok pos toktype t1
532532
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+
533539dolstinline :: PandocMonad m => LP m Inlines
534540dolstinline = do
535541 options <- option [] keyvals
536− let classes = maybeToList $ lookup "language" options >>= fromListingsLanguage
542+ let classes = maybeToList $ listingsLanguage options
537543 doinlinecode classes
538544
539545domintinline :: PandocMonad m => LP m Inlines
@@ -2041,8 +2047,7 @@ parseListingsOptions options =
20412047 else k, v) | (k,v) <- options ]
20422048 classes = [ "numberLines" |
20432049 lookup "numbers" options == Just "left" ]
2044− ++ maybeToList (lookup "language" options
2045− >>= fromListingsLanguage)
2050+ ++ maybeToList (listingsLanguage options)
20462051 in (fromMaybe "" (lookup "label" options), classes, kvs)
20472052
20482053inputListing :: PandocMonad m => LP m Blocks
@@ -2058,15 +2063,16 @@ inputListing = do
20582063 report $ CouldNotLoadIncludeFile f pos
20592064 return []
20602065 let (ident,classes,kvs) = parseListingsOptions options
2061− let language = case lookup "language" options >>= fromListingsLanguage of
2062− Just l -> [l]
2063− Nothing -> take 1 $ languagesByExtension (takeExtension f)
2066+ let classes' =
2067+ (case listingsLanguage options of
2068+ Nothing -> (take 1 (languagesByExtension (takeExtension f)) ++)
2069+ Just _ -> id) classes
20642070 let firstline = fromMaybe 1 $ lookup "firstline" options >>= safeRead
20652071 let lastline = fromMaybe (length codeLines) $
20662072 lookup "lastline" options >>= safeRead
20672073 let codeContents = intercalate "\n" $ take (1 + lastline - firstline) $
20682074 drop (firstline - 1) codeLines
2069− return $ codeBlockWith (ident,ordNub (classes ++ language),kvs) codeContents
2075+ return $ codeBlockWith (ident,classes',kvs) codeContents
20702076
20712077-- lists
20722078
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+```