aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-04-17 18:55:35 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2015-04-17 18:55:35 -0700
commitfb143be038810f7265f6254177437c23e54222ca (patch)
treeb122c0b2d4eb0b9ccd74bef4513d80e0d979cf4c /src
parent9ad336f586542cd8af30f2e16d2c935fb0f97a3e (diff)
parent4229cf2d92faf5774fe1a3a9c89a5de885cf75cd (diff)
downloadpandoc-fb143be038810f7265f6254177437c23e54222ca.tar.gz
Merge pull request #2092 from lierdakil/issue1909
MD Reader: Smart apostrophe after inline math
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Parsing.hs7
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs3
2 files changed, 8 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs
index c18aa331f..d30c74230 100644
--- a/src/Text/Pandoc/Parsing.hs
+++ b/src/Text/Pandoc/Parsing.hs
@@ -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) . (<>)
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index ccda83576..5e0cef4f8 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -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.