git.iko.soy/typeable/pandoc
on master help sign in
Allow a theme file as argument to `--highlight-style`.

Also include a sample, `default.theme`, in `data/`.

commit420e3eb26e6ac8b9854d41ede1bbd78e1c23fa66 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 1 Apr 2017, 22:27 (10 years ago) parent1c84a03
3 files changed+17−3
MANUAL.txt+7−1 pandoc.cabal+2 src/Text/Pandoc/App.hs+8−2
MANUAL.txt+7−1
@@ -630,7 +630,7 @@ General writer options
630630: Disables syntax highlighting for code blocks and inlines, even when
631631 a language attribute is given.
632632
633−`--highlight-style=`*STYLE*
633+`--highlight-style=`*STYLE*|*FILE*
634634
635635: Specifies the coloring style to be used in highlighted source code.
636636 Options are `pygments` (the default), `kate`, `monochrome`,
@@ -639,6 +639,12 @@ General writer options
639639 [Syntax highlighting], below. See also
640640 `--list-highlight-styles`.
641641
642+ Instead of a *STYLE* name, a JSON file with extension
643+ `.theme` may be supplied. This will be parsed as a KDE
644+ syntax highlighting theme and (if valid) used as the
645+ highlighting style. To see a sample theme that can be
646+ modified, `pandoc --print-default-data-file default.theme`.
647+
642648`--syntax-definition=`*FILE*
643649
644650: Instructs pandoc to load a KDE XML syntax definition file,
pandoc.cabal+2
@@ -109,6 +109,8 @@ Data-Files:
109109 data/sample.lua
110110 -- pandoc lua module
111111 data/pandoc.lua
112+ -- sample highlighting theme
113+ data/default.theme
112114 -- bash completion template
113115 data/bash_completion.tpl
114116 -- jats csl
src/Text/Pandoc/App.hs+8−2
@@ -56,7 +56,7 @@ import Data.Yaml (decode)
5656import qualified Data.Yaml as Yaml
5757import Network.URI (URI (..), isURI, parseURI)
5858import Paths_pandoc (getDataDir)
59−import Skylighting (Style, Syntax (..), defaultSyntaxMap)
59+import Skylighting (Style, Syntax (..), defaultSyntaxMap, parseTheme)
6060import Skylighting.Parser (missingIncludes, parseSyntaxDefinition,
6161 addSyntaxDefinition)
6262import System.Console.GetOpt
@@ -802,7 +802,13 @@ writerFn f = liftIO . UTF8.writeFile f
802802
803803lookupHighlightStyle :: Maybe String -> IO (Maybe Style)
804804lookupHighlightStyle Nothing = return Nothing
805−lookupHighlightStyle (Just s) =
805+lookupHighlightStyle (Just s)
806+ | takeExtension s == ".theme" = -- attempt to load KDE theme
807+ do contents <- B.readFile s
808+ case parseTheme contents of
809+ Left _ -> err 69 $ "Could not read highlighting theme " ++ s
810+ Right sty -> return (Just sty)
811+ | otherwise =
806812 case lookup (map toLower s) highlightingStyles of
807813 Just sty -> return (Just sty)
808814 Nothing -> err 68 $ "Unknown highlight-style " ++ s