diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2012-07-26 19:10:56 -0700 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2012-07-26 19:10:56 -0700 |
commit | 5186da929ddda15ef28926169b1eae87e699ed50 (patch) | |
tree | 9f1b05919496544e2871a9540691f4a499709d59 /src | |
parent | 631e5c16fc00ed5f08b4c1152c02f69c4f8411e1 (diff) | |
download | pandoc-5186da929ddda15ef28926169b1eae87e699ed50.tar.gz |
Parsing: Added guardEnabled, guardDisabled.
Diffstat (limited to 'src')
-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 |