From 650b13e2d6952efc3bf07c496ffc10c8a09830c4 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 2 Oct 2021 08:26:35 -0700 Subject: Docx reader spacing fix: avoid creating `Str ""`. --- src/Text/Pandoc/Readers/Docx.hs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index c311fb367..c45dc2d1d 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -530,14 +530,22 @@ trimSps = trimlSps . trimrSps SoftBreak :< xs -> trimlSps $ Many xs LineBreak :< xs -> trimlSps $ Many xs Str t :< xs - | startsWithSpace t -> Many (Str (T.dropWhile (==' ') t) <| xs) + | startsWithSpace t -> + let t' = T.dropWhile (==' ') t + in if T.null t' + then trimlSps $ Many xs + else Many (Str t' <| xs) _ -> Many ils trimrSps (Many ils) = case viewr ils of (xs :> SoftBreak) -> trimrSps $ Many xs (xs :> LineBreak) -> trimrSps $ Many xs (xs :> Str t) - | endsWithSpace t -> Many (xs |> Str (T.dropWhileEnd (==' ') t)) + | endsWithSpace t -> + let t' = T.dropWhileEnd (==' ') t + in if T.null t' + then trimrSps $ Many xs + else Many (xs |> Str t') _ -> Many ils startsWithSpace t = case T.uncons t of Just (' ',_) -> True -- cgit v1.2.3