wordwrap: fix some corner cases

– 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
This commit is contained in:
Nicolas Mailhot 2019-11-11 13:15:56 +01:00 committed by ignatenkobrain
parent ddce306578
commit f5f6818d6e

View File

@ -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*", "")