aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Extensions.hs22
-rw-r--r--src/Text/Pandoc/Options.hs51
2 files changed, 22 insertions, 51 deletions
diff --git a/src/Text/Pandoc/Extensions.hs b/src/Text/Pandoc/Extensions.hs
index b7227860a..67ad2ad04 100644
--- a/src/Text/Pandoc/Extensions.hs
+++ b/src/Text/Pandoc/Extensions.hs
@@ -15,8 +15,10 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-}
-{-# LANGUAGE DeriveDataTypeable #-}
-{-# LANGUAGE DeriveGeneric #-}
+{-# LANGUAGE DeriveDataTypeable #-}
+{-# LANGUAGE DeriveGeneric #-}
+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
+{-# LANGUAGE TemplateHaskell #-}
{- |
Module : Text.Pandoc.Extensions
@@ -45,8 +47,8 @@ module Text.Pandoc.Extensions ( Extension(..)
, githubMarkdownExtensions
, multimarkdownExtensions )
where
-import Data.Aeson (FromJSON (..), ToJSON (..), defaultOptions,
- genericToEncoding)
+import Data.Aeson (FromJSON (..), ToJSON (..), defaultOptions)
+import Data.Aeson.TH (deriveJSON)
import Data.Bits (clearBit, setBit, testBit, (.|.))
import Data.Data (Data)
import Data.Typeable (Typeable)
@@ -55,11 +57,7 @@ import Text.Pandoc.Shared (safeRead)
import Text.Parsec
newtype Extensions = Extensions Integer
- deriving (Show, Read, Eq, Ord, Data, Typeable, Generic)
-
-instance ToJSON Extensions where
- toEncoding = genericToEncoding defaultOptions
-instance FromJSON Extensions
+ deriving (Show, Read, Eq, Ord, Data, Typeable, Generic, ToJSON, FromJSON)
instance Monoid Extensions where
mempty = Extensions 0
@@ -156,10 +154,6 @@ data Extension =
| Ext_amuse -- ^ Enable Text::Amuse extensions to Emacs Muse markup
deriving (Show, Read, Enum, Eq, Ord, Bounded, Data, Typeable, Generic)
-instance ToJSON Extension where
- toEncoding = genericToEncoding defaultOptions
-instance FromJSON Extension
-
-- | Extensions to be used with pandoc-flavored markdown.
pandocExtensions :: Extensions
pandocExtensions = extensionsFromList
@@ -373,3 +367,5 @@ parseFormatSpec = parse formatSpec ""
return $ case polarity of
'-' -> disableExtension ext
_ -> enableExtension ext
+
+$(deriveJSON defaultOptions ''Extension)
diff --git a/src/Text/Pandoc/Options.hs b/src/Text/Pandoc/Options.hs
index 03960b6b9..1fb838321 100644
--- a/src/Text/Pandoc/Options.hs
+++ b/src/Text/Pandoc/Options.hs
@@ -1,5 +1,6 @@
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
+{-# LANGUAGE TemplateHaskell #-}
{-
Copyright (C) 2012-2017 John MacFarlane <jgm@berkeley.edu>
@@ -45,8 +46,8 @@ module Text.Pandoc.Options ( module Text.Pandoc.Extensions
, def
, isEnabled
) where
-import Data.Aeson (FromJSON (..), ToJSON (..), defaultOptions,
- genericToEncoding)
+import Data.Aeson (defaultOptions)
+import Data.Aeson.TH (deriveJSON)
import Data.Data (Data)
import Data.Default
import qualified Data.Set as Set
@@ -75,10 +76,6 @@ data ReaderOptions = ReaderOptions{
instance HasSyntaxExtensions ReaderOptions where
getExtensions opts = readerExtensions opts
-instance ToJSON ReaderOptions where
- toEncoding = genericToEncoding defaultOptions
-instance FromJSON ReaderOptions
-
instance Default ReaderOptions
where def = ReaderOptions{
readerExtensions = emptyExtensions
@@ -116,29 +113,17 @@ data HTMLMathMethod = PlainMath
| KaTeX String -- url of KaTeX files
deriving (Show, Read, Eq, Data, Typeable, Generic)
-instance ToJSON HTMLMathMethod where
- toEncoding = genericToEncoding defaultOptions
-instance FromJSON HTMLMathMethod
-
data CiteMethod = Citeproc -- use citeproc to render them
| Natbib -- output natbib cite commands
| Biblatex -- output biblatex cite commands
deriving (Show, Read, Eq, Data, Typeable, Generic)
-instance ToJSON CiteMethod where
- toEncoding = genericToEncoding defaultOptions
-instance FromJSON CiteMethod
-
-- | Methods for obfuscating email addresses in HTML.
data ObfuscationMethod = NoObfuscation
| ReferenceObfuscation
| JavascriptObfuscation
deriving (Show, Read, Eq, Data, Typeable, Generic)
-instance ToJSON ObfuscationMethod where
- toEncoding = genericToEncoding defaultOptions
-instance FromJSON ObfuscationMethod
-
-- | Varieties of HTML slide shows.
data HTMLSlideVariant = S5Slides
| SlidySlides
@@ -148,30 +133,18 @@ data HTMLSlideVariant = S5Slides
| NoSlides
deriving (Show, Read, Eq, Data, Typeable, Generic)
-instance ToJSON HTMLSlideVariant where
- toEncoding = genericToEncoding defaultOptions
-instance FromJSON HTMLSlideVariant
-
-- | Options for accepting or rejecting MS Word track-changes.
data TrackChanges = AcceptChanges
| RejectChanges
| AllChanges
deriving (Show, Read, Eq, Data, Typeable, Generic)
-instance ToJSON TrackChanges where
- toEncoding = genericToEncoding defaultOptions
-instance FromJSON TrackChanges
-
-- | Options for wrapping text in the output.
data WrapOption = WrapAuto -- ^ Automatically wrap to width
| WrapNone -- ^ No non-semantic newlines
| WrapPreserve -- ^ Preserve wrapping of input source
deriving (Show, Read, Eq, Data, Typeable, Generic)
-instance ToJSON WrapOption where
- toEncoding = genericToEncoding defaultOptions
-instance FromJSON WrapOption
-
-- | Options defining the type of top-level headers.
data TopLevelDivision = TopLevelPart -- ^ Top-level headers become parts
| TopLevelChapter -- ^ Top-level headers become chapters
@@ -180,20 +153,12 @@ data TopLevelDivision = TopLevelPart -- ^ Top-level headers become parts
-- heuristics
deriving (Show, Read, Eq, Data, Typeable, Generic)
-instance ToJSON TopLevelDivision where
- toEncoding = genericToEncoding defaultOptions
-instance FromJSON TopLevelDivision
-
-- | Locations for footnotes and references in markdown output
data ReferenceLocation = EndOfBlock -- ^ End of block
| EndOfSection -- ^ prior to next section header (or end of document)
| EndOfDocument -- ^ at end of document
deriving (Show, Read, Eq, Data, Typeable, Generic)
-instance ToJSON ReferenceLocation where
- toEncoding = genericToEncoding defaultOptions
-instance FromJSON ReferenceLocation
-
-- | Options for writers
data WriterOptions = WriterOptions
{ writerTemplate :: Maybe String -- ^ Template to use
@@ -271,3 +236,13 @@ instance HasSyntaxExtensions WriterOptions where
-- | Returns True if the given extension is enabled.
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 ''HTMLSlideVariant)
+$(deriveJSON defaultOptions ''TrackChanges)
+$(deriveJSON defaultOptions ''WrapOption)
+$(deriveJSON defaultOptions ''TopLevelDivision)
+$(deriveJSON defaultOptions ''ReferenceLocation)