diff options
author | defanor <defanor@uberspace.net> | 2017-10-28 03:16:26 +0300 |
---|---|---|
committer | defanor <defanor@uberspace.net> | 2017-10-28 03:16:26 +0300 |
commit | d2da10d36b857e399e10388ddc6f66850211ec77 (patch) | |
tree | 40e98bcc17276200f98c5af7c0de2b64263b9bc9 /Pancake.hs | |
parent | b52d2a395814158319a781d38a49bb0f132c221d (diff) |
Improve plaintext rendering
Reuse lineToInlines previously used for Gopher, and adjust fitLines.
Diffstat (limited to 'Pancake.hs')
-rw-r--r-- | Pancake.hs | 17 |
1 files changed, 11 insertions, 6 deletions
@@ -237,12 +237,17 @@ fitLines maxLen inlineBits = map mconcat $ map reverse $ fitWords [] 0 inlineBit -- a new line fitWords _ 0 (w:ws) = fitWords [w] (length $ asString w) ws -- add a word to a line - fitWords curLine curLen (w:ws) = let wLen = length (asString w) in - if curLen + wLen <= maxLen - then fitWords (w:curLine) (curLen + wLen) ws - else curLine : fitWords [] 0 (case w of - " " -> ws - _ -> (w:ws)) + fitWords curLine curLen (w:ws) = let wLen = length (asString w) + spaceAhead = case ws of + (" " : _) -> True + _ -> False + in if curLen + wLen <= maxLen + then fitWords (w:curLine) (curLen + wLen) $ + -- if there's an unnecessary space ahead, skip it + if (curLen + wLen + 1 > maxLen && spaceAhead) + then tail ws + else ws + else curLine : fitWords [] 0 (w:ws) -- end, no words pending fitWords _ 0 [] = [] -- end, with words pending |