Cannot add css classes to implicit_figures
nomeata opened this issue · 7 comments
When creating an implicit_figure
, e.g.
![Function composition](/images/function-machine.png){ width=200 .floatright .noprint }
then the style information is attached to the <img>
tag, not the <div class="figure">
tag:
<div class="figure">
<img src="../images/function-machine.png" alt="Function composition" class="floatright noprint" width="200">
<p class="caption">Function composition</p>
</div>
This prevents different styling of figures via CSS, e.g.
@media print {
.noprint {
display: none;
}
}
(This would leave the caption in the document.)
I don’t have a good idea about a backwards-compatible syntax that would allow the user to assign style data to the outermost <div>
, though.
could you use the +
css selector, which selects elements found just after other elements to display:none the caption?:
@media print{
.noprint, .noprint+.caption {
display:none;
}
}
This would not hide the div .figure
, though, would it?
No, but if everything in the div is display:none then it might note show up. Depends on your layout etc.
Faced the same issue with implicit figures in html5:
$ cat test.md
![caption](picture.jpg "title"){#id .class}
$ pandoc -t html5 ./test.md
<figure>
<img src="picture.jpg" title="title" id="id" class="class"
alt="caption" />
<figcaption aria-hidden="true">caption</figcaption>
</figure>
Everything is correct, but id
and class
attributes will be much more useful if they are attributes of figure
element, e. g.:
$ pandoc -t html5 ./test.md
<figure id="id" class="class">
<img src="picture.jpg" title="title" alt="caption" />
<figcaption aria-hidden="true">caption</figcaption>
</figure>
In such a case, custom style sheet will be trivial and allow to freely stylize everything: figure
, img
, and figcaption
. Having id
and class
attributes at img
element makes figure
stylizing non-trivial.
With pandoc 3.1.5, the id attribute, at least, does get put on figure (but not class).
With pandoc 3.1.5, the id attribute, at least, does get put on figure (but not class).
Thanks for the info, it's good to know. I still use pandoc 2.19.2 in Fedora 38, though.
What about class
? Is it not yet implemented, or do you have any principal objections from moving it to figure
?
BTW: If id
and class
attributes are put on img
, styling figure
element is trivial with :has
CSS selector. Unfortunately, this is Selectors Level 4 Draft. Only very recent browsers support it.
I'm very tempted to move class
, yes. But there's the usual fear of unexpected consequences and breaking things.