From 6619b96dd70296112c2e31f9a1df6b8b6d1d698e Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Tue, 6 Nov 2018 22:54:43 -0800
Subject: Text.Pandoc.Pretty: don't render BreakingSpace at end of line...

or beginning of line.

Closes #5050.
---
 src/Text/Pandoc/Pretty.hs | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

(limited to 'src/Text')

diff --git a/src/Text/Pandoc/Pretty.hs b/src/Text/Pandoc/Pretty.hs
index ec1d36a68..a6e150a81 100644
--- a/src/Text/Pandoc/Pretty.hs
+++ b/src/Text/Pandoc/Pretty.hs
@@ -239,7 +239,7 @@ render linelen doc = fromString . mconcat . reverse . output $
 
 renderDoc :: (IsString a, Monoid a)
           => Doc -> DocState a
-renderDoc = renderList . toList . unDoc
+renderDoc = renderList . dropWhile (== BreakingSpace) . toList . unDoc
 
 data IsBlock = IsBlock Int [String]
 
@@ -280,6 +280,9 @@ renderList [BlankLines _] = return ()
 renderList (BlankLines m : BlankLines n : xs) =
   renderList (BlankLines (max m n) : xs)
 
+renderList (BlankLines num : BreakingSpace : xs) =
+  renderList (BlankLines num : xs)
+
 renderList (BlankLines num : xs) = do
   st <- get
   case output st of
@@ -290,6 +293,9 @@ renderList (BlankLines num : xs) = do
 renderList (CarriageReturn : BlankLines m : xs) =
   renderList (BlankLines m : xs)
 
+renderList (CarriageReturn : BreakingSpace : xs) =
+  renderList (CarriageReturn : xs)
+
 renderList (CarriageReturn : xs) = do
   st <- get
   if newlines st > 0 || null xs
@@ -302,7 +308,8 @@ renderList (NewLine : xs) = do
   outp (-1) "\n"
   renderList xs
 
-renderList (BreakingSpace : CarriageReturn : xs) = renderList (CarriageReturn:xs)
+renderList (BreakingSpace : CarriageReturn : xs) =
+  renderList (CarriageReturn:xs)
 renderList (BreakingSpace : NewLine : xs) = renderList (NewLine:xs)
 renderList (BreakingSpace : BlankLines n : xs) = renderList (BlankLines n:xs)
 renderList (BreakingSpace : BreakingSpace : xs) = renderList (BreakingSpace:xs)
-- 
cgit v1.2.3