summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/lxml-tex.lua
diff options
context:
space:
mode:
authorContext Git Mirror Bot <phg42.2a@gmail.com>2016-02-01 14:15:07 +0100
committerContext Git Mirror Bot <phg42.2a@gmail.com>2016-02-01 14:15:07 +0100
commit46c0953642cf16e575215a49dc36984a681a91d1 (patch)
tree7cc4ca2fde94a90269ff573a03c68d31ece78140 /tex/context/base/mkiv/lxml-tex.lua
parent7874dbe9834f98579d88719fc4fbe3a67c042492 (diff)
downloadcontext-46c0953642cf16e575215a49dc36984a681a91d1.tar.gz
2016-02-01 13:28:00
Diffstat (limited to 'tex/context/base/mkiv/lxml-tex.lua')
-rw-r--r--tex/context/base/mkiv/lxml-tex.lua36
1 files changed, 35 insertions, 1 deletions
diff --git a/tex/context/base/mkiv/lxml-tex.lua b/tex/context/base/mkiv/lxml-tex.lua
index 0ec981d68..abb807181 100644
--- a/tex/context/base/mkiv/lxml-tex.lua
+++ b/tex/context/base/mkiv/lxml-tex.lua
@@ -11,7 +11,7 @@ if not modules then modules = { } end modules ['lxml-tex'] = {
-- be an cldf-xml helper library.
local utfchar = utf.char
-local concat, insert, remove, sortedkeys = table.concat, table.insert, table.remove, table.sortedkeys
+local concat, insert, remove, sortedkeys, reversed = table.concat, table.insert, table.remove, table.sortedkeys, table.reverse
local format, sub, gsub, find, gmatch, match = string.format, string.sub, string.gsub, string.find, string.gmatch, string.match
local type, next, tonumber, tostring, select = type, next, tonumber, tostring, select
local lpegmatch = lpeg.match
@@ -1396,6 +1396,35 @@ local function chainattribute(collected,arguments) -- todo: optional levels
end
end
+local function chainpath(collected,nonamespace)
+ if collected and #collected > 0 then
+ local e = collected[1]
+ local t = { }
+ while e do
+ local tg = e.tg
+ local rt = e.__p__
+ local ns = e.ns
+ if tg == "@rt@" then
+ break
+ elseif rt.tg == "@rt@" then
+ if nonamespace or not ns or ns == "" then
+ t[#t+1] = tg
+ else
+ t[#t+1] = ns .. ":" .. tg
+ end
+ else
+ if nonamespace or not ns or ns == "" then
+ t[#t+1] = tg .. "[" .. e.ei .. "]"
+ else
+ t[#t+1] = ns .. ":" .. tg .. "[" .. e.ei .. "]"
+ end
+ end
+ e = rt
+ end
+ contextsprint(notcatcodes,concat(reversed(t),"/"))
+ end
+end
+
local function text(collected)
if collected then
local nc = #collected
@@ -1513,6 +1542,7 @@ texfinalizers.index = index
texfinalizers.concat = concat
texfinalizers.concatrange = concatrange
texfinalizers.chainattribute = chainattribute
+texfinalizers.chainpath = chainpath
texfinalizers.default = all -- !!
local concat = table.concat
@@ -1690,6 +1720,10 @@ function lxml.chainattribute(id,pattern,a,default)
chainattribute(xmlapplylpath(getid(id),pattern),a,default)
end
+function lxml.path(id,pattern,nonamespace)
+ chainpath(xmlapplylpath(getid(id),pattern),nonamespace)
+end
+
function lxml.concatrange(id,pattern,start,stop,separator,lastseparator,textonly) -- test this on mml
concatrange(xmlapplylpath(getid(id),pattern),start,stop,separator,lastseparator,textonly)
end