summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/lxml-aux.lua
diff options
context:
space:
mode:
authorContext Git Mirror Bot <phg42.2a@gmail.com>2016-02-17 12:15:07 +0100
committerContext Git Mirror Bot <phg42.2a@gmail.com>2016-02-17 12:15:07 +0100
commitb13dd166ce8563c60c10affc97ab28940d6a7776 (patch)
tree6b15f0462d36ae916875ce1fbcdd990660d3f410 /tex/context/base/mkiv/lxml-aux.lua
parenta036ac2dd19b592316e1b479360e9e6c6700e935 (diff)
downloadcontext-b13dd166ce8563c60c10affc97ab28940d6a7776.tar.gz
2016-02-17 11:13:00
Diffstat (limited to 'tex/context/base/mkiv/lxml-aux.lua')
-rw-r--r--tex/context/base/mkiv/lxml-aux.lua98
1 files changed, 52 insertions, 46 deletions
diff --git a/tex/context/base/mkiv/lxml-aux.lua b/tex/context/base/mkiv/lxml-aux.lua
index 01c2a8bfc..f28fd819d 100644
--- a/tex/context/base/mkiv/lxml-aux.lua
+++ b/tex/context/base/mkiv/lxml-aux.lua
@@ -370,6 +370,8 @@ xml.insertbefore = function(r,p,e) insert_element(r,p,e,true) end
xml.injectafter = inject_element
xml.injectbefore = function(r,p,e) inject_element(r,p,e,true) end
+-- loaddata can restrict loading
+
local function include(xmldata,pattern,attribute,recursive,loaddata,level)
-- attribute = attribute or 'href'
pattern = pattern or 'include'
@@ -383,56 +385,60 @@ local function include(xmldata,pattern,attribute,recursive,loaddata,level)
local ek = collected[c]
local name = nil
local ekdt = ek.dt
- local ekat = ek.at
- local ekrt = ek.__p__
- local epdt = ekrt.dt
- if not attribute or attribute == "" then
- name = (type(ekdt) == "table" and ekdt[1]) or ekdt -- check, probably always tab or str
- end
- if not name then
- for a in gmatch(attribute or "href","([^|]+)") do
- name = ekat[a]
- if name then
- break
+ if ekdt then
+ local ekat = ek.at
+ local ekrt = ek.__p__
+ if ekrt then
+ local epdt = ekrt.dt
+ if not attribute or attribute == "" then
+ name = (type(ekdt) == "table" and ekdt[1]) or ekdt -- check, probably always tab or str
end
- end
- end
- local data = nil
- if name and name ~= "" then
- data = loaddata(name) or ""
- if trace_inclusions then
- report_xml("including %s bytes from %a at level %s by pattern %a and attribute %a (%srecursing)",#data,name,level,pattern,attribute or "",recursive and "" or "not ")
- end
- end
- if not data or data == "" then
- epdt[ek.ni] = "" -- xml.empty(d,k)
- elseif ekat["parse"] == "text" then
- -- for the moment hard coded
- epdt[ek.ni] = xml.escaped(data) -- d[k] = xml.escaped(data)
- else
- local xi = xmlinheritedconvert(data,xmldata)
- if not xi then
- epdt[ek.ni] = "" -- xml.empty(d,k)
- else
- if recursive then
- include(xi,pattern,attribute,recursive,loaddata,level+1)
+ if not name then
+ for a in gmatch(attribute or "href","([^|]+)") do
+ name = ekat[a]
+ if name then
+ break
+ end
+ end
end
- local child = xml.body(xi) -- xml.assign(d,k,xi)
- child.__p__ = ekrt
- child.__f__ = name -- handy for tracing
- epdt[ek.ni] = child
- local inclusions = xmldata.settings.inclusions
- if inclusions then
- inclusions[#inclusions+1] = name
- else
- xmldata.settings.inclusions = { name }
+ local data = nil
+ if name and name ~= "" then
+ data = loaddata(name) or ""
+ if trace_inclusions then
+ report_xml("including %s bytes from %a at level %s by pattern %a and attribute %a (%srecursing)",#data,name,level,pattern,attribute or "",recursive and "" or "not ")
+ end
end
- if child.er then
- local badinclusions = xmldata.settings.badinclusions
- if badinclusions then
- badinclusions[#badinclusions+1] = name
+ if not data or data == "" then
+ epdt[ek.ni] = "" -- xml.empty(d,k)
+ elseif ekat["parse"] == "text" then
+ -- for the moment hard coded
+ epdt[ek.ni] = xml.escaped(data) -- d[k] = xml.escaped(data)
+ else
+ local xi = xmlinheritedconvert(data,xmldata)
+ if not xi then
+ epdt[ek.ni] = "" -- xml.empty(d,k)
else
- xmldata.settings.badinclusions = { name }
+ if recursive then
+ include(xi,pattern,attribute,recursive,loaddata,level+1)
+ end
+ local child = xml.body(xi) -- xml.assign(d,k,xi)
+ child.__p__ = ekrt
+ child.__f__ = name -- handy for tracing
+ epdt[ek.ni] = child
+ local inclusions = xmldata.settings.inclusions
+ if inclusions then
+ inclusions[#inclusions+1] = name
+ else
+ xmldata.settings.inclusions = { name }
+ end
+ if child.er then
+ local badinclusions = xmldata.settings.badinclusions
+ if badinclusions then
+ badinclusions[#badinclusions+1] = name
+ else
+ xmldata.settings.badinclusions = { name }
+ end
+ end
end
end
end