diff options
author | John MacFarlane <jgm@berkeley.edu> | 2019-06-08 12:25:34 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2019-06-08 12:25:34 -0700 |
commit | d1df2b2783a6fdbe0315cf69d2306271254960f3 (patch) | |
tree | 27dfcd934abc5f3411c5fa088da9756dd34a9661 | |
parent | 931030d95d85ca3059516d15ef1b632131a84a20 (diff) | |
download | pandoc-d1df2b2783a6fdbe0315cf69d2306271254960f3.tar.gz |
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.
-rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 20 | ||||
-rw-r--r-- | test/command/5540.md | 8 |
2 files changed, 21 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 4f24dd3d0..6734bc32d 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -530,10 +530,16 @@ verbTok stopchar = do : totoks (incSourceColumn pos (i + 1)) (T.drop 1 t2) ++ inp return $ Tok pos toktype t1 +listingsLanguage :: [(String, String)] -> Maybe String +listingsLanguage opts = + case lookup "language" opts of + Nothing -> Nothing + Just l -> fromListingsLanguage l `mplus` Just l + dolstinline :: PandocMonad m => LP m Inlines dolstinline = do options <- option [] keyvals - let classes = maybeToList $ lookup "language" options >>= fromListingsLanguage + let classes = maybeToList $ listingsLanguage options doinlinecode classes domintinline :: PandocMonad m => LP m Inlines @@ -2041,8 +2047,7 @@ parseListingsOptions options = else k, v) | (k,v) <- options ] classes = [ "numberLines" | lookup "numbers" options == Just "left" ] - ++ maybeToList (lookup "language" options - >>= fromListingsLanguage) + ++ maybeToList (listingsLanguage options) in (fromMaybe "" (lookup "label" options), classes, kvs) inputListing :: PandocMonad m => LP m Blocks @@ -2058,15 +2063,16 @@ inputListing = do report $ CouldNotLoadIncludeFile f pos return [] let (ident,classes,kvs) = parseListingsOptions options - let language = case lookup "language" options >>= fromListingsLanguage of - Just l -> [l] - Nothing -> take 1 $ languagesByExtension (takeExtension f) + let classes' = + (case listingsLanguage options of + Nothing -> (take 1 (languagesByExtension (takeExtension f)) ++) + Just _ -> id) classes let firstline = fromMaybe 1 $ lookup "firstline" options >>= safeRead let lastline = fromMaybe (length codeLines) $ lookup "lastline" options >>= safeRead let codeContents = intercalate "\n" $ take (1 + lastline - firstline) $ drop (firstline - 1) codeLines - return $ codeBlockWith (ident,ordNub (classes ++ language),kvs) codeContents + return $ codeBlockWith (ident,classes',kvs) codeContents -- lists diff --git a/test/command/5540.md b/test/command/5540.md new file mode 100644 index 000000000..802a88d9d --- /dev/null +++ b/test/command/5540.md @@ -0,0 +1,8 @@ +``` +% pandoc -f latex -t native +\begin{lstlisting}[language=myfunnylanguage] +Stay pure! +\end{lstlisting} +^D +[CodeBlock ("",["myfunnylanguage"],[("language","myfunnylanguage")]) "Stay pure!"] +``` |