Pass the metas hash table to tag functions
Closedopened 5 years ago by jlorieau · 4 comments
Reference in New Issue
There is no content yet.
Delete Branch '%!s(<nil>)'
Deleting a branch is permanent. It CANNOT be undone. Continue?
It would be useful for tag functions to have access to the
metashash table to render tags. An example of such a use would be to calculate the pagenode's position for chapter and section rendering.
Matthew provided a helpful macro that can be used to wrap tag functions for this purpose. However, I would like to suggest an implementation of a tag function, like
define-tag-functionthat optionally receives the
metashash. I'm not sure whether such a change could be done in a backwards-compatible way, but creating a new function (e.g.
define-tag-metas-function), or enabling the passed argument with a setup flag, could be possible alternative solutions.
There’s more than one way to do this, so I think it would be a worthwhile mini-tutorial for the docs.
For now, I’m not enthusiastic about upgrading
metasas an argument. (Or creating another function in
pollen/tagto do it.)
The problem is that this blends the macro and runtime worlds in an awkward way. The technique I showed you before is a macro that depends on grabbing the
metasat the caller site. But it assumes that
metasis defined there. If it were used in a module without
metasdefined, it would fail.
True, we could adjust the macro to behave differently based on whether
metasis defined. But that just shifts the problem. The body of the tag function will be written to rely on
metas. So the operation would still fail.
I just pushed an update that adds a
pollen/core. I’m not ready to document this as part of the public interface. But try it, see if it suits your needs, and report back.
Instead of having to pass
metasto a tag function explicitly, the
current-metasparameter contains the metas of the source file currently being rendered (or if there is no file, then
#f). So you can do things like this:
you must import
you should always assume
#f(if the function isn’t being called from inside a Pollen source) and program accordingly
That's great and a perfect solution. Thanks!
current-metasworking as advertised? If so I will add it to the docs.