Skip to content

Commit

Permalink
add highlighting-css-dark option
Browse files Browse the repository at this point in the history
  • Loading branch information
mb21 committed Mar 20, 2021
1 parent 7b2747e commit 8a3e3e7
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
11 changes: 11 additions & 0 deletions MANUAL.txt
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,12 @@ header when requesting a document from a URL:
To generate the JSON version of an existing style,
use `--print-highlight-style`.

`--highlight-style-dark=`*STYLE*|*FILE*

: Specifies the coloring style to be used in highlighted source code
in [dark mode] for HTML-based output formats. The default is `breezeDark`.
See `--highlight-style` for more information.

`--print-highlight-style=`*STYLE*|*FILE*

: Prints a JSON version of a highlighting style, which can
Expand Down Expand Up @@ -6202,6 +6208,10 @@ scheme used by the Python library pygments (though pygments is not actually
used to do the highlighting). To see a list of highlight styles,
type `pandoc --list-highlight-styles`.

For HTML-based output formats, the color scheme used for [dark mode]
can be selected using the `--highlight-style-dark` option.
It defaults to `breezeDark`.

If you are not satisfied with the predefined styles, you can
use `--print-highlight-style` to generate a JSON `.theme` file which
can be modified and used as the argument to `--highlight-style`. To
Expand All @@ -6223,6 +6233,7 @@ definitions](https://github.com/KDE/syntax-highlighting/tree/master/data/syntax)
To disable highlighting, use the `--no-highlight` option.

[skylighting]: https://github.com/jgm/skylighting
[dark mode]: https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme

# Custom Styles

Expand Down
12 changes: 11 additions & 1 deletion src/Text/Pandoc/App/CommandLineOptions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,9 @@ options =

, Option "" ["no-highlight"]
(NoArg
(\opt -> return opt { optHighlightStyle = Nothing }))
(\opt -> return opt { optHighlightStyle = Nothing
, optHighlightStyleDark = Nothing
}))
"" -- "Don't highlight source code"

, Option "" ["highlight-style"]
Expand All @@ -330,6 +332,14 @@ options =
"STYLE|FILE")
"" -- "Style for highlighted code"

, Option "" ["highlight-style-dark"]
(ReqArg
(\arg opt ->
return opt{ optHighlightStyleDark = Just $
T.pack $ normalizePath arg })
"STYLE|FILE")
"" -- "Style for highlighted code in dark mode"

, Option "" ["syntax-definition"]
(ReqArg
(\arg opt -> do
Expand Down
4 changes: 4 additions & 0 deletions src/Text/Pandoc/App/Opt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ data Opt = Opt
, optSelfContained :: Bool -- ^ Make HTML accessible offline
, optHtmlQTags :: Bool -- ^ Use <q> tags in HTML
, optHighlightStyle :: Maybe Text -- ^ Style to use for highlighted code
, optHighlightStyleDark :: Maybe Text -- ^ Style to use for highlighted code in dark mode
, optSyntaxDefinitions :: [FilePath] -- ^ xml syntax defs to load
, optTopLevelDivision :: TopLevelDivision -- ^ Type of the top-level divisions
, optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
Expand Down Expand Up @@ -417,6 +418,8 @@ doOpt (k',v) = do
parseYAML v >>= \x -> return (\o -> o{ optHtmlQTags = x })
"highlight-style" ->
parseYAML v >>= \x -> return (\o -> o{ optHighlightStyle = x })
"highlight-style-dark" ->
parseYAML v >>= \x -> return (\o -> o{ optHighlightStyleDark = x })
"syntax-definition" ->
(parseYAML v >>= \x ->
return (\o -> o{ optSyntaxDefinitions =
Expand Down Expand Up @@ -620,6 +623,7 @@ defaultOpts = Opt
, optSelfContained = False
, optHtmlQTags = False
, optHighlightStyle = Just "pygments"
, optHighlightStyleDark = Just "breezeDark"
, optSyntaxDefinitions = []
, optTopLevelDivision = TopLevelDefault
, optHTMLMathMethod = PlainMath
Expand Down
2 changes: 2 additions & 0 deletions src/Text/Pandoc/App/OutputSettings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ optToOutputSettings opts = do
(optSyntaxDefinitions opts)

hlStyle <- traverse (lookupHighlightStyle . T.unpack) $ optHighlightStyle opts
hlStyleDark <- traverse (lookupHighlightStyle . T.unpack) $ optHighlightStyleDark opts

let setVariableM k v = return . setVariable k v

Expand Down Expand Up @@ -202,6 +203,7 @@ optToOutputSettings opts = do
, writerListings = optListings opts
, writerSlideLevel = optSlideLevel opts
, writerHighlightStyle = hlStyle
, writerHighlightStyleDark = hlStyleDark
, writerSetextHeaders = optSetextHeaders opts
, writerEpubSubdirectory = T.pack $ optEpubSubdirectory opts
, writerEpubMetadata = epubMetadata
Expand Down
4 changes: 3 additions & 1 deletion src/Text/Pandoc/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import GHC.Generics (Generic)
import Skylighting (SyntaxMap, defaultSyntaxMap)
import Text.DocTemplates (Context(..), Template)
import Text.Pandoc.Extensions
import Text.Pandoc.Highlighting (Style, pygments)
import Text.Pandoc.Highlighting (Style, breezeDark, pygments)
import Text.Pandoc.Shared (camelCaseStrToHyphenated)
import Data.Aeson.TH (deriveJSON, defaultOptions, Options(..),
SumEncoding(..))
Expand Down Expand Up @@ -255,6 +255,7 @@ data WriterOptions = WriterOptions
, writerListings :: Bool -- ^ Use listings package for code
, writerHighlightStyle :: Maybe Style -- ^ Style to use for highlighting
-- (Nothing = no highlighting)
, writerHighlightStyleDark :: Maybe Style -- ^ Style to use for highlighting dark mode
, writerSetextHeaders :: Bool -- ^ Use setext headers for levels 1-2 in markdown
, writerEpubSubdirectory :: Text -- ^ Subdir for epub in OCF
, writerEpubMetadata :: Maybe Text -- ^ Metadata to include in EPUB
Expand Down Expand Up @@ -290,6 +291,7 @@ instance Default WriterOptions where
, writerTopLevelDivision = TopLevelDefault
, writerListings = False
, writerHighlightStyle = Just pygments
, writerHighlightStyleDark = Just breezeDark
, writerSetextHeaders = False
, writerEpubSubdirectory = "EPUB"
, writerEpubMetadata = Nothing
Expand Down
6 changes: 4 additions & 2 deletions src/Text/Pandoc/Writers/HTML.hs
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,10 @@ pandocToHtml opts (Pandoc meta blocks) = do
Nothing -> id
else id) .
(if stHighlighting st
then defField "highlighting-css-dark"
(T.pack $ styleToCss breezeDark)
then case writerHighlightStyleDark opts of
Just sty -> defField "highlighting-css-dark"
(T.pack $ styleToCss sty)
Nothing -> id
else id) .
(if stCsl st
then defField "csl-css" True .
Expand Down

0 comments on commit 8a3e3e7

Please sign in to comment.