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
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue