diff options
author | Hans Hagen <pragma@wxs.nl> | 2009-10-19 14:43:00 +0200 |
---|---|---|
committer | Hans Hagen <pragma@wxs.nl> | 2009-10-19 14:43:00 +0200 |
commit | e95ec93b5fe70c7d0e16071a1df8777cb9289d3b (patch) | |
tree | 3ea17776ea748226d95e52b420a5f30394e2d1eb /tex/context/base/lxml-aux.lua | |
parent | ea36ada779b87db193b865429d5db510713038a4 (diff) | |
download | context-e95ec93b5fe70c7d0e16071a1df8777cb9289d3b.tar.gz |
beta 2009.10.19 14:43
Diffstat (limited to 'tex/context/base/lxml-aux.lua')
-rw-r--r-- | tex/context/base/lxml-aux.lua | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/tex/context/base/lxml-aux.lua b/tex/context/base/lxml-aux.lua index eb2f3bb85..9eab06e45 100644 --- a/tex/context/base/lxml-aux.lua +++ b/tex/context/base/lxml-aux.lua @@ -9,6 +9,8 @@ if not modules then modules = { } end modules ['lxml-aux'] = { -- not all functions here make sense anymore vbut we keep them for -- compatibility reasons +local trace_manipulations = false trackers.register("lxml.manipulations", function(v) trace_manipulations = v end) + local xmlparseapply, xmlconvert, xmlcopy = xml.parse_apply, xml.convert, xml.copy local type = type @@ -238,16 +240,25 @@ xml.insert_element_before = function(r,p,e) xml.insert_element(r,p,e,true) end xml.inject_element_after = xml.inject_element xml.inject_element_before = function(r,p,e) xml.inject_element(r,p,e,true) end +local function report(what,pattern,c,e) + logs.report("xml","%s element '%s' (root: '%s', position: %s, index: %s, pattern: %s)",what,xml.name(e),xml.name(e.__p__),c,e.ni,pattern) +end + function xml.delete_element(root, pattern) local collected = xmlparseapply({ root },pattern) if collected then for c=1,#collected do local e = collected[c] - remove(e.__p__.dt,e.ni) - e.ni = nil + local p = e.__p__ + if p then + if trace_manipulations then + report('deleting',pattern,c,e) + end + remove(p.dt,e.ni) + e.ni = nil + end end end - return collection end function xml.replace_element(root, pattern, element) @@ -262,7 +273,13 @@ function xml.replace_element(root, pattern, element) if collected then for c=1,#collected do local e = collected[c] - e.__p__.dt[e.ni] = element.dt -- maybe not clever enough + local p = e.__p__ + if p then + if trace_manipulations then + report('replacing',pattern,c,e) + end + p.dt[e.ni] = element.dt -- maybe not clever enough + end end end end |