git.iko.soy/typeable/pandoc
on master help sign in
Added --print-highlight-style option.

This generates a JSON version of a highlighting style, which can be saved as a .theme file, modified, and used with `--highlight-style`. Closes #4106. Closes #4096.

commit845b6c8670a6d1a11c1a31ec15ec2f0831883cbe authorJohn MacFarlane <jgm@berkeley.edu> dateTue 28 Nov 2017, 13:35 (9 years ago) parent00561b1
2 files changed+36−3
MANUAL.txt+10−2 src/Text/Pandoc/App.hs+26−1
MANUAL.txt+10−2
@@ -685,8 +685,16 @@ General writer options
685685 Instead of a *STYLE* name, a JSON file with extension
686686 `.theme` may be supplied. This will be parsed as a KDE
687687 syntax highlighting theme and (if valid) used as the
688− highlighting style. To see a sample theme that can be
689− modified, `pandoc --print-default-data-file default.theme`.
688+ highlighting style.
689+
690+ To generate the JSON version of an existing style,
691+ use `--print-highlight-style`.
692+
693+`--print-highlight-style=`*STYLE*|*FILE*
694+
695+: Prints a JSON version of a highlighting style, which can
696+ be modified, saved with a `.theme` extension, and used
697+ with `--highlight-style`.
690698
691699`--syntax-definition=`*FILE*
692700
src/Text/Pandoc/App.hs+26−1
@@ -63,7 +63,10 @@ import qualified Data.Yaml as Yaml
6363import GHC.Generics
6464import Network.URI (URI (..), parseURI)
6565import Paths_pandoc (getDataDir)
66−import Skylighting (Style, Syntax (..), defaultSyntaxMap, parseTheme)
66+import Data.Aeson.Encode.Pretty (encodePretty', Config(..), keyOrder,
67+ defConfig, Indent(..), NumberFormat(..))
68+import Skylighting (Style, Syntax (..), defaultSyntaxMap, parseTheme,
69+ pygments)
6770import Skylighting.Parser (addSyntaxDefinition, missingIncludes,
6871 parseSyntaxDefinition)
6972import System.Console.GetOpt
@@ -1047,6 +1050,28 @@ options =
10471050 "FILE")
10481051 "" -- "Print default data file"
10491052
1053+ , Option "" ["print-highlight-style"]
1054+ (ReqArg
1055+ (\arg _ -> do
1056+ sty <- fromMaybe pygments <$>
1057+ lookupHighlightStyle (Just arg)
1058+ B.putStr $ encodePretty'
1059+ defConfig{confIndent = Spaces 4
1060+ ,confCompare = keyOrder
1061+ (map T.pack
1062+ ["text-color"
1063+ ,"background-color"
1064+ ,"line-numbers"
1065+ ,"bold"
1066+ ,"italic"
1067+ ,"underline"
1068+ ,"text-styles"])
1069+ ,confNumFormat = Generic
1070+ ,confTrailingNewline = True} sty
1071+ exitSuccess)
1072+ "STYLE|FILE")
1073+ "" -- "Print default template for FORMAT"
1074+
10501075 , Option "" ["dpi"]
10511076 (ReqArg
10521077 (\arg opt ->