diff options
-rw-r--r-- | lib/xmllib.lua | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/lib/xmllib.lua b/lib/xmllib.lua index 8c4a258..78cf551 100644 --- a/lib/xmllib.lua +++ b/lib/xmllib.lua @@ -19,7 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: xmllib.lua,v 1.12 2007-06-14 14:11:33 pixel Exp $ */ +/* $Id: xmllib.lua,v 1.13 2007-06-16 13:44:20 pixel Exp $ */ ]]-- @@ -168,19 +168,19 @@ local function space_indent(depth) end local function render_comment(depth, v) - return space_indent(depth) .. "<!-- " .. v.nodes[1] .. " -->\n" + return space_indent(depth) .. "<!-- " .. v.nodes[1] .. " -->\n", true end local function render_lf(depth, v) - return "\n" + return "\n", true end local function render_raw(depth, v) - return v.nodes[1] + return v.nodes[1], true end local function render_empty(depth, v) - return "" + return "", false end local special_renders = { @@ -191,28 +191,39 @@ local special_renders = { } local function do_render_r(v, depth) - local middle, i, n = "" + local middle, i, n, rec, enters, r_enters = "" if v.__objname == "Handle" then local r = "" while not v:isclosed() do r = r .. v:read() .. "\n" end - return r + return r, true elseif type(v.type) == "string" and type(special_renders[v.type]) == "function" then return special_renders[v.type](depth, v) elseif type(v.key) == "string" then if type(v.nodes) == "table" then + enters = false for i, n in ipairs(v.nodes) do if type(n) == "string" then - middle = middle .. "\n" .. n + if middle ~= "" then + middle = middle .. "\n" .. n + enters = true + else + middle = n + end elseif type(n) == "table" then - middle = middle .. "\n" .. do_render_r(n, depth + 1) .. "\n" .. space_indent(depth) + rec, r_enters = do_render_r(n, depth + 1) + if enters or r_enters or middle ~= "" then + middle = middle .. "\n" .. rec .. "\n" .. space_indent(depth) + else + middle = rec + end end end - return space_indent(depth) .. "<" .. v.key .. render_attrs(v.attrs) .. ">" .. middle .. "</" .. v.key .. ">" + return space_indent(depth) .. "<" .. v.key .. render_attrs(v.attrs) .. ">" .. middle .. "</" .. v.key .. ">", true else - return space_indent(depth) .. "<" .. v.key .. render_attrs(v.attrs) .. " />" + return space_indent(depth) .. "<" .. v.key .. render_attrs(v.attrs) .. " />", true end else error "Inconsistancy in the XML structure." |