Skip to content

Commit d9281d1

Browse files
committed
Markdown writer: avoid collapsing of initial/final newline in...
...markdown raw blocks. For motivation see #10477.
1 parent d064ad7 commit d9281d1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Text/Pandoc/Writers/Markdown.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,16 +470,18 @@ blockToMarkdown' opts b@(RawBlock f str) = do
470470
let renderEmpty = mempty <$ report (BlockNotRendered b)
471471
case variant of
472472
PlainText
473-
| f == "plain" -> return $ literal str <> literal "\n"
473+
| f == "plain" -> return $ nest 0 (literal str) <> literal "\n"
474474
Commonmark
475475
| f `elem` ["gfm", "commonmark", "commonmark_x", "markdown"]
476-
-> return $ literal str $$ blankline
476+
-> return $ nest 0 (literal str) $$ blankline
477477
| f `elem` ["html", "html5", "html4"]
478478
-> return $ literal (removeBlankLinesInHTML str) $$ blankline
479479
Markdown
480480
| f `elem` ["markdown", "markdown_github", "markdown_phpextra",
481481
"markdown_mmd", "markdown_strict"]
482-
-> return $ literal str <> literal "\n"
482+
-- the 'nest 0' ensures that leading and trailing newlines
483+
-- don't get collapsed. See #10477 for context;
484+
-> return $ nest 0 (literal str) <> literal "\n"
483485
Markua -> renderEmpty
484486
_ | f `elem` ["html", "html5", "html4"]
485487
, isEnabled Ext_markdown_attribute opts

0 commit comments

Comments
 (0)