mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-01 05:33:41 +08:00
T.P.Options: add type HighlightMethod and patterns [API Change]
The Text.Pandoc.Options module exports the `HighlightMethod` data type and it's constructors. Furthermore, three pattern synonyms are exported, `NoHighlightingString`, `DefaultHighlightingString`, and `IdiomaticHighlightingString`, which hold the string value that's used for decoding and encoding of HighlightMethod values.
This commit is contained in:
committed by
John MacFarlane
parent
3a298067ae
commit
64757254ab
@@ -3,6 +3,7 @@
|
||||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE PatternSynonyms #-}
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
{- |
|
||||
Module : Text.Pandoc.Options
|
||||
@@ -21,6 +22,10 @@ module Text.Pandoc.Options ( module Text.Pandoc.Extensions
|
||||
, HTMLMathMethod (..)
|
||||
, CiteMethod (..)
|
||||
, ObfuscationMethod (..)
|
||||
, HighlightMethod (..)
|
||||
, pattern NoHighlightingString
|
||||
, pattern DefaultHighlightingString
|
||||
, pattern IdiomaticHighlightingString
|
||||
, HTMLSlideVariant (..)
|
||||
, EPUBVersion (..)
|
||||
, WrapOption (..)
|
||||
@@ -42,13 +47,14 @@ import Data.Default
|
||||
import Data.Char (toLower)
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Set as Set
|
||||
import qualified Data.Text as T
|
||||
import Data.Typeable (Typeable)
|
||||
import GHC.Generics (Generic)
|
||||
import Skylighting (SyntaxMap, defaultSyntaxMap)
|
||||
import Text.DocTemplates (Context(..), Template)
|
||||
import Text.Pandoc.Extensions
|
||||
import Text.Pandoc.Chunks (PathTemplate)
|
||||
import Text.Pandoc.Highlighting (Style, defaultStyle)
|
||||
import Text.Pandoc.Highlighting (Style)
|
||||
import Text.Pandoc.UTF8 (toStringLazy)
|
||||
import Data.Aeson.TH (deriveJSON)
|
||||
import Data.Aeson
|
||||
@@ -186,6 +192,43 @@ instance ToJSON ObfuscationMethod where
|
||||
toJSON ReferenceObfuscation = String "references"
|
||||
toJSON JavascriptObfuscation = String "javascript"
|
||||
|
||||
-- | Method to provide code highlighting.
|
||||
data HighlightMethod =
|
||||
Skylighting Style
|
||||
| IdiomaticHighlighting
|
||||
| DefaultHighlighting
|
||||
| NoHighlighting
|
||||
deriving (Show, Read, Eq, Data, Typeable, Generic)
|
||||
|
||||
-- | String representation of the idiomatic highlighting option.
|
||||
pattern IdiomaticHighlightingString :: Text
|
||||
pattern IdiomaticHighlightingString = "idiomatic"
|
||||
|
||||
-- | String representation of the default highlighting option.
|
||||
pattern DefaultHighlightingString :: Text
|
||||
pattern DefaultHighlightingString = "default"
|
||||
|
||||
-- | String representation of the no highlighting option
|
||||
pattern NoHighlightingString :: Text
|
||||
pattern NoHighlightingString = "none"
|
||||
|
||||
instance ToJSON HighlightMethod where
|
||||
toJSON NoHighlighting = String NoHighlightingString
|
||||
toJSON IdiomaticHighlighting = String IdiomaticHighlightingString
|
||||
toJSON DefaultHighlighting = String DefaultHighlightingString
|
||||
toJSON (Skylighting style) = toJSON style
|
||||
|
||||
instance FromJSON HighlightMethod where
|
||||
parseJSON = \case
|
||||
String NoHighlightingString -> pure NoHighlighting
|
||||
String IdiomaticHighlightingString -> pure IdiomaticHighlighting
|
||||
String DefaultHighlightingString -> pure DefaultHighlighting
|
||||
String x -> fail $ "Unknown highlighting method " <> T.unpack x
|
||||
Bool True -> pure DefaultHighlighting
|
||||
Bool False -> pure NoHighlighting
|
||||
Null -> pure NoHighlighting
|
||||
v -> Skylighting <$> parseJSON v
|
||||
|
||||
-- | Varieties of HTML slide shows.
|
||||
data HTMLSlideVariant = S5Slides
|
||||
| SlidySlides
|
||||
@@ -330,9 +373,7 @@ data WriterOptions = WriterOptions
|
||||
, writerHtmlQTags :: Bool -- ^ Use @<q>@ tags for quotes in HTML
|
||||
, writerSlideLevel :: Maybe Int -- ^ Force header level of slides
|
||||
, writerTopLevelDivision :: TopLevelDivision -- ^ Type of top-level divisions
|
||||
, writerListings :: Bool -- ^ Use listings package for code
|
||||
, writerHighlightStyle :: Maybe Style -- ^ Style to use for highlighting
|
||||
-- (Nothing = no highlighting)
|
||||
, writerHighlightMethod :: HighlightMethod -- ^ Style to use for highlighting
|
||||
, writerSetextHeaders :: Bool -- ^ Use setext headers for levels 1-2 in markdown
|
||||
, writerListTables :: Bool -- ^ Use list tables for RST tables
|
||||
, writerEpubSubdirectory :: Text -- ^ Subdir for epub in OCF
|
||||
@@ -374,8 +415,7 @@ instance Default WriterOptions where
|
||||
, writerHtmlQTags = False
|
||||
, writerSlideLevel = Nothing
|
||||
, writerTopLevelDivision = TopLevelDefault
|
||||
, writerListings = False
|
||||
, writerHighlightStyle = Just defaultStyle
|
||||
, writerHighlightMethod = DefaultHighlighting
|
||||
, writerSetextHeaders = False
|
||||
, writerListTables = False
|
||||
, writerEpubSubdirectory = "EPUB"
|
||||
|
||||
Reference in New Issue
Block a user