Hi Linas, On Thu, 2024-05-30 at 10:39 +0300, Linas Stonys wrote:
For example if there would be few primitives which could add an attribute or/and properties to next (yet to be created) non discardable item like \luaAddFeaturesNodeNext {{attr=1, properties={"<section>}}} \section{foo} \luaAddFeaturesNodePrev{{attr=1, properties={"</section>}}}
The primitive \attribute is pretty close. You just need a little bit of Lua to make it behave exactly like you want: \attributedef\myattribute=1234 % or use \newattribute \newcount\mycount \def\addattribute#1{% \advance\mycount by 1 \global\myattribute=\mycount \global\expandafter\def\csname myattribute\the\mycount\endcsname{#1}% } \catcode`\~=12 \directlua{% attribute_number = token.create("myattribute").index local function recurse(head) for n in node.traverse(head) do if n.list then recurse(n.list) end local attr = node.get_attribute(n, attribute_number) local value if attr and n.id ~= node.id("glue") and n.id ~= node.id("local_par") then value = token.get_macro("myattribute" .. attr) token.set_macro("myattribute" .. attr, nil, "global") end if value and value ~= "" then local colour = node.new("whatsit", "pdf_literal") node.unset_attribute(colour, attribute_number) colour.mode = 2 colour.data = value node.insert_before(head, n, colour) end end return head end callback.register("pre_output_filter", recurse) } \addattribute{1 0 0 rg} abc \addattribute{0 1 0 rg} def \addattribute{0 0 1 rg} ghi \bye -- Max