MD Reader: Smart ' after inline math

Closes #1909.

Adds new parser combinator to Parsing.hs

`a <+?> b`

:   if a succeeds, applies b and mappends
    output (if any) to result of a. If b fails,
    it's just a, if a fails, whole expression fails.
This commit is contained in:
Nikolay Yakimov 2015-04-18 01:18:06 +03:00
parent 94e4a5ec44
commit 4229cf2d92
2 changed files with 8 additions and 2 deletions

View file

@ -161,7 +161,8 @@ module Text.Pandoc.Parsing ( anyLine,
setSourceColumn,
setSourceLine,
newPos,
addWarning
addWarning,
(<+?>)
)
where
@ -1245,3 +1246,7 @@ addWarning mbpos msg =
generalize :: (Monad m) => Parser s st a -> ParserT s st m a
generalize m = mkPT (\ s -> (return $ (return . runIdentity) <$> runIdentity (runParsecT m s)))
infixr 5 <+?>
(<+?>) :: (Monoid a, Monad m) => ParserT s st m a -> ParserT s st m a -> ParserT s st m a
a <+?> b = a >>= flip fmap (try b <|> return mempty) . (<>)

View file

@ -1487,7 +1487,8 @@ code = try $ do
math :: MarkdownParser Inlines
math = (B.displayMath <$> (mathDisplay >>= applyMacros'))
<|> (B.math <$> (mathInline >>= applyMacros'))
<|> ((B.math <$> (mathInline >>= applyMacros')) <+?>
((getOption readerSmart >>= guard) *> apostrophe <* notFollowedBy space))
-- Parses material enclosed in *s, **s, _s, or __s.
-- Designed to avoid backtracking.