diff --git a/MANUAL.txt b/MANUAL.txt index 569c04781..1534beec2 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -630,7 +630,7 @@ General writer options : Disables syntax highlighting for code blocks and inlines, even when a language attribute is given. -`--highlight-style=`*STYLE* +`--highlight-style=`*STYLE*|*FILE* : Specifies the coloring style to be used in highlighted source code. Options are `pygments` (the default), `kate`, `monochrome`, @@ -639,6 +639,12 @@ General writer options [Syntax highlighting], below. See also `--list-highlight-styles`. + Instead of a *STYLE* name, a JSON file with extension + `.theme` may be supplied. This will be parsed as a KDE + syntax highlighting theme and (if valid) used as the + highlighting style. To see a sample theme that can be + modified, `pandoc --print-default-data-file default.theme`. + `--syntax-definition=`*FILE* : Instructs pandoc to load a KDE XML syntax definition file, diff --git a/pandoc.cabal b/pandoc.cabal index 97216e0eb..16997486a 100644 --- a/pandoc.cabal +++ b/pandoc.cabal @@ -109,6 +109,8 @@ Data-Files: data/sample.lua -- pandoc lua module data/pandoc.lua + -- sample highlighting theme + data/default.theme -- bash completion template data/bash_completion.tpl -- jats csl diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs index dfc8e3559..8f0410f12 100644 --- a/src/Text/Pandoc/App.hs +++ b/src/Text/Pandoc/App.hs @@ -56,7 +56,7 @@ import Data.Yaml (decode) import qualified Data.Yaml as Yaml import Network.URI (URI (..), isURI, parseURI) import Paths_pandoc (getDataDir) -import Skylighting (Style, Syntax (..), defaultSyntaxMap) +import Skylighting (Style, Syntax (..), defaultSyntaxMap, parseTheme) import Skylighting.Parser (missingIncludes, parseSyntaxDefinition, addSyntaxDefinition) import System.Console.GetOpt @@ -802,7 +802,13 @@ writerFn f = liftIO . UTF8.writeFile f lookupHighlightStyle :: Maybe String -> IO (Maybe Style) lookupHighlightStyle Nothing = return Nothing -lookupHighlightStyle (Just s) = +lookupHighlightStyle (Just s) + | takeExtension s == ".theme" = -- attempt to load KDE theme + do contents <- B.readFile s + case parseTheme contents of + Left _ -> err 69 $ "Could not read highlighting theme " ++ s + Right sty -> return (Just sty) + | otherwise = case lookup (map toLower s) highlightingStyles of Just sty -> return (Just sty) Nothing -> err 68 $ "Unknown highlight-style " ++ s