From 2351f7a112f7ebc612200ef3684cc3327dec8296 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 19 Jul 2012 12:38:54 -0700 Subject: Provide Data.Default instances for ParserState and WriterOptions. Now you can use def (which is re-exported by Text.Pandoc) instead of defaultParserState or defaultWriterOptions. For now, these are still defined too, so existing code need not change. Closes #546. --- src/Text/Pandoc.hs | 3 +++ src/Text/Pandoc/Parsing.hs | 8 ++++++-- src/Text/Pandoc/Shared.hs | 6 +++++- 3 files changed, 14 insertions(+), 3 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc.hs b/src/Text/Pandoc.hs index 432a5c2ba..f3436cc7b 100644 --- a/src/Text/Pandoc.hs +++ b/src/Text/Pandoc.hs @@ -114,6 +114,8 @@ module Text.Pandoc , rtfEmbedImage , jsonFilter , ToJsonFilter(..) + -- * From Data.Default + , def ) where import Text.Pandoc.Definition @@ -149,6 +151,7 @@ import Text.Pandoc.Shared import Data.Version (showVersion) import Text.JSON.Generic import Paths_pandoc (version) +import Data.Default -- | Version number of pandoc library. pandocVersion :: String diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs index cac2b71ca..70a8586db 100644 --- a/src/Text/Pandoc/Parsing.hs +++ b/src/Text/Pandoc/Parsing.hs @@ -88,6 +88,7 @@ import Text.Pandoc.Shared import qualified Data.Map as M import Text.TeXMath.Macros (applyMacros, Macro, parseMacroDefinitions) import Text.HTML.TagSoup.Entity ( lookupEntity ) +import Data.Default -- | Like >>, but returns the operation on the left. -- (Suggested by Tillmann Rendel on Haskell-cafe list.) @@ -658,6 +659,9 @@ data ParserState = ParserState } deriving Show +instance Default ParserState where + def = defaultParserState + defaultParserState :: ParserState defaultParserState = ParserState { stateParseRaw = False, @@ -872,13 +876,13 @@ macro = do inp <- getInput case parseMacroDefinitions inp of ([], _) -> pzero - (ms, rest) -> do def <- count (length inp - length rest) anyChar + (ms, rest) -> do def' <- count (length inp - length rest) anyChar if apply then do updateState $ \st -> st { stateMacros = ms ++ stateMacros st } return Null - else return $ RawBlock "latex" def + else return $ RawBlock "latex" def' -- | Apply current macros to string. applyMacros' :: String -> GenParser Char ParserState String diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index f14a57c1f..6c8904010 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -72,7 +72,7 @@ module Text.Pandoc.Shared ( readDataFile, -- * Error handling err, - warn, + warn ) where import Text.Pandoc.Definition @@ -94,6 +94,7 @@ import Text.Pandoc.Highlighting (Style, pygments) import Text.Pandoc.Pretty (charWidth) import System.Locale (defaultTimeLocale) import Data.Time +import Data.Default import System.IO (stderr) -- @@ -524,6 +525,9 @@ data WriterOptions = WriterOptions , writerTeXLigatures :: Bool -- ^ Use tex ligatures quotes, dashes in latex } deriving Show +instance Default WriterOptions where + def = defaultWriterOptions + {-# DEPRECATED writerXeTeX "writerXeTeX no longer does anything" #-} -- | Default writer options. defaultWriterOptions :: WriterOptions -- cgit v1.2.3