mirror of
https://github.com/TangentFoxy/lume.git
synced 2024-11-19 07:04:24 +00:00
Changed lume.wordwrap() to better retain existing whitespace
This commit is contained in:
parent
a6744d4ab3
commit
b25fee071f
26
lume.lua
26
lume.lua
@ -565,20 +565,26 @@ function lume.wordwrap(str, limit)
|
|||||||
check = limit
|
check = limit
|
||||||
end
|
end
|
||||||
local rtn = {}
|
local rtn = {}
|
||||||
for j, line in ipairs(lume.split(str, "\n")) do
|
local line = ""
|
||||||
local str
|
for word, spaces in str:gmatch("(%S+)(%s*)") do
|
||||||
for i, word in ipairs(lume.split(line)) do
|
local str = line .. word
|
||||||
local s = (str and (str .. " ") or "") .. word
|
if check(str) then
|
||||||
if check(s) then
|
table.insert(rtn, line .. "\n")
|
||||||
rtn[#rtn + 1] = str
|
line = word
|
||||||
str = word
|
|
||||||
else
|
else
|
||||||
str = s
|
line = str
|
||||||
|
end
|
||||||
|
for c in spaces:gmatch(".") do
|
||||||
|
if c == "\n" then
|
||||||
|
table.insert(rtn, line .. "\n")
|
||||||
|
line = ""
|
||||||
|
else
|
||||||
|
line = line .. c
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rtn[#rtn + 1] = str
|
|
||||||
end
|
end
|
||||||
return table.concat(rtn, "\n")
|
table.insert(rtn, line)
|
||||||
|
return table.concat(rtn)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user