diff options
| author | John MacFarlane <[email protected]> | 2025-12-11 11:30:38 +0100 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2025-12-11 11:30:38 +0100 |
| commit | 1f76d3f1547c410d06db68007dd5aead8e75834d (patch) | |
| tree | 2db3b1ff560e4b3d01ada9d540320f049c4bdebb | |
| parent | 6d745e52767d1a1595d19b1950f41f4eaef5145f (diff) | |
Markdown writer: use setext for headers containing line breaks...
...for commonmark. Closes #11341.
| -rw-r--r-- | src/Text/Pandoc/Writers/Markdown.hs | 10 | ||||
| -rw-r--r-- | test/command/11341.md | 9 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index 1750db3bd..ee5463a1e 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -529,15 +529,19 @@ blockToMarkdown' opts (Header level attr inlines) = do isEnabled Ext_attributes opts -> space <> attrsToMarkdown opts attr | otherwise -> empty + let setext = level <= 2 && writerSetextHeaders opts || + (variant == Commonmark && + hasLineBreaks inlines) -- #11341 contents <- inlineListToMarkdown opts $ - -- ensure no newlines; see #3736 - walk lineBreakToSpace $ + (if variant == Commonmark && setext + then id + else -- ensure no newlines; see #3736 + walk lineBreakToSpace) $ if level == 1 && variant == PlainText && isEnabled Ext_gutenberg opts then capitalize inlines else inlines - let setext = writerSetextHeaders opts when (not setext && isEnabled Ext_literate_haskell opts) $ report $ ATXHeadingInLHS level (render Nothing contents) diff --git a/test/command/11341.md b/test/command/11341.md new file mode 100644 index 000000000..c04c2f334 --- /dev/null +++ b/test/command/11341.md @@ -0,0 +1,9 @@ +``` +% pandoc -t commonmark -f html +<h1>The Hobbit<br>or<br>There and Back Again</h1> +^D +The Hobbit\ +or\ +There and Back Again +==================== +``` |
