From f5f6818d6eb8c0384e497231b9e8af667d78b76e Mon Sep 17 00:00:00 2001 From: Nicolas Mailhot Date: Mon, 11 Nov 2019 13:15:56 +0100 Subject: [PATCH] wordwrap: fix some corner cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit – handle CR in addition to LF – be smarter in presence of lists – fix off-by-one mistake when a LF in the processed text falls exactly on the 81st column --- common.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common.lua b/common.lua index e087a1c..e469ba0 100644 --- a/common.lua +++ b/common.lua @@ -138,6 +138,7 @@ end local function wordwrap(text) text = rpm.expand(text .. "\n") text = string.gsub(text, "\t", " ") + text = string.gsub(text, "\r", "\n") text = string.gsub(text, " +\n", "\n") text = string.gsub(text, "\n+\n", "\n\n") text = string.gsub(text, "^\n", "") @@ -160,7 +161,8 @@ local function wordwrap(text) end advance = string.gsub(advance, "– ", " ") pos = pos + wl - elseif (pos + wl < 81) then + elseif (pos + wl < 81) or + ((pos + wl == 81) and string.match(word, "\n$")) then pos = pos + wl else word = advance .. string.gsub(word, "^%s*", "")