diff options
author | pixel <pixel> | 2007-06-12 07:41:19 +0000 |
---|---|---|
committer | pixel <pixel> | 2007-06-12 07:41:19 +0000 |
commit | 4a850a197c9e3ba39a05dfbb8f635e5a5950d9ff (patch) | |
tree | 3311f08435e550e5ca9e6118f5f839d452892d5b /lib | |
parent | 3cbdf9478a18f21e28c3bc196fed72e26ca87168 (diff) |
-) Code cleanup.
-) Adding raw method.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/xmllib.lua | 46 |
1 files changed, 31 insertions, 15 deletions
diff --git a/lib/xmllib.lua b/lib/xmllib.lua index 4bdf977..adebc15 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.8 2007-05-30 17:59:50 pixel Exp $ */ +/* $Id: xmllib.lua,v 1.9 2007-06-12 07:41:19 pixel Exp $ */ ]]-- @@ -33,16 +33,6 @@ local attribute_replacements = { { '"', '\\"' }, } -local function generic_escape(str, replacements) - local _, r - - for _, r in pairs(replacements) do - str = string.gsub(str, r[1], r[2]) - end - - return str -end - local function xml_escape(str) return generic_escape(str, xml_replacements) end @@ -68,6 +58,16 @@ local function process_lf(xm) } end +local function process_raw(xm, a) + return { + istop = true, + nodes = { + a + }, + type = "raw", + } +end + local function burrow(xm, t) local k, v @@ -160,6 +160,23 @@ local function space_indent(depth) return string.rep(" ", 4 * depth) end +local function render_comment(depth, v) + return space_indent(depth) .. "<!-- " .. v.nodes[1] .. " -->\n" +end + +local function render_lf(depth, v) + return "\n" +end + +local function render_raw(depth, v) +end + +local special_renders = { + comment = render_comment, + lf = render_lf, + raw = render_raw, +} + local function do_render_r(v, depth) local middle, i, n = "" @@ -169,10 +186,8 @@ local function do_render_r(v, depth) r = r .. v:read() .. "\n" end return r - elseif v.type == "comment" then - return space_indent(depth) .. "<!-- " .. v.nodes[1] .. " -->\n" - elseif v.type == "lf" then - return "\n" + 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 for i, n in ipairs(v.nodes) do @@ -214,6 +229,7 @@ function NewXmlMarkup() local r = { comment = process_comment, lf = process_lf, + raw = process_raw, tops = {}, render = do_render, doctype = '<?xml version="1.0" encoding="UTF-8"?>', |