git.iko.soy/typeable/pandoc
on master help sign in
add highlighting-css-dark option
commit0e489c511578b9e131f94a3ff268209d4d6646a7 authormb21 <mb21@users.noreply.github.com> dateSat 20 Mar 2021, 10:29 (6 years ago) parent7b2747e
6 files changed+37−6
MANUAL.txt+11 src/Text/Pandoc/App/CommandLineOptions.hs+11−1 src/Text/Pandoc/App/Opt.hs+4 src/Text/Pandoc/App/OutputSettings.hs+2 src/Text/Pandoc/Options.hs+3−1 src/Text/Pandoc/Writers/HTML.hs+6−4
MANUAL.txt+11
@@ -837,6 +837,12 @@ header when requesting a document from a URL:
837837 To generate the JSON version of an existing style,
838838 use `--print-highlight-style`.
839839
840+`--highlight-style-dark=`*STYLE*|*FILE*
841+
842+: Specifies the coloring style to be used in highlighted source code
843+ in [dark mode] for HTML-based output formats. The default is `breezeDark`.
844+ See `--highlight-style` for more information.
845+
840846`--print-highlight-style=`*STYLE*|*FILE*
841847
842848: Prints a JSON version of a highlighting style, which can
@@ -6202,6 +6208,10 @@ scheme used by the Python library pygments (though pygments is not actually
62026208used to do the highlighting). To see a list of highlight styles,
62036209type `pandoc --list-highlight-styles`.
62046210
6211+For HTML-based output formats, the color scheme used for [dark mode]
6212+can be selected using the `--highlight-style-dark` option.
6213+It defaults to `breezeDark`.
6214+
62056215If you are not satisfied with the predefined styles, you can
62066216use `--print-highlight-style` to generate a JSON `.theme` file which
62076217can be modified and used as the argument to `--highlight-style`. To
@@ -6223,6 +6233,7 @@ definitions](https://github.com/KDE/syntax-highlighting/tree/master/data/syntax)
62236233To disable highlighting, use the `--no-highlight` option.
62246234
62256235[skylighting]: https://github.com/jgm/skylighting
6236+[dark mode]: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme
62266237
62276238# Custom Styles
62286239
src/Text/Pandoc/App/CommandLineOptions.hs+11−1
@@ -319,7 +319,9 @@ options =
319319
320320 , Option "" ["no-highlight"]
321321 (NoArg
322− (\opt -> return opt { optHighlightStyle = Nothing }))
322+ (\opt -> return opt { optHighlightStyle = Nothing
323+ , optHighlightStyleDark = Nothing
324+ }))
323325 "" -- "Don't highlight source code"
324326
325327 , Option "" ["highlight-style"]
@@ -330,6 +332,14 @@ options =
330332 "STYLE|FILE")
331333 "" -- "Style for highlighted code"
332334
335+ , Option "" ["highlight-style-dark"]
336+ (ReqArg
337+ (\arg opt ->
338+ return opt{ optHighlightStyleDark = Just $
339+ T.pack $ normalizePath arg })
340+ "STYLE|FILE")
341+ "" -- "Style for highlighted code in dark mode"
342+
333343 , Option "" ["syntax-definition"]
334344 (ReqArg
335345 (\arg opt -> do
src/Text/Pandoc/App/Opt.hs+4
@@ -107,6 +107,7 @@ data Opt = Opt
107107 , optSelfContained :: Bool -- ^ Make HTML accessible offline
108108 , optHtmlQTags :: Bool -- ^ Use <q> tags in HTML
109109 , optHighlightStyle :: Maybe Text -- ^ Style to use for highlighted code
110+ , optHighlightStyleDark :: Maybe Text -- ^ Style to use for highlighted code in dark mode
110111 , optSyntaxDefinitions :: [FilePath] -- ^ xml syntax defs to load
111112 , optTopLevelDivision :: TopLevelDivision -- ^ Type of the top-level divisions
112113 , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
@@ -417,6 +418,8 @@ doOpt (k',v) = do
417418 parseYAML v >>= \x -> return (\o -> o{ optHtmlQTags = x })
418419 "highlight-style" ->
419420 parseYAML v >>= \x -> return (\o -> o{ optHighlightStyle = x })
421+ "highlight-style-dark" ->
422+ parseYAML v >>= \x -> return (\o -> o{ optHighlightStyleDark = x })
420423 "syntax-definition" ->
421424 (parseYAML v >>= \x ->
422425 return (\o -> o{ optSyntaxDefinitions =
@@ -620,6 +623,7 @@ defaultOpts = Opt
620623 , optSelfContained = False
621624 , optHtmlQTags = False
622625 , optHighlightStyle = Just "pygments"
626+ , optHighlightStyleDark = Just "breezeDark"
623627 , optSyntaxDefinitions = []
624628 , optTopLevelDivision = TopLevelDefault
625629 , optHTMLMathMethod = PlainMath
src/Text/Pandoc/App/OutputSettings.hs+2
@@ -109,6 +109,7 @@ optToOutputSettings opts = do
109109 (optSyntaxDefinitions opts)
110110
111111 hlStyle <- traverse (lookupHighlightStyle . T.unpack) $ optHighlightStyle opts
112+ hlStyleDark <- traverse (lookupHighlightStyle . T.unpack) $ optHighlightStyleDark opts
112113
113114 let setVariableM k v = return . setVariable k v
114115
@@ -202,6 +203,7 @@ optToOutputSettings opts = do
202203 , writerListings = optListings opts
203204 , writerSlideLevel = optSlideLevel opts
204205 , writerHighlightStyle = hlStyle
206+ , writerHighlightStyleDark = hlStyleDark
205207 , writerSetextHeaders = optSetextHeaders opts
206208 , writerEpubSubdirectory = T.pack $ optEpubSubdirectory opts
207209 , writerEpubMetadata = epubMetadata
src/Text/Pandoc/Options.hs+3−1
@@ -45,7 +45,7 @@ import GHC.Generics (Generic)
4545import Skylighting (SyntaxMap, defaultSyntaxMap)
4646import Text.DocTemplates (Context(..), Template)
4747import Text.Pandoc.Extensions
48−import Text.Pandoc.Highlighting (Style, pygments)
48+import Text.Pandoc.Highlighting (Style, breezeDark, pygments)
4949import Text.Pandoc.Shared (camelCaseStrToHyphenated)
5050import Data.Aeson.TH (deriveJSON, defaultOptions, Options(..),
5151 SumEncoding(..))
@@ -255,6 +255,7 @@ data WriterOptions = WriterOptions
255255 , writerListings :: Bool -- ^ Use listings package for code
256256 , writerHighlightStyle :: Maybe Style -- ^ Style to use for highlighting
257257 -- (Nothing = no highlighting)
258+ , writerHighlightStyleDark :: Maybe Style -- ^ Style to use for highlighting dark mode
258259 , writerSetextHeaders :: Bool -- ^ Use setext headers for levels 1-2 in markdown
259260 , writerEpubSubdirectory :: Text -- ^ Subdir for epub in OCF
260261 , writerEpubMetadata :: Maybe Text -- ^ Metadata to include in EPUB
@@ -290,6 +291,7 @@ instance Default WriterOptions where
290291 , writerTopLevelDivision = TopLevelDefault
291292 , writerListings = False
292293 , writerHighlightStyle = Just pygments
294+ , writerHighlightStyleDark = Just breezeDark
293295 , writerSetextHeaders = False
294296 , writerEpubSubdirectory = "EPUB"
295297 , writerEpubMetadata = Nothing
src/Text/Pandoc/Writers/HTML.hs+6−4
@@ -45,8 +45,8 @@ import Text.Blaze.Internal (MarkupM (Empty), customLeaf, customParent)
4545import Text.DocTemplates (FromContext (lookupContext), Context (..))
4646import Text.Blaze.Html hiding (contents)
4747import Text.Pandoc.Definition
48−import Text.Pandoc.Highlighting (breezeDark, formatHtmlBlock, formatHtmlInline,
49− highlight, styleToCss)
48+import Text.Pandoc.Highlighting (formatHtmlBlock, formatHtmlInline, highlight,
49+ styleToCss)
5050import Text.Pandoc.ImageSize
5151import Text.Pandoc.Options
5252import Text.Pandoc.Shared
@@ -324,8 +324,10 @@ pandocToHtml opts (Pandoc meta blocks) = do
324324 Nothing -> id
325325 else id) .
326326 (if stHighlighting st
327− then defField "highlighting-css-dark"
328− (T.pack $ styleToCss breezeDark)
327+ then case writerHighlightStyleDark opts of
328+ Just sty -> defField "highlighting-css-dark"
329+ (T.pack $ styleToCss sty)
330+ Nothing -> id
329331 else id) .
330332 (if stCsl st
331333 then defField "csl-css" True .