diff options
author | John MacFarlane <jgm@berkeley.edu> | 2019-10-07 22:23:00 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2019-10-07 22:23:51 -0700 |
commit | 34c61fcad5f0809bbcc3cd82a45e9b6eff110533 (patch) | |
tree | b9741cca2f5a1c40237796773de2b1a1fe0eaef1 /src/Text | |
parent | e4ccfeab8c55578fead30233394d531f31a429c3 (diff) | |
download | pandoc-34c61fcad5f0809bbcc3cd82a45e9b6eff110533.tar.gz |
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.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/App/Opt.hs | 4 | ||||
-rw-r--r-- | src/Text/Pandoc/Options.hs | 40 |
2 files changed, 35 insertions, 9 deletions
diff --git a/src/Text/Pandoc/App/Opt.hs b/src/Text/Pandoc/App/Opt.hs index f714586e4..6610f6186 100644 --- a/src/Text/Pandoc/App/Opt.hs +++ b/src/Text/Pandoc/App/Opt.hs @@ -20,6 +20,7 @@ module Text.Pandoc.App.Opt ( , defaultOpts ) where import Prelude +import Data.Char (isLower) import GHC.Generics import Text.Pandoc.Filter (Filter (..)) import Text.Pandoc.Logging (Verbosity (WARNING)) @@ -201,4 +202,5 @@ defaultOpts = Opt -- using generic deriving caused long compilation times $(deriveJSON defaultOptions{ fieldLabelModifier = - camelCaseToHyphenated . drop 3 } ''Opt) + camelCaseToHyphenated . dropWhile isLower + } ''Opt) diff --git a/src/Text/Pandoc/Options.hs b/src/Text/Pandoc/Options.hs index d230291cb..59546cd1b 100644 --- a/src/Text/Pandoc/Options.hs +++ b/src/Text/Pandoc/Options.hs @@ -31,6 +31,7 @@ module Text.Pandoc.Options ( module Text.Pandoc.Extensions , isEnabled ) where import Prelude +import Data.Char (toLower) import Data.Data (Data) import Data.Default import qualified Data.Set as Set @@ -39,8 +40,10 @@ import GHC.Generics (Generic) import Skylighting (SyntaxMap, defaultSyntaxMap) import Text.Pandoc.Extensions import Text.Pandoc.Highlighting (Style, pygments) +import Text.Pandoc.Shared (camelCaseToHyphenated) import Text.DocTemplates (Template) -import Data.Aeson.TH (deriveJSON, defaultOptions) +import Data.Aeson.TH (deriveJSON, defaultOptions, Options(..), + SumEncoding(..)) class HasSyntaxExtensions a where getExtensions :: a -> Extensions @@ -223,11 +226,32 @@ isEnabled :: HasSyntaxExtensions a => Extension -> a -> Bool isEnabled ext opts = ext `extensionEnabled` getExtensions opts $(deriveJSON defaultOptions ''ReaderOptions) -$(deriveJSON defaultOptions ''HTMLMathMethod) -$(deriveJSON defaultOptions ''CiteMethod) -$(deriveJSON defaultOptions ''ObfuscationMethod) +$(deriveJSON defaultOptions{ + constructorTagModifier = map toLower, + 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 ''TrackChanges) -$(deriveJSON defaultOptions ''WrapOption) -$(deriveJSON defaultOptions ''TopLevelDivision) -$(deriveJSON defaultOptions ''ReferenceLocation) +$(deriveJSON defaultOptions{ constructorTagModifier = + camelCaseToHyphenated + } ''TrackChanges) +$(deriveJSON defaultOptions{ constructorTagModifier = + camelCaseToHyphenated + } ''WrapOption) +$(deriveJSON defaultOptions{ constructorTagModifier = + camelCaseToHyphenated . drop 8 + } ''TopLevelDivision) +$(deriveJSON defaultOptions{ constructorTagModifier = + camelCaseToHyphenated + } ''ReferenceLocation) |