aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pandoc.cabal3
-rw-r--r--pandoc.hs2
-rw-r--r--src/Text/Pandoc/Highlighting.hs70
-rw-r--r--src/Text/Pandoc/Writers/LaTeX.hs61
-rw-r--r--tests/Tests/Writers/HTML.hs2
5 files changed, 78 insertions, 60 deletions
diff --git a/pandoc.cabal b/pandoc.cabal
index 621bb3b00..6494db741 100644
--- a/pandoc.cabal
+++ b/pandoc.cabal
@@ -272,7 +272,6 @@ Library
Text.Pandoc.Options,
Text.Pandoc.Pretty,
Text.Pandoc.Shared,
- Text.Pandoc.Highlighting,
Text.Pandoc.Readers.HTML,
Text.Pandoc.Readers.LaTeX,
Text.Pandoc.Readers.Markdown,
@@ -312,6 +311,7 @@ Library
Text.Pandoc.UUID,
Text.Pandoc.ImageSize,
Text.Pandoc.Slides,
+ Text.Pandoc.Highlighting,
Paths_pandoc
Buildable: True
@@ -375,6 +375,7 @@ Test-Suite test-pandoc
directory >= 1 && < 1.3,
filepath >= 1.1 && < 1.4,
process >= 1 && < 1.2,
+ highlighting-kate >= 0.5.3.7 && < 0.6,
Diff >= 0.2 && < 0.4,
test-framework >= 0.3 && < 0.9,
test-framework-hunit >= 0.2 && < 0.4,
diff --git a/pandoc.hs b/pandoc.hs
index c777a3065..6a6094ced 100644
--- a/pandoc.hs
+++ b/pandoc.hs
@@ -37,7 +37,7 @@ import Text.Pandoc.Shared ( tabFilter, readDataFileUTF8, safeRead,
headerShift, normalize, err, warn )
import Text.Pandoc.XML ( toEntities, fromEntities )
import Text.Pandoc.SelfContained ( makeSelfContained )
-import Text.Pandoc.Highlighting ( languages, Style, tango, pygments,
+import Text.Highlighting.Kate ( languages, Style, tango, pygments,
espresso, zenburn, kate, haddock, monochrome )
import System.Environment ( getArgs, getProgName )
import System.Exit ( exitWith, ExitCode (..) )
diff --git a/src/Text/Pandoc/Highlighting.hs b/src/Text/Pandoc/Highlighting.hs
index 95df88099..be600fbcd 100644
--- a/src/Text/Pandoc/Highlighting.hs
+++ b/src/Text/Pandoc/Highlighting.hs
@@ -45,6 +45,8 @@ module Text.Pandoc.Highlighting ( languages
, monochrome
, haddock
, Style
+ , fromListingsLanguage
+ , toListingsLanguage
) where
import Text.Pandoc.Definition
import Text.Pandoc.Shared (safeRead)
@@ -52,6 +54,8 @@ import Text.Highlighting.Kate
import Data.List (find)
import Data.Maybe (fromMaybe)
import Data.Char (toLower)
+import qualified Data.Map as M
+import Control.Applicative ((<|>))
lcLanguages :: [String]
lcLanguages = map (map toLower) languages
@@ -76,3 +80,69 @@ highlight formatter (_, classes, keyvals) rawCode =
containerClasses = classes }
$ highlightAs language rawCode
+-- Functions for correlating latex listings package's language names
+-- with highlighting-kate language names:
+
+langToListingsMap :: M.Map String String
+langToListingsMap = M.fromList langsList
+
+listingsToLangMap :: M.Map String String
+listingsToLangMap = M.fromList $ reverse langsList
+
+langsList :: [(String, String)]
+langsList = [("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 name from highlighting-kate language name.
+toListingsLanguage :: String -> Maybe String
+toListingsLanguage lang = (if lang `elem` listingsLangs
+ then Just lang
+ else Nothing) <|>
+ M.lookup (map toLower lang) langToListingsMap
+
+-- Determine highlighting-kate language name from listings language name.
+fromListingsLanguage :: String -> Maybe String
+fromListingsLanguage lang = M.lookup lang listingsToLangMap
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index 2e9f2f028..3ab107d68 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -35,18 +35,18 @@ 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 Control.Monad.State
import Text.Pandoc.Pretty
import System.FilePath (dropExtension)
import Text.Pandoc.Slides
import Text.Pandoc.Highlighting (highlight, styleToLaTeX,
- formatLaTeXInline, formatLaTeXBlock)
+ formatLaTeXInline, formatLaTeXBlock,
+ toListingsLanguage)
data WriterState =
WriterState { stInNote :: Bool -- true if we're in a note
@@ -762,60 +762,7 @@ citationsToBiblatex (c:cs) = do
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
+getListingsLanguage (x:xs) = toListingsLanguage x <|> getListingsLanguage xs
diff --git a/tests/Tests/Writers/HTML.hs b/tests/Tests/Writers/HTML.hs
index dad1d0880..1693f2fc1 100644
--- a/tests/Tests/Writers/HTML.hs
+++ b/tests/Tests/Writers/HTML.hs
@@ -6,7 +6,7 @@ import Text.Pandoc.Builder
import Text.Pandoc
import Tests.Helpers
import Tests.Arbitrary()
-import Text.Pandoc.Highlighting (languages) -- null if no hl support
+import Text.Highlighting.Kate (languages) -- null if no hl support
html :: (ToString a, ToPandoc a) => a -> String
html = writeHtmlString def{ writerWrapText = False } . toPandoc