Skip to content

Commit

Permalink
Text.Pandoc.Pretty: don't render BreakingSpace at end of line...
Browse files Browse the repository at this point in the history
or beginning of line.

Closes #5050.
  • Loading branch information
jgm committed Nov 7, 2018
1 parent 985db7b commit 6619b96
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Text/Pandoc/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 6619b96

Please sign in to comment.