Convert highlighting-kate language to listings language
if --listings is used. Closes #704.
This commit is contained in:
parent
820a9143e7
commit
4aea26e8e1
1 changed files with 63 additions and 19 deletions
|
@ -35,11 +35,13 @@ import Text.Pandoc.Shared
|
|||
import Text.Pandoc.Options
|
||||
import Text.Pandoc.Templates
|
||||
import Text.Printf ( printf )
|
||||
import qualified Data.Map as M
|
||||
import Network.URI ( isAbsoluteURI, unEscapeString )
|
||||
import Data.List ( (\\), isSuffixOf, isInfixOf,
|
||||
isPrefixOf, intercalate, intersperse )
|
||||
import Data.Char ( toLower, isPunctuation )
|
||||
import Control.Monad.State
|
||||
import Control.Applicative ((<|>))
|
||||
import Text.Pandoc.Pretty
|
||||
import System.FilePath (dropExtension)
|
||||
import Text.Pandoc.Slides
|
||||
|
@ -327,25 +329,9 @@ blockToLaTeX (CodeBlock (_,classes,keyvalAttr) str) = do
|
|||
listingsCodeBlock = do
|
||||
st <- get
|
||||
let params = if writerListings (stOptions st)
|
||||
then take 1
|
||||
[ "language=" ++ lang | lang <- classes
|
||||
, lang `elem` ["ABAP","IDL","Plasm","ACSL","inform"
|
||||
,"POV","Ada","Java","Prolog","Algol"
|
||||
,"JVMIS","Promela","Ant","ksh","Python"
|
||||
,"Assembler","Lisp","R","Awk","Logo"
|
||||
,"Reduce","bash","make","Rexx","Basic"
|
||||
,"Mathematica","RSL","C","Matlab","Ruby"
|
||||
,"C++","Mercury","S","Caml","MetaPost"
|
||||
,"SAS","Clean","Miranda","Scilab","Cobol"
|
||||
,"Mizar","sh","Comal","ML","SHELXL","csh"
|
||||
,"Modula-2","Simula","Delphi","MuPAD"
|
||||
,"SQL","Eiffel","NASTRAN","tcl","Elan"
|
||||
,"Oberon-2","TeX","erlang","OCL"
|
||||
,"VBScript","Euphoria","Octave","Verilog"
|
||||
,"Fortran","Oz","VHDL","GCL","Pascal"
|
||||
,"VRML","Gnuplot","Perl","XML","Haskell"
|
||||
,"PHP","XSLT","HTML","PL/I"]
|
||||
] ++
|
||||
then (case getListingsLanguage classes of
|
||||
Just l -> [ "language=" ++ l ]
|
||||
Nothing -> []) ++
|
||||
[ key ++ "=" ++ attr | (key,attr) <- keyvalAttr ]
|
||||
else []
|
||||
printParams
|
||||
|
@ -755,3 +741,61 @@ citationsToBiblatex (c:cs) = do
|
|||
= citeArguments p s k
|
||||
|
||||
citationsToBiblatex _ = return empty
|
||||
|
||||
-- correlate pandoc language names with listings names
|
||||
langsMap :: M.Map String String
|
||||
langsMap = M.fromList
|
||||
[("ada","Ada")
|
||||
,("java","Java")
|
||||
,("prolog","Prolog")
|
||||
,("python","Python")
|
||||
,("gnuassembler","Assembler")
|
||||
,("commonlisp","Lisp")
|
||||
,("r","R")
|
||||
,("awk","Awk")
|
||||
,("bash","bash")
|
||||
,("makefile","make")
|
||||
,("c","C")
|
||||
,("matlab","Matlab")
|
||||
,("ruby","Ruby")
|
||||
,("cpp","C++")
|
||||
,("ocaml","Caml")
|
||||
,("modula2","Modula-2")
|
||||
,("sql","SQL")
|
||||
,("eiffel","Eiffel")
|
||||
,("tcl","tcl")
|
||||
,("erlang","erlang")
|
||||
,("verilog","Verilog")
|
||||
,("fortran","Fortran")
|
||||
,("vhdl","VHDL")
|
||||
,("pascal","Pascal")
|
||||
,("perl","Perl")
|
||||
,("xml","XML")
|
||||
,("haskell","Haskell")
|
||||
,("php","PHP")
|
||||
,("xslt","XSLT")
|
||||
,("html","HTML")
|
||||
]
|
||||
|
||||
listingsLangs :: [String]
|
||||
listingsLangs = ["Ada","Java","Prolog","Algol","JVMIS","Promela",
|
||||
"Ant","ksh","Python","Assembler","Lisp","R","Awk",
|
||||
"Logo","Reduce","bash","make","Rexx","Basic",
|
||||
"Mathematica","RSL","C","Matlab","Ruby","C++",
|
||||
"Mercury","S","Caml","MetaPost","SAS","Clean",
|
||||
"Miranda","Scilab","Cobol","Mizar","sh","Comal",
|
||||
"ML","SHELXL","csh","Modula-2","Simula","Delphi",
|
||||
"MuPAD","SQL","Eiffel","NASTRAN","tcl","Elan",
|
||||
"Oberon-2","TeX","erlang","OCL","VBScript","Euphoria",
|
||||
"Octave","Verilog","Fortran","Oz","VHDL","GCL",
|
||||
"Pascal","VRML","Gnuplot","Perl","XML","Haskell",
|
||||
"PHP","XSLT","HTML","PL/I"]
|
||||
|
||||
-- Determine listings language from list of class attributes.
|
||||
getListingsLanguage :: [String] -> Maybe String
|
||||
getListingsLanguage [] = Nothing
|
||||
getListingsLanguage (x:xs) = (if x `elem` listingsLangs
|
||||
then Just x
|
||||
else Nothing) <|>
|
||||
M.lookup (map toLower x) langsMap <|>
|
||||
getListingsLanguage xs
|
||||
|
|
Loading…
Reference in a new issue