I’m rewriting my syntax-tree package, with syntax that looks like this (whitespace insensitive):
#tree[
[*Head*
[Child
[Leaf]
]
[_Italicized Child_]
]
]
But for each node, I’d like the user to be able to provide custom data and styling. Currently I have a very hacky aproach that looks like this.
#tree[
[*Head* %(align: left)%
[Child
[Leaf %(name: "leaf-node")%]
]
[_Italicized Child_]
]
]
This is ugly to parse (%
is an arbitrary delimiter for now, and that part can be made nicer). But more importantly it uses eval
to get at the data. I’d like to avoid that if possible, since it’s a last resort and relies on content-to-string parsing which might be brittle. I considered something like #node(name: "leaf-node")[Leaf]
, but at the end of the day that function needs to return content, and I could not find a way to embed data into content.
Is there a way to embed data into content, or a different way to go about this? Crucially without compromising the ability to use the simple [node]
syntax when styling is not needed.