@@ -1,3 +1,4 @@
1+{-# LANGUAGE OverloadedStrings #-}
12{-# LANGUAGE NoImplicitPrelude #-}
23{-# LANGUAGE CPP #-}
34{-# LANGUAGE DeriveGeneric #-}
@@ -31,16 +32,29 @@ import Text.Pandoc.Options (TopLevelDivision (TopLevelDefault),
3132 ObfuscationMethod (NoObfuscation),
3233 CiteMethod (Citeproc))
3334import Text.Pandoc.Shared (camelCaseToHyphenated)
35+import qualified Data.Text as T
36+import Data.Aeson (defaultOptions, Options(..), FromJSON(..), ToJSON(..),
37+ Value(..))
3438#ifdef DERIVE_JSON_VIA_TH
35−import Data.Aeson.TH (deriveJSON, defaultOptions, Options(..))
39+import Data.Aeson.TH (deriveJSON)
3640#else
37−import Data.Aeson (FromJSON (..), ToJSON (..), Options(..)
38− defaultOptions, genericToEncoding)
41+import Data.Aeson (genericToEncoding)
3942#endif
4043
4144-- | The type of line-endings to be used when writing plain-text.
4245data LineEnding = LF | CRLF | Native deriving (Show, Generic)
4346
47+instance ToJSON LineEnding
48+
49+instance FromJSON LineEnding where
50+ parseJSON (String t) =
51+ case T.toLower t of
52+ "lf" -> return LF
53+ "crlf" -> return CRLF
54+ "native" -> return Native
55+ _ -> fail "Expecting LF, CRLF, or Native"
56+ parseJSON _ = fail "Expecting string"
57+
4458-- | Data structure for command line options.
4559data Opt = Opt
4660 { optTabStop :: Int -- ^ Number of spaces per tab
@@ -191,15 +205,10 @@ defaultOpts = Opt
191205#ifdef DERIVE_JSON_VIA_TH
192206-- see https://github.com/jgm/pandoc/pull/4083
193207-- using generic deriving caused long compilation times
194−$(deriveJSON defaultOptions ''LineEnding)
195208$(deriveJSON
196209 defaultOptions{ fieldLabelModifier =
197210 camelCaseToHyphenated . drop 3 } ''Opt)
198211#else
199−instance ToJSON LineEnding where
200− toEncoding = genericToEncoding defaultOptions
201−instance FromJSON LineEnding
202−
203212instance ToJSON Opt where
204213 toEncoding = genericToEncoding
205214 defaultOptions{ fieldLabelModifier =