tomduck / pandoc-fignos

A pandoc filter for numbering figures and figure references.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why is id on img instead of containing figure

vincerubinetti opened this issue · comments

The output of fignos seems to put the id/anchor to the image in the <img> tag itself instead of in the containing <figure> element. It might seem sensible to put it on the <img>, however there may be cases where it causes inconvenience.

For example, I'm working on a project called manubot where we take the html output from pandoc, using tablenos and fignos, and insert javascript "plugins" to add certain handy functionality to the manuscript. One of the plugins briefly highlights/glows an element when a user clicks a relative (eg href="#introduction") link to it. In the case of a figure, I want to highlight both the <img> and its associated <figcaption> - in other words, everything contained in the <figure>. It is the same issue with #11 on tablenos.

It's a minor grievance, but I think it's most sensible to put the id on the thing that is actually being referenced, which is the whole figure object. Same thing with the tables, having the id right on the table.

Thanks for your question, and sorry for the delay.

The choice of where to put the id (either in the <figure> or <img> tag) is actually made by pandoc. You can see this by disabling pandoc-fignos and looking at the output.

I don't see a way for pandoc-fignos (as a filter) to overcome this. The fundamental problem is that while pandoc's abstract syntax has an Image type, it does not have a Figure type. So an id is necessarily associated with an Image at the filter stage . The conversion to an html <figure> occurs at pandoc's html writer stage; i.e., after filters are applied.

Maybe file an issue with pandoc?

I see that you have submitted an issue to pandoc-tablenos about this, and will address tables separately there.

Hi Tom, thanks for the response. No need to reply to the tables one too. You can just reference this response.

I think in the time since I asked this question, I noticed that it was actually a problem with pandoc. As I recall, and as you mentioned above, a limitation of its internal abstract syntax tree.

Feel free to close the issue.

Yes, that is exactly what I see: a limitation of pandoc's internal abstract syntax tree.

I will have a separate look at the tables issue. There is a Table type in pandoc's AST, so it may be possible to move the id there. I'm not sure, but I will check.

Cheers,
Tom