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:
parent
ddce306578
commit
f5f6818d6e
@ -138,6 +138,7 @@ end
|
|||||||
local function wordwrap(text)
|
local function wordwrap(text)
|
||||||
text = rpm.expand(text .. "\n")
|
text = rpm.expand(text .. "\n")
|
||||||
text = string.gsub(text, "\t", " ")
|
text = string.gsub(text, "\t", " ")
|
||||||
|
text = string.gsub(text, "\r", "\n")
|
||||||
text = string.gsub(text, " +\n", "\n")
|
text = string.gsub(text, " +\n", "\n")
|
||||||
text = string.gsub(text, "\n+\n", "\n\n")
|
text = string.gsub(text, "\n+\n", "\n\n")
|
||||||
text = string.gsub(text, "^\n", "")
|
text = string.gsub(text, "^\n", "")
|
||||||
@ -160,7 +161,8 @@ local function wordwrap(text)
|
|||||||
end
|
end
|
||||||
advance = string.gsub(advance, "– ", " ")
|
advance = string.gsub(advance, "– ", " ")
|
||||||
pos = pos + wl
|
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
|
pos = pos + wl
|
||||||
else
|
else
|
||||||
word = advance .. string.gsub(word, "^%s*", "")
|
word = advance .. string.gsub(word, "^%s*", "")
|
||||||
|
Loading…
Reference in New Issue
Block a user