git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #2092 from lierdakil/issue1909

MD Reader: Smart apostrophe after inline math

commitfb143be038810f7265f6254177437c23e54222ca authorJohn MacFarlane <jgm@berkeley.edu> dateFri 17 Apr 2015, 18:55 (12 years ago) parent9ad336f4229cf2
3 files changed+11−2
src/Text/Pandoc/Parsing.hs+6−1 src/Text/Pandoc/Readers/Markdown.hs+2−1 tests/Tests/Readers/Markdown.hs+3
src/Text/Pandoc/Parsing.hs+6−1
@@ -161,7 +161,8 @@ module Text.Pandoc.Parsing ( anyLine,
161161 setSourceColumn,
162162 setSourceLine,
163163 newPos,
164− addWarning
164+ addWarning,
165+ (<+?>)
165166 )
166167where
167168
@@ -1245,3 +1246,7 @@ addWarning mbpos msg =
12451246
12461247generalize :: (Monad m) => Parser s st a -> ParserT s st m a
12471248generalize m = mkPT (\ s -> (return $ (return . runIdentity) <$> runIdentity (runParsecT m s)))
1249+
1250+infixr 5 <+?>
1251+(<+?>) :: (Monoid a, Monad m) => ParserT s st m a -> ParserT s st m a -> ParserT s st m a
1252+a <+?> b = a >>= flip fmap (try b <|> return mempty) . (<>)
src/Text/Pandoc/Readers/Markdown.hs+2−1
@@ -1487,7 +1487,8 @@ code = try $ do
14871487
14881488math :: MarkdownParser Inlines
14891489math = (B.displayMath <$> (mathDisplay >>= applyMacros'))
1490− <|> (B.math <$> (mathInline >>= applyMacros'))
1490+ <|> ((B.math <$> (mathInline >>= applyMacros')) <+?>
1491+ ((getOption readerSmart >>= guard) *> apostrophe <* notFollowedBy space))
14911492
14921493-- Parses material enclosed in *s, **s, _s, or __s.
14931494-- Designed to avoid backtracking.
tests/Tests/Readers/Markdown.hs+3
@@ -208,6 +208,9 @@ tests = [ testGroup "inline code"
208208 , test markdownSmart "apostrophe in French"
209209 ("À l'arrivée de la guerre, le thème de l'«impossibilité du socialisme»"
210210 =?> para "À l’arrivée de la guerre, le thème de l’«impossibilité du socialisme»")
211+ , test markdownSmart "apostrophe after math" $ -- issue #1909
212+ "The value of the $x$'s and the systems' condition." =?>
213+ para (text "The value of the " <> math "x" <> text "\8217s and the systems\8217 condition.")
211214 ]
212215 , testGroup "footnotes"
213216 [ "indent followed by newline and flush-left text" =: