diff options
-rw-r--r-- | src/Text/Pandoc/Parsing.hs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs index 2ac902211..ab35892dc 100644 --- a/src/Text/Pandoc/Parsing.hs +++ b/src/Text/Pandoc/Parsing.hs @@ -60,8 +60,10 @@ module Text.Pandoc.Parsing ( (>>~), gridTableWith, readWith, testStringWith, - ParserState (..), getOption, + guardEnabled, + guardDisabled, + ParserState (..), defaultParserState, HeaderType (..), ParserContext (..), @@ -75,8 +77,8 @@ module Text.Pandoc.Parsing ( (>>~), smartPunctuation, macro, applyMacros', - -- * Re-exports from Text.Pandoc.Parsec Parser, + -- * Re-exports from Text.Pandoc.Parsec runParser, parse, anyToken, @@ -144,6 +146,7 @@ import qualified Data.Map as M import Text.TeXMath.Macros (applyMacros, Macro, parseMacroDefinitions) import Text.HTML.TagSoup.Entity ( lookupEntity ) import Data.Default +import qualified Data.Set as Set type Parser t s = Parsec t s @@ -728,9 +731,17 @@ defaultParserState = stateMacros = [], stateRstDefaultRole = "title-reference"} -getOption :: (ReaderOptions -> a) -> Parser [t] ParserState a +getOption :: (ReaderOptions -> a) -> Parser s ParserState a getOption f = (f . stateOptions) `fmap` getState +-- | Succeed only if the extension is enabled. +guardEnabled :: Extension -> Parser s ParserState () +guardEnabled ext = getOption readerExtensions >>= guard . Set.member ext + +-- | Succeed only if the extension is disabled. +guardDisabled :: Extension -> Parser s ParserState () +guardDisabled ext = getOption readerExtensions >>= guard . not . Set.member ext + data HeaderType = SingleHeader Char -- ^ Single line of characters underneath | DoubleHeader Char -- ^ Lines of characters above and below |