Text.Pandoc.Options: change To/FromJSON instances for...
HTMLMathMethod, CiteMethod, ObfuscationMethod, TrackChanges, WrapOption, TopLevelDivision, ReferenceLocation, HTMLSlideVariant. In each case we use lowercase (or hyphenated lowercase) for constructors to line up more closely with command-line option values. This is a breaking change for those who manually decode or encode JSON for these data types (e.g. for ReaderOptions or WriterOptions). See #5790.
This commit is contained in:
parent
e4ccfeab8c
commit
34c61fcad5
2 changed files with 35 additions and 9 deletions
src/Text/Pandoc
|
@ -20,6 +20,7 @@ module Text.Pandoc.App.Opt (
|
||||||
, defaultOpts
|
, defaultOpts
|
||||||
) where
|
) where
|
||||||
import Prelude
|
import Prelude
|
||||||
|
import Data.Char (isLower)
|
||||||
import GHC.Generics
|
import GHC.Generics
|
||||||
import Text.Pandoc.Filter (Filter (..))
|
import Text.Pandoc.Filter (Filter (..))
|
||||||
import Text.Pandoc.Logging (Verbosity (WARNING))
|
import Text.Pandoc.Logging (Verbosity (WARNING))
|
||||||
|
@ -201,4 +202,5 @@ defaultOpts = Opt
|
||||||
-- using generic deriving caused long compilation times
|
-- using generic deriving caused long compilation times
|
||||||
$(deriveJSON
|
$(deriveJSON
|
||||||
defaultOptions{ fieldLabelModifier =
|
defaultOptions{ fieldLabelModifier =
|
||||||
camelCaseToHyphenated . drop 3 } ''Opt)
|
camelCaseToHyphenated . dropWhile isLower
|
||||||
|
} ''Opt)
|
||||||
|
|
|
@ -31,6 +31,7 @@ module Text.Pandoc.Options ( module Text.Pandoc.Extensions
|
||||||
, isEnabled
|
, isEnabled
|
||||||
) where
|
) where
|
||||||
import Prelude
|
import Prelude
|
||||||
|
import Data.Char (toLower)
|
||||||
import Data.Data (Data)
|
import Data.Data (Data)
|
||||||
import Data.Default
|
import Data.Default
|
||||||
import qualified Data.Set as Set
|
import qualified Data.Set as Set
|
||||||
|
@ -39,8 +40,10 @@ import GHC.Generics (Generic)
|
||||||
import Skylighting (SyntaxMap, defaultSyntaxMap)
|
import Skylighting (SyntaxMap, defaultSyntaxMap)
|
||||||
import Text.Pandoc.Extensions
|
import Text.Pandoc.Extensions
|
||||||
import Text.Pandoc.Highlighting (Style, pygments)
|
import Text.Pandoc.Highlighting (Style, pygments)
|
||||||
|
import Text.Pandoc.Shared (camelCaseToHyphenated)
|
||||||
import Text.DocTemplates (Template)
|
import Text.DocTemplates (Template)
|
||||||
import Data.Aeson.TH (deriveJSON, defaultOptions)
|
import Data.Aeson.TH (deriveJSON, defaultOptions, Options(..),
|
||||||
|
SumEncoding(..))
|
||||||
|
|
||||||
class HasSyntaxExtensions a where
|
class HasSyntaxExtensions a where
|
||||||
getExtensions :: a -> Extensions
|
getExtensions :: a -> Extensions
|
||||||
|
@ -223,11 +226,32 @@ isEnabled :: HasSyntaxExtensions a => Extension -> a -> Bool
|
||||||
isEnabled ext opts = ext `extensionEnabled` getExtensions opts
|
isEnabled ext opts = ext `extensionEnabled` getExtensions opts
|
||||||
|
|
||||||
$(deriveJSON defaultOptions ''ReaderOptions)
|
$(deriveJSON defaultOptions ''ReaderOptions)
|
||||||
$(deriveJSON defaultOptions ''HTMLMathMethod)
|
$(deriveJSON defaultOptions{
|
||||||
$(deriveJSON defaultOptions ''CiteMethod)
|
constructorTagModifier = map toLower,
|
||||||
$(deriveJSON defaultOptions ''ObfuscationMethod)
|
sumEncoding = TaggedObject{
|
||||||
|
tagFieldName = "method",
|
||||||
|
contentsFieldName = "url" }
|
||||||
|
} ''HTMLMathMethod)
|
||||||
|
$(deriveJSON defaultOptions{ constructorTagModifier =
|
||||||
|
camelCaseToHyphenated
|
||||||
|
} ''CiteMethod)
|
||||||
|
$(deriveJSON defaultOptions{ constructorTagModifier =
|
||||||
|
\t -> case t of
|
||||||
|
"NoObfuscation" -> "none"
|
||||||
|
"ReferenceObfuscation" -> "references"
|
||||||
|
"JavascriptObfuscation" -> "javascript"
|
||||||
|
_ -> "none"
|
||||||
|
} ''ObfuscationMethod)
|
||||||
$(deriveJSON defaultOptions ''HTMLSlideVariant)
|
$(deriveJSON defaultOptions ''HTMLSlideVariant)
|
||||||
$(deriveJSON defaultOptions ''TrackChanges)
|
$(deriveJSON defaultOptions{ constructorTagModifier =
|
||||||
$(deriveJSON defaultOptions ''WrapOption)
|
camelCaseToHyphenated
|
||||||
$(deriveJSON defaultOptions ''TopLevelDivision)
|
} ''TrackChanges)
|
||||||
$(deriveJSON defaultOptions ''ReferenceLocation)
|
$(deriveJSON defaultOptions{ constructorTagModifier =
|
||||||
|
camelCaseToHyphenated
|
||||||
|
} ''WrapOption)
|
||||||
|
$(deriveJSON defaultOptions{ constructorTagModifier =
|
||||||
|
camelCaseToHyphenated . drop 8
|
||||||
|
} ''TopLevelDivision)
|
||||||
|
$(deriveJSON defaultOptions{ constructorTagModifier =
|
||||||
|
camelCaseToHyphenated
|
||||||
|
} ''ReferenceLocation)
|
||||||
|
|
Loading…
Add table
Reference in a new issue