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
This commit is contained in:
John MacFarlane 2013-03-05 22:09:42 -08:00
parent fd657986cc
commit 3b63cb0903
5 changed files with 78 additions and 60 deletions

View file

@ -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,

View file

@ -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 (..) )

View file

@ -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

View file

@ -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

View file

@ -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