summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2023-11-15 10:06:22 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2023-11-15 10:06:22 -0800
commitcd48bf40597e99bec6419a9a0b49fef46330d56c (patch)
tree06d4e8c22fcd70e3190849139d2b22669f50f758
parent0283cdc200b7ee44d3abdcc7061c47473ed9fd92 (diff)
Markdown reader: don't change newlines to spaces in math.
Preserve them: otherwise we can get unwanted results if there's a `%` comment. Closes #9193.
-rw-r--r--src/Text/Pandoc/Parsing/Math.hs8
-rw-r--r--test/command/9193.md7
-rw-r--r--test/testsuite.txt3
3 files changed, 11 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Parsing/Math.hs b/src/Text/Pandoc/Parsing/Math.hs
index 0be9ac3d6..73ae1e0c2 100644
--- a/src/Text/Pandoc/Parsing/Math.hs
+++ b/src/Text/Pandoc/Parsing/Math.hs
@@ -17,7 +17,7 @@ where
import Control.Monad (mzero, when)
import Data.Text (Text)
-import Text.Parsec ((<|>), ParsecT, Stream(..), notFollowedBy, skipMany, try)
+import Text.Parsec ((<|>), ParsecT, Stream(..), notFollowedBy, many1, try)
import Text.Pandoc.Options
( Extension(Ext_tex_math_dollars, Ext_tex_math_single_backslash,
Ext_tex_math_double_backslash) )
@@ -42,10 +42,8 @@ mathInlineWith op cl = try $ do
(try (string "text" >>
(("\\text" <>) <$> inBalancedBraces 0 ""))
<|> (\c -> T.pack ['\\',c]) <$> anyChar))
- <|> do (blankline <* notFollowedBy' blankline) <|>
- (spaceChar <* skipMany spaceChar)
- notFollowedBy (char '$')
- return " "
+ <|> ("\n" <$ blankline <* notFollowedBy' blankline)
+ <|> (T.pack <$> many1 spaceChar <* notFollowedBy (char '$'))
) (try $ textStr cl)
notFollowedBy digit -- to prevent capture of $5
return $ trimMath $ T.concat words'
diff --git a/test/command/9193.md b/test/command/9193.md
new file mode 100644
index 000000000..3a5a7a941
--- /dev/null
+++ b/test/command/9193.md
@@ -0,0 +1,7 @@
+```
+% pandoc -t native
+$a+%
+b$
+^D
+[ Para [ Math InlineMath "a+%\nb" ] ]
+```
diff --git a/test/testsuite.txt b/test/testsuite.txt
index 9413cc81a..1b58922d1 100644
--- a/test/testsuite.txt
+++ b/test/testsuite.txt
@@ -522,8 +522,7 @@ Ellipses...and...and....
- $p$-Tree
- Here's some display math:
$$\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}$$
-- Here's one that has a line break in it: $\alpha + \omega \times
-x^2$.
+- Here's one that has a line break in it: $\alpha + \omega \times x^2$.
These shouldn't be math: