Skip to content

Commit 8123be6

Browse files
committed
Markdown writer: Allow display math to start/end with space.
This reverts to earlier < 3.7 behavior. Closes #11384.
1 parent 6c28ead commit 8123be6

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

‎src/Text/Pandoc/Writers/Markdown/Inline.hs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -500,24 +500,24 @@ inlineToMarkdown opts (Str str) = do
500500
else escapeText opts) $ str
501501
return $ literal str'
502502
inlineToMarkdown opts (Math InlineMath str) = do
503+
let str' = T.strip str
503504
variant <- asks envVariant
504505
case () of
505506
_ | variant == Markua -> return $ "`" <> literal str <> "`" <> "$"
506507
| otherwise -> case writerHTMLMathMethod opts of
507508
WebTeX url ->
508-
let str' = T.strip str
509-
in inlineToMarkdown opts
509+
inlineToMarkdown opts
510510
(Image nullAttr [Str str'] (url <> urlEncode str', str'))
511511
_ | isEnabled Ext_tex_math_gfm opts ->
512-
return $ "$`" <> literal str <> "`$"
512+
return $ "$`" <> literal str' <> "`$"
513513
| isEnabled Ext_tex_math_dollars opts ->
514-
return $ delimited "$" "$" (literal str)
514+
return $ "$" <> literal str' <> "$"
515515
| isEnabled Ext_tex_math_single_backslash opts ->
516-
return $ "\\(" <> literal str <> "\\)"
516+
return $ "\\(" <> literal str' <> "\\)"
517517
| isEnabled Ext_tex_math_double_backslash opts ->
518-
return $ "\\\\(" <> literal str <> "\\\\)"
518+
return $ "\\\\(" <> literal str' <> "\\\\)"
519519
| otherwise ->
520-
texMathToInlines InlineMath str >>=
520+
texMathToInlines InlineMath str' >>=
521521
inlineListToMarkdown opts .
522522
(if variant == PlainText then makeMathPlainer else id)
523523

@@ -540,7 +540,7 @@ inlineToMarkdown opts (Math DisplayMath str) = do
540540
$$ literal (T.dropAround (=='\n') str)
541541
$$ literal "```") <> cr
542542
| isEnabled Ext_tex_math_dollars opts ->
543-
return $ delimited "$$" "$$" (literal str)
543+
return $ "$$" <> literal str <> "$$"
544544
| isEnabled Ext_tex_math_single_backslash opts ->
545545
return $ "\\[" <> literal str <> "\\]"
546546
| isEnabled Ext_tex_math_double_backslash opts ->

‎test/command/11384.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
```
2+
% pandoc -t markdown -f native
3+
[ Para [ Math DisplayMath "\ne = mc^2\n" ] ]
4+
^D
5+
$$
6+
e = mc^2
7+
$$
8+
```
9+
10+
But we need to collapse spaces around inline math:
11+
12+
```
13+
% pandoc -t markdown -f native
14+
[ Para [ Math InlineMath "\ne=mc\n" ]]
15+
^D
16+
$e=mc$
17+
```

0 commit comments

Comments
 (0)