|
3 | 3 |
|
4 | 4 | local patterns = require("modules/patterns") |
5 | 5 |
|
| 6 | +local attributes_to_not_merge = pandoc.List({ |
| 7 | + "width", "height" |
| 8 | +}) |
| 9 | + |
| 10 | +-- Narrow fix for #8000 |
| 11 | +local classes_to_not_merge = pandoc.List({ |
| 12 | + "border" |
| 13 | +}) |
| 14 | + |
6 | 15 | function handle_subfloatreftargets() |
7 | 16 | -- #7045: pull fig-pos and fig-env attributes from subfloat to parent |
8 | 17 | return { |
@@ -238,8 +247,22 @@ function parse_floatreftargets() |
238 | 247 | -- if the div contains a single image, then we simply use the image as |
239 | 248 | -- the content |
240 | 249 | content = content[1].content[1] |
241 | | - attr = merge_attrs(attr, content.attr) |
242 | | - attr.identifier = div.identifier -- never override the identifier |
| 250 | + |
| 251 | + -- don't merge classes because they often have CSS consequences |
| 252 | + -- but merge attributes because they're needed to correctly resolve |
| 253 | + -- behavior such as fig-pos="h", etc |
| 254 | + -- See #8000. |
| 255 | + -- We also exclude attributes we know to not be relevant to the div |
| 256 | + for k, v in pairs(content.attr.attributes) do |
| 257 | + if not attributes_to_not_merge:includes(k) then |
| 258 | + attr.attributes[k] = v |
| 259 | + end |
| 260 | + end |
| 261 | + for _, v in ipairs(content.attr.classes) do |
| 262 | + if not classes_to_not_merge:includes(v) then |
| 263 | + attr.classes:insert(v) |
| 264 | + end |
| 265 | + end |
243 | 266 | end |
244 | 267 |
|
245 | 268 | local skip_outer_reftarget = false |
@@ -353,9 +376,20 @@ function parse_floatreftargets() |
353 | 376 | local fig_attr = fig.attr |
354 | 377 | local new_content = _quarto.ast.walk(fig.content[1], { |
355 | 378 | Image = function(image) |
356 | | - -- forward attributes and classes from the image to the float |
357 | | - fig_attr = merge_attrs(fig_attr, image.attr) |
358 | | - -- strip redundant image caption |
| 379 | + -- don't merge classes because they often have CSS consequences |
| 380 | + -- but merge attributes because they're needed to correctly resolve |
| 381 | + -- behavior such as fig-pos="h", etc |
| 382 | + -- See #8000. |
| 383 | + for k, v in pairs(image.attributes) do |
| 384 | + if not attributes_to_not_merge:includes(k) then |
| 385 | + fig_attr.attributes[k] = v |
| 386 | + end |
| 387 | + end |
| 388 | + for _, v in ipairs(image.classes) do |
| 389 | + if not classes_to_not_merge:includes(v) then |
| 390 | + fig_attr.classes:insert(v) |
| 391 | + end |
| 392 | + end |
359 | 393 | image.caption = {} |
360 | 394 | return image |
361 | 395 | end |
@@ -485,7 +519,7 @@ function parse_floatreftargets() |
485 | 519 | end |
486 | 520 | return quarto.FloatRefTarget({ |
487 | 521 | identifier = identifier, |
488 | | - classes = img.classes, |
| 522 | + classes = {}, |
489 | 523 | attributes = as_plain_table(img.attributes), |
490 | 524 | type = category.name, |
491 | 525 | content = img, |
|
0 commit comments