From 4f9814087e3aa65d4482982aca34ed40ed2a2655 Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Tue, 25 Sep 2007 05:43:38 +0000 Subject: Fixed a bug in the Markdown writer: incorrect line wrapping in paragraphs including hard line breaks. Resolves Issue #25. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1032 788f1e2b-df1e-0410-8736-df70ead52e1b --- src/Text/Pandoc/Writers/Markdown.hs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index ab9525576..554e0a059 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -156,15 +156,24 @@ beginsWithOrderedListMarker str = Left _ -> False Right _ -> True +wrappedMarkdown :: WriterOptions -> [Inline] -> State WriterState Doc +wrappedMarkdown opts inlines = do + let chunks = splitBy LineBreak inlines + let chunks' = if null chunks + then [] + else (map (++ [Str " "]) $ init chunks) ++ [last chunks] + lns <- mapM (wrapped (inlineListToMarkdown opts)) chunks' + return $ vcat lns + -- | Convert Pandoc block element to markdown. blockToMarkdown :: WriterOptions -- ^ Options -> Block -- ^ Block element -> State WriterState Doc blockToMarkdown opts Null = return empty blockToMarkdown opts (Plain inlines) = - wrapped (inlineListToMarkdown opts) inlines + wrappedMarkdown opts inlines blockToMarkdown opts (Para inlines) = do - contents <- wrapped (inlineListToMarkdown opts) inlines + contents <- wrappedMarkdown opts inlines -- escape if para starts with ordered list marker let esc = if (not (writerStrictMarkdown opts)) && beginsWithOrderedListMarker (render contents) -- cgit v1.2.3