Строка 32: |
Строка 32: |
| 'a', 'span', 'b', 'i', 'strong', 'em', | | 'a', 'span', 'b', 'i', 'strong', 'em', |
| 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', | | 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', |
− | 'p', 'div', 'br', 'img', | + | 'p', 'div', 'br', 'hr', 'img', |
| 'table', 'thead', 'tbody', 'tfoot', 'tr', 'th', 'td' | | 'table', 'thead', 'tbody', 'tfoot', 'tr', 'th', 'td' |
| } | | } |
− |
| |
− | -- Only these tags can be legitimately empty:
| |
− | local empty = to_set { 'th', 'td', 'br', 'hr' }
| |
| | | |
| -- Table tags are unmergeable: | | -- Table tags are unmergeable: |
Строка 118: |
Строка 115: |
| --if node.__name == child.__name then | | --if node.__name == child.__name then |
| for key, value in pairs (child) do | | for key, value in pairs (child) do |
− | if key == 'style' and node [key] then | + | if key == 'style' and node [key] and node [key] ~= '' then |
| node [key] = node [key] .. '; ' .. value | | node [key] = node [key] .. '; ' .. value |
| else | | else |
Строка 136: |
Строка 133: |
| local serialised = { '<' .. tag.__name } | | local serialised = { '<' .. tag.__name } |
| for attr, value in pairs (tag) do | | for attr, value in pairs (tag) do |
− | if type (attr) ~= 'number' and attr ~= '__name' then | + | if type (attr) ~= 'number' and attr ~= '__name' and value ~= '' then |
| serialised [#serialised + 1] = attr .. '="' .. gsub (value, '"', '\\"', 1, true) .. '"' | | serialised [#serialised + 1] = attr .. '="' .. gsub (value, '"', '\\"', 1, true) .. '"' |
| end | | end |
Строка 152: |
Строка 149: |
| end | | end |
| | | |
− | local grammar = P { V'fragment' * -1, | + | -- Only these tags can be legitimately empty: |
| + | local empty = to_set { 'th', 'td', 'br', 'hr', 'img' } |
| + | |
| + | 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 = { __name = tbl.__name } --setmetatable ({ __name = tbl.__name }, { __tostring = serialise }) | + | local tag = setmetatable ({ __name = tbl.__name }, { __tostring = serialise }) |
| for _, attr in ipairs (tbl.__attrs) do | | for _, attr in ipairs (tbl.__attrs) do |
| tag [attr.name] = attr.value | | tag [attr.name] = attr.value |
Строка 203: |
Строка 203: |
| return { | | return { |
| test = function (frame) | | test = function (frame) |
− | return mw.dumpObject {grammar:match (test)} | + | return frame:preprocess (grammar:match (test))--mw.dumpObject (grammar:match (test)) |
| end | | end |
| } | | } |