diff options
author | Hans Hagen <pragma@wxs.nl> | 2020-04-19 20:29:51 +0200 |
---|---|---|
committer | Context Git Mirror Bot <phg@phi-gamma.net> | 2020-04-19 20:29:51 +0200 |
commit | 3c25716e01b7251f0f7504481692421a729e4b53 (patch) | |
tree | f35478a7500c113744dd3875f3f8ab486a21c595 /tex/context/base/mkiv/lxml-aux.lua | |
parent | 9a1b9756939e12e328dea3633d9fe3cbde8f154b (diff) | |
download | context-3c25716e01b7251f0f7504481692421a729e4b53.tar.gz |
2020-04-19 19:24:00
Diffstat (limited to 'tex/context/base/mkiv/lxml-aux.lua')
-rw-r--r-- | tex/context/base/mkiv/lxml-aux.lua | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/tex/context/base/mkiv/lxml-aux.lua b/tex/context/base/mkiv/lxml-aux.lua index 67ee31c88..dd0e733c0 100644 --- a/tex/context/base/mkiv/lxml-aux.lua +++ b/tex/context/base/mkiv/lxml-aux.lua @@ -22,7 +22,7 @@ local xmlapplylpath = xml.applylpath local type, next, setmetatable, getmetatable = type, next, setmetatable, getmetatable local insert, remove, fastcopy, concat = table.insert, table.remove, table.fastcopy, table.concat -local gmatch, gsub, format, find, strip = string.gmatch, string.gsub, string.format, string.find, string.strip +local gmatch, gsub, format, find, strip, match = string.gmatch, string.gsub, string.format, string.find, string.strip, string.match local utfbyte = utf.byte local lpegmatch, lpegpatterns = lpeg.match, lpeg.patterns local striplinepatterns = utilities.strings.striplinepatterns @@ -247,6 +247,33 @@ function xml.delete(root,pattern) end end +function xml.wipe(root,pattern) -- not yet in manual + local collected = xmlapplylpath(root,pattern) + if collected then + for c=1,#collected do + local e = collected[c] + local p = e.__p__ + if p then + local d = p.dt + local ni = e.ni + if ni <= #d then + local dt = e.dt + if #dt == 1 then + local d1 = dt[1] + if type(d1) == "string" and match(d1,"^%s*$") then + if trace_manipulations then + report('wiping',pattern,c,e) + end + remove(d,ni) + redo_ni(d) -- can be made faster and inlined + end + end + end + end + end + end +end + function xml.replace(root,pattern,whatever) local element = root and xmltoelement(whatever,root) local collected = element and xmlapplylpath(root,pattern) |