git.iko.soy/typeable/pandoc
on master help sign in
Parsing: Added guardEnabled, guardDisabled.
5186da9John MacFarlane
src/Text/Pandoc/Parsing.hs+14−3
@@ -60,8 +60,10 @@ module Text.Pandoc.Parsing ( (>>~),
60 gridTableWith,
60 gridTableWith,
61 readWith,
61 readWith,
62 testStringWith,
62 testStringWith,
63− ParserState (..),
64 getOption,
63 getOption,
64+ guardEnabled,
65+ guardDisabled,
66+ ParserState (..),
65 defaultParserState,
67 defaultParserState,
66 HeaderType (..),
68 HeaderType (..),
67 ParserContext (..),
69 ParserContext (..),
@@ -75,8 +77,8 @@ module Text.Pandoc.Parsing ( (>>~),
75 smartPunctuation,
77 smartPunctuation,
76 macro,
78 macro,
77 applyMacros',
79 applyMacros',
78− -- * Re-exports from Text.Pandoc.Parsec
79 Parser,
80 Parser,
81+ -- * Re-exports from Text.Pandoc.Parsec
80 runParser,
82 runParser,
81 parse,
83 parse,
82 anyToken,
84 anyToken,
@@ -144,6 +146,7 @@ import qualified Data.Map as M
144import Text.TeXMath.Macros (applyMacros, Macro, parseMacroDefinitions)
146import Text.TeXMath.Macros (applyMacros, Macro, parseMacroDefinitions)
145import Text.HTML.TagSoup.Entity ( lookupEntity )
147import Text.HTML.TagSoup.Entity ( lookupEntity )
146import Data.Default
148import Data.Default
149+import qualified Data.Set as Set
147
150
148type Parser t s = Parsec t s
151type Parser t s = Parsec t s
149
152
@@ -728,9 +731,17 @@ defaultParserState =
728 stateMacros = [],
731 stateMacros = [],
729 stateRstDefaultRole = "title-reference"}
732 stateRstDefaultRole = "title-reference"}
730
733
731−getOption :: (ReaderOptions -> a) -> Parser [t] ParserState a
734+getOption :: (ReaderOptions -> a) -> Parser s ParserState a
732getOption f = (f . stateOptions) `fmap` getState
735getOption f = (f . stateOptions) `fmap` getState
733
736
737+-- | Succeed only if the extension is enabled.
738+guardEnabled :: Extension -> Parser s ParserState ()
739+guardEnabled ext = getOption readerExtensions >>= guard . Set.member ext
740+
741+-- | Succeed only if the extension is disabled.
742+guardDisabled :: Extension -> Parser s ParserState ()
743+guardDisabled ext = getOption readerExtensions >>= guard . not . Set.member ext
744+
734data HeaderType
745data HeaderType
735 = SingleHeader Char -- ^ Single line of characters underneath
746 = SingleHeader Char -- ^ Single line of characters underneath
736 | DoubleHeader Char -- ^ Lines of characters above and below
747 | DoubleHeader Char -- ^ Lines of characters above and below