aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2013-01-17 19:47:03 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2013-01-17 19:47:03 -0800
commit4aea26e8e1179a2feb1672256b1b9317d2c3baf8 (patch)
treee7c5a9ea59946a2e16e618ec5d87f8e99f99b78a /src
parent820a9143e76d86f8a9812c29e7c51a1124c75548 (diff)
downloadpandoc-4aea26e8e1179a2feb1672256b1b9317d2c3baf8.tar.gz
Convert highlighting-kate language to listings language
if --listings is used. Closes #704.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs82
1 files changed, 63 insertions, 19 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index 12384ca97..3d3e6ae5d 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -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