summaryrefslogtreecommitdiff
path: root/tex/context/base/strc-tag.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/strc-tag.lua')
-rw-r--r--tex/context/base/strc-tag.lua95
1 files changed, 65 insertions, 30 deletions
diff --git a/tex/context/base/strc-tag.lua b/tex/context/base/strc-tag.lua
index e368eae37..6f69144dc 100644
--- a/tex/context/base/strc-tag.lua
+++ b/tex/context/base/strc-tag.lua
@@ -8,9 +8,10 @@ if not modules then modules = { } end modules ['strc-tag'] = {
-- This is rather experimental code.
+local type = type
local insert, remove, unpack, concat = table.insert, table.remove, table.unpack, table.concat
local gsub, find, topattern, format = string.gsub, string.find, string.topattern, string.format
-local lpegmatch = lpeg.match
+local lpegmatch, P, S, C = lpeg.match, lpeg.P, lpeg.S, lpeg.C
local texattribute = tex.attribute
local allocate = utilities.storage.allocate
local settings_to_hash = utilities.parsers.settings_to_hash
@@ -26,23 +27,26 @@ local a_tagged = attributes.private('tagged')
local unsetvalue = attributes.unsetvalue
local codeinjections = backends.codeinjections
-local taglist = allocate()
-local properties = allocate()
-local labels = allocate()
-local stack = { }
-local chain = { }
-local ids = { }
-local enabled = false
-local tagdata = { } -- used in export
-local tagmetadata = { } -- used in export
-
-local tags = structures.tags
-tags.taglist = taglist -- can best be hidden
-tags.labels = labels
-tags.data = tagdata
-tags.metadata = tagmetadata
-
-local properties = allocate {
+local taglist = allocate()
+local properties = allocate()
+local userproperties = allocate()
+local labels = allocate()
+local stack = { }
+local chain = { }
+local ids = { }
+local enabled = false
+local tagdata = { } -- used in export
+local tagmetadata = { } -- used in export
+local tagcontext = { }
+
+local tags = structures.tags
+tags.taglist = taglist -- can best be hidden
+tags.labels = labels
+tags.data = tagdata
+tags.metadata = tagmetadata
+tags.userproperties = userproperties -- used in backend
+
+local properties = allocate {
document = { pdf = "Div", nature = "display" },
@@ -203,7 +207,7 @@ tags.properties = properties
local lasttags = { }
local userdata = { }
-tags.userdata = userdata
+tags.userdata = userdata
function tags.setproperty(tag,key,value)
local p = properties[tag]
@@ -237,21 +241,15 @@ local nstack = 0
function tags.start(tag,specification)
local label, detail, user
if specification then
- label, detail, user = specification.label, specification.detail, specification.userdata
+ label = specification.label
+ detail = specification.detail
+ user = specification.userdata
end
if not enabled then
codeinjections.enabletags()
enabled = true
end
--
---~ labels[tag] = label ~= "" and label or tag
---~ local fulltag
---~ if detail and detail ~= "" then
---~ fulltag = tag .. ":" .. detail
---~ else
---~ fulltag = tag
---~ end
- --
local fulltag = label ~= "" and label or tag
labels[tag] = fulltag
if detail and detail ~= "" then
@@ -266,6 +264,9 @@ function tags.start(tag,specification)
nstack = nstack + 1
chain[nstack] = completetag
stack[nstack] = t
+ --
+ tagcontext[tag] = completetag
+ --
-- a copy as we can add key values for alt and actualtext if needed:
taglist[t] = { unpack(chain,1,nstack) }
--
@@ -319,10 +320,44 @@ function tags.last(tag)
return lasttags[tag] -- or false
end
-function tags.lastinchain()
- return chain[nstack]
+function tags.lastinchain(tag)
+ if tag and tag ~= "" then
+ return tagcontext[tag]
+ else
+ return chain[nstack]
+ end
+end
+
+local strip = C((1-S(":-"))^1)
+
+commands.getelementtag = function()
+ local fulltag = chain[nstack]
+ if fulltag then
+ context(lpegmatch(strip,fulltag))
+ end
+end
+
+function tags.setuserproperties(tag,list)
+ if list then
+ tag = tagcontext[tag]
+ else
+ tag, list = chain[nstack], tag
+ end
+ if tag then
+ local l = settings_to_hash(list)
+ local p = userproperties[tag]
+ if p then
+ for k, v in next, l do
+ p[k] = v
+ end
+ else
+ userproperties[tag] = l
+ end
+ end
end
+commands.setelementuserproperties = tags.setuserproperties
+
function structures.atlocation(str)
local location = gsub(concat(taglist[texattribute[a_tagged]],"-"),"%-%d+","")
return find(location,topattern(str)) ~= nil