diff options
Diffstat (limited to 'tex/context/base/mkiv/strc-tag.lua')
-rw-r--r-- | tex/context/base/mkiv/strc-tag.lua | 106 |
1 files changed, 70 insertions, 36 deletions
diff --git a/tex/context/base/mkiv/strc-tag.lua b/tex/context/base/mkiv/strc-tag.lua index 649465a6a..0453640ca 100644 --- a/tex/context/base/mkiv/strc-tag.lua +++ b/tex/context/base/mkiv/strc-tag.lua @@ -15,7 +15,6 @@ local type, next = type, next local insert, remove, unpack, concat, merge = table.insert, table.remove, table.unpack, table.concat, table.merge local find, topattern, format = string.find, string.topattern, string.format local lpegmatch, P, S, C, Cc = lpeg.match, lpeg.P, lpeg.S, lpeg.C, lpeg.Cc -local texattribute = tex.attribute local allocate = utilities.storage.allocate local settings_to_hash = utilities.parsers.settings_to_hash local setmetatableindex = table.setmetatableindex @@ -24,34 +23,44 @@ local trace_tags = false trackers.register("structures.tags", function(v) trace local report_tags = logs.reporter("structure","tags") -local attributes = attributes -local structures = structures -local implement = interfaces.implement - -local a_tagged = attributes.private('tagged') - -local unsetvalue = attributes.unsetvalue -local codeinjections = backends.codeinjections - -local taglist = allocate() -- access by attribute -local specifications = allocate() -- access by fulltag -local labels = allocate() -local stack = { } -local chain = { } -local ids = { } -local enabled = false -local tagcontext = { } -local tagpatterns = { } -local lasttags = { } -local stacksize = 0 -local metadata = nil -- applied to the next element -local documentdata = { } - -local tags = structures.tags -tags.taglist = taglist -- can best be hidden -tags.labels = labels -tags.patterns = tagpatterns -tags.specifications = specifications +local attributes = attributes +local structures = structures +local implement = interfaces.implement + +local a_tagged = attributes.private('tagged') + +local unsetvalue = attributes.unsetvalue +local codeinjections = backends.codeinjections + +local texgetattribute = tex.getattribute +local texsetattribute = tex.setattribute + +local taglist = allocate() -- access by attribute +local specifications = allocate() -- access by fulltag +local labels = allocate() +local stack = { } +local chain = { } +local ids = { } +local enabled = false +local tagcontext = { } +local tagpatterns = { } +local lasttags = { } +local stacksize = 0 +local metadata = nil -- applied to the next element +local documentdata = { } +local extradata = false + +local tags = structures.tags +tags.taglist = taglist -- can best be hidden +tags.labels = labels +tags.patterns = tagpatterns +tags.specifications = specifications + +function tags.current() + if stacksize > 0 then + return stack[stacksize] -- maybe copy or proxy + end +end -- Tags are internally stored as: -- @@ -126,6 +135,7 @@ local properties = allocate { -- todo: more "record = true" to improve forma listcontent = { pdf = "P", nature = "mixed" }, listdata = { pdf = "P", nature = "mixed" }, listpage = { pdf = "Reference", nature = "mixed" }, + listtext = { pdf = "Span", nature = "inline" }, delimitedblock = { pdf = "BlockQuote", nature = "display" }, delimited = { pdf = "Quote", nature = "inline" }, @@ -157,9 +167,11 @@ local properties = allocate { -- todo: more "record = true" to improve forma subformula = { pdf = "Div", nature = "display" }, link = { pdf = "Link", nature = "inline" }, + reference = { pdf = "Span", nature = "inline" }, margintextblock = { pdf = "Span", nature = "inline" }, margintext = { pdf = "Span", nature = "inline" }, + marginanchor = { pdf = "Span", nature = "inline" }, math = { pdf = "Div", nature = "inline" }, -- no display mn = { pdf = "Span", nature = "mixed" }, @@ -204,6 +216,14 @@ local properties = allocate { -- todo: more "record = true" to improve forma combinationpair = { pdf = "Span", nature = "display" }, combinationcontent = { pdf = "Span", nature = "mixed" }, combinationcaption = { pdf = "Span", nature = "mixed" }, + + publications = { pdf = "Div", nature = "display" }, + publication = { pdf = "Div", nature = "mixed" }, + pubfld = { pdf = "Span", nature = "inline" }, + + block = { pdf = "Div", nature = "display" }, + userdata = { pdf = "Div", nature = "display" }, + } tags.properties = properties @@ -215,7 +235,7 @@ local patterns = setmetatableindex(function(t,tag) end) function tags.locatedtag(tag) - local attribute = texattribute[a_tagged] + local attribute = texgetattribute(a_tagged) if attribute >= 0 then local specification = taglist[attribute] if specification then @@ -235,7 +255,7 @@ function tags.locatedtag(tag) end function structures.atlocation(str) - local specification = taglist[texattribute[a_tagged]] + local specification = taglist[texgetattribute(a_tagged)] if specification then if list then local taglist = specification.taglist @@ -287,6 +307,20 @@ function tags.getmetadata() return documentdata or { } end +function tags.registerextradata(name,serializer) + if type(serializer) == "function" then + if extradata then + extradata[name] = serializer + else + extradata = { [name] = serializer } + end + end +end + +function tags.getextradata() + return extradata +end + function tags.start(tag,specification) if not enabled then codeinjections.enabletags() @@ -349,7 +383,7 @@ function tags.start(tag,specification) specification.metadata = documentdata end -- - texattribute[a_tagged] = attribute + texsetattribute(a_tagged,attribute) return attribute end @@ -364,7 +398,7 @@ function tags.restart(attribute) taglist[attribute] = { taglist = { unpack(chain,1,stacksize) } } end stack[stacksize] = attribute - texattribute[a_tagged] = attribute + texsetattribute(a_tagged,attribute) return attribute end @@ -374,12 +408,12 @@ function tags.stop() end local t = stack[stacksize] if not t then - -- if trace_tags then + if trace_tags then report_tags("ignoring end tag, previous chain: %s",stacksize > 0 and concat(chain," ",1,stacksize) or "none") - -- end + end t = unsetvalue end - texattribute[a_tagged] = t + texsetattribute(a_tagged,t) return t end |