Skip to content

Commit 8a3e3e7

Browse files
committed
add highlighting-css-dark option
1 parent 7b2747e commit 8a3e3e7

File tree

6 files changed

+35
-4
lines changed

6 files changed

+35
-4
lines changed

MANUAL.txt

+11
Original file line numberDiff line numberDiff line change
@@ -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
62026208
used to do the highlighting). To see a list of highlight styles,
62036209
type `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+
62056215
If you are not satisfied with the predefined styles, you can
62066216
use `--print-highlight-style` to generate a JSON `.theme` file which
62076217
can 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)
62236233
To 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
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -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
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import GHC.Generics (Generic)
4545
import Skylighting (SyntaxMap, defaultSyntaxMap)
4646
import Text.DocTemplates (Context(..), Template)
4747
import Text.Pandoc.Extensions
48-
import Text.Pandoc.Highlighting (Style, pygments)
48+
import Text.Pandoc.Highlighting (Style, breezeDark, pygments)
4949
import Text.Pandoc.Shared (camelCaseStrToHyphenated)
5050
import 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

+4-2
Original file line numberDiff line numberDiff line change
@@ -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 .

0 commit comments

Comments
 (0)