Изменения

нет описания правки
Строка 110: Строка 110:  
end
 
end
 
local child = clone (node [1])
 
local child = clone (node [1])
if type (child) == 'string' or table_set [child.__name] then
+
if not child or type (child) == 'string' or table_set [child.__name] then
 
return node
 
return node
 
end
 
end
--if node.__name == child.__name then
+
if node.__name == child.__name or child.__name == 'span' then
 +
child = assimilate (child)
 
for key, value in pairs (child) do
 
for key, value in pairs (child) do
 
if key == 'style' and node [key] and node [key] ~= '' then
 
if key == 'style' and node [key] and node [key] ~= '' then
Строка 122: Строка 123:  
end
 
end
 
node [1] = child [1]
 
node [1] = child [1]
--end
+
end
 
return node
 
return node
 
end
 
end
Строка 128: Строка 129:  
-- Serialise a parsed tag back:
 
-- Serialise a parsed tag back:
 
local function serialise (tag)
 
local function serialise (tag)
 +
if not tag then
 +
return ''
 +
end
 
if type (tag) == 'string' then
 
if type (tag) == 'string' then
 
return tag
 
return tag
Строка 150: Строка 154:     
-- Only these tags can be legitimately empty:
 
-- Only these tags can be legitimately empty:
local empty = to_set { 'th', 'td', 'br', 'hr', 'img' }
+
local empty = to_set { 'p', 'th', 'td', 'br', 'hr', 'img' }
   −
local grammar = P { V'fragment' * -1,
+
local grammar = P { Ct (V'fragment') * -1,
 
fragment = (V'tag' + C (V'char' ^ 1)) ^ 0,
 
fragment = (V'tag' + C (V'char' ^ 1)) ^ 0,
 
tag = Ct (V'open' * V'fragment' * V'close' + V'void') / function (tbl)
 
tag = Ct (V'open' * V'fragment' * V'close' + V'void') / function (tbl)
 
local tag = setmetatable ({ __name = tbl.__name }, { __tostring = serialise })
 
local tag = setmetatable ({ __name = tbl.__name }, { __tostring = serialise })
 +
--local tag = { __name = tbl.__name }
 
for _, attr in ipairs (tbl.__attrs) do
 
for _, attr in ipairs (tbl.__attrs) do
 
tag [attr.name] = attr.value
 
tag [attr.name] = attr.value
Строка 166: Строка 171:  
end
 
end
 
end
 
end
if --[[#tag == 0 or ]]type (tag [1]) == 'string' and match (tag [1], '^%s*$') and not empty [tag.__name] then
+
tag = assimilate (tag) -- try to assimilate the only child.
 +
if not empty [tag.__name] and (#tag == 0 or type (tag [1]) == 'string' and match (tag [1], '^%s*$')) then
 
-- An empty tag of this type can be safely dropped:
 
-- An empty tag of this type can be safely dropped:
 
return nil
 
return nil
 
end
 
end
return assimilate (tag) -- try to assimilate the only child.
+
return tag
 
end,
 
end,
 
open = lt * spaces * Cg (possible, '__name') * V'attributes' * spaces * gt,
 
open = lt * spaces * Cg (possible, '__name') * V'attributes' * spaces * gt,
Строка 202: Строка 208:     
return {
 
return {
 +
run = function (html)
 +
return tostring (grammar:match (html))
 +
end,
 
test = function (frame)
 
test = function (frame)
 
--return frame:preprocess (tostring (grammar:match (test)))
 
--return frame:preprocess (tostring (grammar:match (test)))