Skip to content

Commit a499ba7

Browse files
committed
Strip leading/trailing space from TextElements
1 parent b3ff06c commit a499ba7

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

fluent/resource.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,20 @@ node_types.Pattern = class({
119119
return tablex.reduce(math.min, indents) or 0
120120
end
121121
local striplen = tablex.reduce(math.min, tablex.imap(mindent, self.elements)) or 0
122-
local i, strippref = 0, "\n"
123-
while i < striplen do
122+
local i, strippref = 1, "\n\n"
123+
while i <= striplen do
124124
strippref = strippref .. " "
125125
i = i + 1
126126
end
127127
local strip = function(node, key, len)
128128
if type(node.value) == "string" then
129129
local value = string.gsub(node.value, "\r\n", "\n")
130130
if len >= 1 then
131-
self.elements[key].value = string.gsub(value, strippref, "\n")
131+
value = string.gsub(value, strippref, "\n")
132132
end
133+
value = string.gsub(value, "^[\n ]+", "")
134+
value = string.gsub(value, "[\n ]+$", "")
135+
self.elements[key].value = value
133136
end
134137
end
135138
tablex.foreachi(self.elements, strip, striplen)

0 commit comments

Comments
 (0)