Markdown reader: inline math must have nonspace before final $.

Closes #1313.
This commit is contained in:
John MacFarlane 2014-05-27 11:59:28 -07:00
parent fd11a5a5eb
commit 2e80613451
3 changed files with 12 additions and 4 deletions

View file

@ -464,11 +464,13 @@ mathInlineWith :: String -> String -> Parser [Char] st String
mathInlineWith op cl = try $ do
string op
notFollowedBy space
words' <- many1Till (count 1 (noneOf "\n\\")
words' <- many1Till (count 1 (noneOf " \t\n\\")
<|> (char '\\' >> anyChar >>= \c -> return ['\\',c])
<|> count 1 newline <* notFollowedBy' blankline
*> return " ")
(try $ string cl)
<|> do (blankline <* notFollowedBy' blankline) <|>
(oneOf " \t" <* skipMany (oneOf " \t"))
notFollowedBy (char '$')
return " "
) (try $ string cl)
notFollowedBy digit -- to prevent capture of $5
return $ concat words'

View file

@ -16,6 +16,8 @@
,Header 3 ("my-header",[],[]) [Str "my",Space,Str "header"]
,Header 2 ("in-math",[],[]) [Str "$",Space,Str "in",Space,Str "math"]
,Para [Math InlineMath "\\$2 + \\$3"]
,Para [Str "This",Space,Str "should",Space,Str "not",Space,Str "be",Space,Str "math:"]
,Para [Str "$PATH",Space,Str "90",Space,Str "$PATH"]
,Header 2 ("commented-out-list-item",[],[]) [Str "Commented-out",Space,Str "list",Space,Str "item"]
,BulletList
[[Plain [Str "one",Space,RawInline (Format "html") "<!--\n- two\n-->"]]

View file

@ -58,6 +58,10 @@
$\$2 + \$3$
This should not be math:
$PATH 90 $PATH
## Commented-out list item
- one