From 3b63cb0903baf4bc551d2b63d884c0fa556f11a0 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 5 Mar 2013 22:09:42 -0800 Subject: Hide Text.Pandoc.Highlighting. * Moved code for translating listings language names to highlighting-kate names and back from LaTeX reader to Highlighting. * Text.Pandoc.Highlighting no longer exposed (API change) * Text.Pandoc.Highlighting exports toListingsLang, fromListingsLang --- src/Text/Pandoc/Highlighting.hs | 70 ++++++++++++++++++++++++++++++++++++++++ src/Text/Pandoc/Writers/LaTeX.hs | 61 +++------------------------------- 2 files changed, 74 insertions(+), 57 deletions(-) (limited to 'src/Text') 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 -- cgit v1.2.3