@@ -57,6 +57,8 @@ import qualified Data.Yaml as Yaml
5757import Network.URI (URI (..), isURI, parseURI)
5858import Paths_pandoc (getDataDir)
5959import Skylighting (Style, Syntax (..), defaultSyntaxMap)
60+import Skylighting.Parser (missingIncludes, parseSyntaxDefinition,
61+ addSyntaxDefinition)
6062import System.Console.GetOpt
6163import System.Directory (Permissions (..), doesFileExist, findExecutable,
6264 getAppUserDataDirectory, getPermissions)
@@ -299,6 +301,21 @@ convertWithOpts opts = do
299301 }
300302
301303 highlightStyle <- lookupHighlightStyle $ optHighlightStyle opts
304+ let addSyntaxMap existingmap f = do
305+ res <- parseSyntaxDefinition f
306+ case res of
307+ Left errstr -> err 67 errstr
308+ Right syn -> return $ addSyntaxDefinition syn existingmap
309+
310+ syntaxMap <- foldM addSyntaxMap defaultSyntaxMap
311+ (optSyntaxDefinitions opts)
312+
313+ case missingIncludes (M.elems syntaxMap) of
314+ [] -> return ()
315+ xs -> err 73 $ "Missing syntax definitions:\n" ++
316+ unlines (map
317+ (\(syn,dep) -> (T.unpack syn ++ " requires " ++
318+ T.unpack dep ++ " through IncludeRules.")) xs)
302319
303320 let writerOptions = def { writerTemplate = templ,
304321 writerVariables = variables,
@@ -330,7 +347,8 @@ convertWithOpts opts = do
330347 writerEpubChapterLevel = optEpubChapterLevel opts,
331348 writerTOCDepth = optTOCDepth opts,
332349 writerReferenceDoc = optReferenceDoc opts,
333− writerLaTeXArgs = optLaTeXEngineArgs opts
350+ writerLaTeXArgs = optLaTeXEngineArgs opts,
351+ writerSyntaxMap = syntaxMap
334352 }
335353
336354
@@ -507,6 +525,7 @@ data Opt = Opt
507525 , optSelfContained :: Bool -- ^ Make HTML accessible offline
508526 , optHtmlQTags :: Bool -- ^ Use <q> tags in HTML
509527 , optHighlightStyle :: Maybe String -- ^ Style to use for highlighted code
528+ , optSyntaxDefinitions :: [FilePath] -- ^ xml syntax defs to load
510529 , optTopLevelDivision :: TopLevelDivision -- ^ Type of the top-level divisions
511530 , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
512531 , optAbbreviations :: Maybe FilePath -- ^ Path to abbrevs file
@@ -574,6 +593,7 @@ defaultOpts = Opt
574593 , optSelfContained = False
575594 , optHtmlQTags = False
576595 , optHighlightStyle = Just "pygments"
596+ , optSyntaxDefinitions = []
577597 , optTopLevelDivision = TopLevelDefault
578598 , optHTMLMathMethod = PlainMath
579599 , optAbbreviations = Nothing
@@ -987,6 +1007,13 @@ options =
9871007 "STYLE")
9881008 "" -- "Style for highlighted code"
9891009
1010+ , Option "" ["syntax-definition"]
1011+ (ReqArg
1012+ (\arg opt -> return opt{ optSyntaxDefinitions = arg :
1013+ optSyntaxDefinitions opt })
1014+ "FILE")
1015+ "" -- "Syntax definition (xml) file"
1016+
9901017 , Option "H" ["include-in-header"]
9911018 (ReqArg
9921019 (\arg opt -> return opt{ optIncludeInHeader =