Use th to derive json instance for LineEnding.
This commit is contained in:
parent
34c61fcad5
commit
1b10b5cea9
1 changed files with 4 additions and 16 deletions
|
@ -20,7 +20,7 @@ module Text.Pandoc.App.Opt (
|
|||
, defaultOpts
|
||||
) where
|
||||
import Prelude
|
||||
import Data.Char (isLower)
|
||||
import Data.Char (isLower, toLower)
|
||||
import GHC.Generics
|
||||
import Text.Pandoc.Filter (Filter (..))
|
||||
import Text.Pandoc.Logging (Verbosity (WARNING))
|
||||
|
@ -31,26 +31,12 @@ import Text.Pandoc.Options (TopLevelDivision (TopLevelDefault),
|
|||
ObfuscationMethod (NoObfuscation),
|
||||
CiteMethod (Citeproc))
|
||||
import Text.Pandoc.Shared (camelCaseToHyphenated)
|
||||
import qualified Data.Text as T
|
||||
import Data.Aeson (defaultOptions, Options(..), FromJSON(..), ToJSON(..),
|
||||
Value(..))
|
||||
import Data.Aeson.Types (typeMismatch)
|
||||
import Data.Aeson (defaultOptions, Options(..))
|
||||
import Data.Aeson.TH (deriveJSON)
|
||||
|
||||
-- | The type of line-endings to be used when writing plain-text.
|
||||
data LineEnding = LF | CRLF | Native deriving (Show, Generic)
|
||||
|
||||
instance ToJSON LineEnding
|
||||
|
||||
instance FromJSON LineEnding where
|
||||
parseJSON (String t) =
|
||||
case T.toLower t of
|
||||
"lf" -> return LF
|
||||
"crlf" -> return CRLF
|
||||
"native" -> return Native
|
||||
_ -> fail "Expecting LF, CRLF, or Native"
|
||||
parseJSON v = typeMismatch "String" v
|
||||
|
||||
-- | Data structure for command line options.
|
||||
data Opt = Opt
|
||||
{ optTabStop :: Int -- ^ Number of spaces per tab
|
||||
|
@ -200,6 +186,8 @@ defaultOpts = Opt
|
|||
|
||||
-- see https://github.com/jgm/pandoc/pull/4083
|
||||
-- using generic deriving caused long compilation times
|
||||
$(deriveJSON
|
||||
defaultOptions{ fieldLabelModifier = map toLower } ''LineEnding)
|
||||
$(deriveJSON
|
||||
defaultOptions{ fieldLabelModifier =
|
||||
camelCaseToHyphenated . dropWhile isLower
|
||||
|
|
Loading…
Add table
Reference in a new issue