summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/lxml-tex.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/lxml-tex.lua')
-rw-r--r--tex/context/base/mkiv/lxml-tex.lua24
1 files changed, 23 insertions, 1 deletions
diff --git a/tex/context/base/mkiv/lxml-tex.lua b/tex/context/base/mkiv/lxml-tex.lua
index 079ab29da..00bff7873 100644
--- a/tex/context/base/mkiv/lxml-tex.lua
+++ b/tex/context/base/mkiv/lxml-tex.lua
@@ -14,7 +14,7 @@ local concat, insert, remove, sortedkeys, reversed = table.concat, table.insert,
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
-local P, S, C, Cc, Cs = lpeg.P, lpeg.S, lpeg.C, lpeg.Cc, lpeg.Cs
+local P, S, C = lpeg.P, lpeg.S, lpeg.C
local patterns = lpeg.patterns
local setmetatableindex = table.setmetatableindex
local formatters, strip = string.formatters, string.strip
@@ -1755,6 +1755,23 @@ local function concatlist(collected,separator,lastseparator,textonly) -- test th
concatrange(collected,false,false,separator,lastseparator,textonly)
end
+local function depth(collected)
+ local d = 0
+ if collected then
+ local c = collected and collected[1]
+ if c.tg then
+ while c do
+ d = d + 1
+ c = c.__p__
+ if not c then
+ break
+ end
+ end
+ end
+ end
+ contextsprint(ctxcatcodes,d)
+end
+
texfinalizers.first = first
texfinalizers.last = last
texfinalizers.all = all
@@ -1778,6 +1795,7 @@ texfinalizers.concatrange = concatrange
texfinalizers.chainattribute = chainattribute
texfinalizers.chainpath = chainpath
texfinalizers.default = all -- !!
+texfinalizers.depth = depth
function texfinalizers.tag(collected,n)
if collected then
@@ -1863,6 +1881,10 @@ lxml.verbatim = verbatim
-- helpers
+function lxml.depth(id)
+ depth { getid(id) }
+end
+
function lxml.first(id,pattern)
local collected = xmlapplylpath(getid(id),pattern)
if collected then