git.iko.soy/typeable/pandoc
on master help sign in
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.

commit2351f7a112f7ebc612200ef3684cc3327dec8296 authorJohn MacFarlane <fiddlosopher@gmail.com> dateThu 19 Jul 2012, 12:38 (14 years ago) parent26748da
4 files changed+17−3
pandoc.cabal+3 src/Text/Pandoc.hs+3 src/Text/Pandoc/Parsing.hs+6−2 src/Text/Pandoc/Shared.hs+5−1
pandoc.cabal+3
@@ -223,6 +223,7 @@ Library
223223 base64-bytestring >= 0.1 && < 0.2,
224224 zlib >= 0.5 && < 0.6,
225225 highlighting-kate >= 0.5.1 && < 0.6,
226+ data-default >= 0.4 && < 0.6,
226227 temporary >= 1.1 && < 1.2
227228 if flag(blaze_html_0_5)
228229 build-depends:
@@ -331,6 +332,7 @@ Executable pandoc
331332 base64-bytestring >= 0.1 && < 0.2,
332333 zlib >= 0.5 && < 0.6,
333334 highlighting-kate >= 0.5.1 && < 0.6,
335+ data-default >= 0.4 && < 0.6,
334336 temporary >= 1.1 && < 1.2
335337 if flag(blaze_html_0_5)
336338 build-depends:
@@ -398,6 +400,7 @@ Executable test-pandoc
398400 base64-bytestring >= 0.1 && < 0.2,
399401 zlib >= 0.5 && < 0.6,
400402 highlighting-kate >= 0.5.1 && < 0.6,
403+ data-default >= 0.4 && < 0.6,
401404 temporary >= 1.1 && < 1.2
402405 if flag(blaze_html_0_5)
403406 build-depends:
src/Text/Pandoc.hs+3
@@ -114,6 +114,8 @@ module Text.Pandoc
114114 , rtfEmbedImage
115115 , jsonFilter
116116 , ToJsonFilter(..)
117+ -- * From Data.Default
118+ , def
117119 ) where
118120
119121import Text.Pandoc.Definition
@@ -149,6 +151,7 @@ import Text.Pandoc.Shared
149151import Data.Version (showVersion)
150152import Text.JSON.Generic
151153import Paths_pandoc (version)
154+import Data.Default
152155
153156-- | Version number of pandoc library.
154157pandocVersion :: String
src/Text/Pandoc/Parsing.hs+6−2
@@ -88,6 +88,7 @@ import Text.Pandoc.Shared
8888import qualified Data.Map as M
8989import Text.TeXMath.Macros (applyMacros, Macro, parseMacroDefinitions)
9090import Text.HTML.TagSoup.Entity ( lookupEntity )
91+import Data.Default
9192
9293-- | Like >>, but returns the operation on the left.
9394-- (Suggested by Tillmann Rendel on Haskell-cafe list.)
@@ -658,6 +659,9 @@ data ParserState = ParserState
658659 }
659660 deriving Show
660661
662+instance Default ParserState where
663+ def = defaultParserState
664+
661665defaultParserState :: ParserState
662666defaultParserState =
663667 ParserState { stateParseRaw = False,
@@ -872,13 +876,13 @@ macro = do
872876 inp <- getInput
873877 case parseMacroDefinitions inp of
874878 ([], _) -> pzero
875− (ms, rest) -> do def <- count (length inp - length rest) anyChar
879+ (ms, rest) -> do def' <- count (length inp - length rest) anyChar
876880 if apply
877881 then do
878882 updateState $ \st ->
879883 st { stateMacros = ms ++ stateMacros st }
880884 return Null
881− else return $ RawBlock "latex" def
885+ else return $ RawBlock "latex" def'
882886
883887-- | Apply current macros to string.
884888applyMacros' :: String -> GenParser Char ParserState String
src/Text/Pandoc/Shared.hs+5−1
@@ -72,7 +72,7 @@ module Text.Pandoc.Shared (
7272 readDataFile,
7373 -- * Error handling
7474 err,
75− warn,
75+ warn
7676 ) where
7777
7878import Text.Pandoc.Definition
@@ -94,6 +94,7 @@ import Text.Pandoc.Highlighting (Style, pygments)
9494import Text.Pandoc.Pretty (charWidth)
9595import System.Locale (defaultTimeLocale)
9696import Data.Time
97+import Data.Default
9798import System.IO (stderr)
9899
99100--
@@ -524,6 +525,9 @@ data WriterOptions = WriterOptions
524525 , writerTeXLigatures :: Bool -- ^ Use tex ligatures quotes, dashes in latex
525526 } deriving Show
526527
528+instance Default WriterOptions where
529+ def = defaultWriterOptions
530+
527531{-# DEPRECATED writerXeTeX "writerXeTeX no longer does anything" #-}
528532-- | Default writer options.
529533defaultWriterOptions :: WriterOptions