summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/lxml-tex.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/lxml-tex.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/lxml-tex.lua84
1 files changed, 73 insertions, 11 deletions
diff --git a/Master/texmf-dist/tex/context/base/lxml-tex.lua b/Master/texmf-dist/tex/context/base/lxml-tex.lua
index 0503c511c45..0c58a47cc9f 100644
--- a/Master/texmf-dist/tex/context/base/lxml-tex.lua
+++ b/Master/texmf-dist/tex/context/base/lxml-tex.lua
@@ -38,9 +38,11 @@ local xmlapplylpath = xml.applylpath
local xmlunprivatized, xmlprivatetoken, xmlprivatecodes = xml.unprivatized, xml.privatetoken, xml.privatecodes
local xmlstripelement = xml.stripelement
-local variables = (interfaces and interfaces.variables) or { }
+local variables = interfaces and interfaces.variables or { }
-local insertbeforevalue, insertaftervalue = utilities.tables.insertbeforevalue, utilities.tables.insertaftervalue
+local settings_to_hash = utilities.parsers.settings_to_hash
+local insertbeforevalue = utilities.tables.insertbeforevalue
+local insertaftervalue = utilities.tables.insertaftervalue
local starttiming, stoptiming = statistics.starttiming, statistics.stoptiming
@@ -352,7 +354,7 @@ end
function lxml.checkindex(name)
local root = getid(name)
- return (root and root.index) or 0
+ return root and root.index or 0
end
function lxml.withindex(name,n,command) -- will change as name is always there now
@@ -434,16 +436,74 @@ function lxml.register(id,xmltable,filename)
return xmltable
end
-function lxml.include(id,pattern,attribute,recurse)
+-- function lxml.include(id,pattern,attribute,recurse,resolve)
+-- starttiming(xml)
+-- local root = getid(id)
+-- xml.include(root,pattern,attribute,recurse,function(filename)
+-- if filename then
+-- -- preprocessing
+-- filename = commands.preparedfile(filename)
+-- -- some protection
+-- if file.dirname(filename) == "" and root.filename then
+-- local dn = file.dirname(root.filename)
+-- if dn ~= "" then
+-- filename = file.join(dn,filename)
+-- end
+-- end
+-- if trace_loading then
+-- report_lxml("including file %a",filename)
+-- end
+-- -- handy if we have a flattened structure
+-- if resolve then
+-- filename = resolvers.resolve(filename) or filename
+-- end
+-- -- todo: check variants and provide
+-- noffiles, nofconverted = noffiles + 1, nofconverted + 1
+-- return resolvers.loadtexfile(filename) or ""
+-- else
+-- return ""
+-- end
+-- end)
+-- stoptiming(xml)
+-- end
+
+-- recurse prepare rootpath resolve basename
+
+local options_true = { "recurse", "prepare", "rootpath" }
+local options_nil = { "prepare", "rootpath" }
+
+function lxml.include(id,pattern,attribute,options)
starttiming(xml)
local root = getid(id)
- xml.include(root,pattern,attribute,recurse,function(filename)
+ if options == true then
+ -- downward compatible
+ options = options_true
+ elseif not options then
+ -- downward compatible
+ options = options_nil
+ else
+ options = settings_to_hash(options) or { }
+ end
+ xml.include(root,pattern,attribute,options.recurse,function(filename)
if filename then
- filename = commands.preparedfile(filename)
- if file.dirname(filename) == "" and root.filename then
- local dn = file.dirname(root.filename)
- if dn ~= "" then
- filename = file.join(dn,filename)
+ -- preprocessing
+ if options.prepare then
+ filename = commands.preparedfile(filename)
+ end
+ -- handy if we have a flattened structure
+ if options.basename then
+ filename = file.basename(filename)
+ end
+ if options.resolve then
+ filename = resolvers.resolve(filename) or filename
+ end
+ -- some protection
+ if options.rootpath then
+ if file.dirname(filename) == "" and root.filename then
+ local dn = file.dirname(root.filename)
+ if dn ~= "" then
+ filename = file.join(dn,filename)
+ end
end
end
if trace_loading then
@@ -1125,7 +1185,9 @@ local function command(collected,cmd,otherwise)
lxml.addindex(name,false,true)
ix = e.ix
end
- if wildcard then
+ if not ix then
+ report_lxml("no valid node index for element %a in command %s",name,cmd)
+ elseif wildcard then
contextsprint(ctxcatcodes,"\\xmlw{",(gsub(cmd,"%*",e.tg)),"}{",name,"::",ix,"}")
else
contextsprint(ctxcatcodes,"\\xmlw{",cmd,"}{",name,"::",ix,"}")