From 8a000e3ecc330ff8a4953ebe8c7da9a54eca5c58 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 12 Jun 2017 09:16:05 +0200 Subject: Markdown writer: don't allow soft break in header. Closes #3736. --- src/Text/Pandoc/Writers/Markdown.hs | 7 +++++++ test/command/3736.md | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 test/command/3736.md diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index 69243a214..3ac677943 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -475,6 +475,8 @@ blockToMarkdown' opts (Header level attr inlines) = do space <> attrsToMarkdown attr | otherwise -> empty contents <- inlineListToMarkdown opts $ + -- ensure no newlines; see #3736 + walk lineBreakToSpace $ if level == 1 && plain then capitalize inlines else inlines @@ -1203,3 +1205,8 @@ toSubscript c Just $ chr (0x2080 + (ord c - 48)) | isSpace c = Just c | otherwise = Nothing + +lineBreakToSpace :: Inline -> Inline +lineBreakToSpace LineBreak = Space +lineBreakToSpace SoftBreak = Space +lineBreakToSpace x = x diff --git a/test/command/3736.md b/test/command/3736.md new file mode 100644 index 000000000..b66e0a359 --- /dev/null +++ b/test/command/3736.md @@ -0,0 +1,25 @@ +``` +% pandoc --wrap=preserve -f html -t markdown +

hi +there

+^D +hi there +-------- +``` + +``` +% pandoc --wrap=preserve -f html -t markdown +

hi there +again

+^D +hi *there again* +---------------- +``` + +``` +% pandoc --wrap=preserve -f html -t markdown +

hi
there

+^D +hi there +-------- +``` -- cgit v1.2.3