aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-10-08 08:02:24 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-10-08 08:02:24 -0700
commit1b10b5cea947cd6567c33466006c4216fde9f107 (patch)
treecbbf0975ab6da246e92f3d873821c09ffe2ff719 /src/Text
parent34c61fcad5f0809bbcc3cd82a45e9b6eff110533 (diff)
downloadpandoc-1b10b5cea947cd6567c33466006c4216fde9f107.tar.gz
Use th to derive json instance for LineEnding.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/App/Opt.hs20
1 files changed, 4 insertions, 16 deletions
diff --git a/src/Text/Pandoc/App/Opt.hs b/src/Text/Pandoc/App/Opt.hs
index 6610f6186..123c860fd 100644
--- a/src/Text/Pandoc/App/Opt.hs
+++ b/src/Text/Pandoc/App/Opt.hs
@@ -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
@@ -201,6 +187,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
} ''Opt)