@@ -12,33 +12,11 @@ local classes_to_not_merge = pandoc.List({
12
12
" border"
13
13
})
14
14
15
- function handle_subfloatreftargets ()
16
- -- #7045: pull fig-pos and fig-env attributes from subfloat to parent
17
- return {
18
- FloatRefTarget = function (float )
19
- local pulled_attrs = {}
20
- local attrs_to_pull = {
21
- " fig-pos" ,
22
- " fig-env" ,
23
- }
24
- local result = _quarto .ast .walk (float , {
25
- FloatRefTarget = function (subfloat )
26
- for _ , attr in ipairs (attrs_to_pull ) do
27
- if subfloat .attributes [attr ] then
28
- pulled_attrs [attr ] = subfloat .attributes [attr ]
29
- subfloat .attributes [attr ] = nil
30
- end
31
- end
32
- return subfloat
33
- end ,
34
- }) or pandoc .Div ({}) -- won't happen but the lua analyzer doesn't know that
35
- for k , v in pairs (pulled_attrs ) do
36
- float .attributes [k ] = v
37
- end
38
- return float
39
- end
40
- }
41
- end
15
+ -- function handle_subfloatreftargets()
16
+ -- return {
17
+ -- FloatRefTarget =
18
+ -- }
19
+ -- end
42
20
43
21
local function process_div_caption_classes (div )
44
22
-- knitr forwards "cap-location: top" as `.caption-top`...
@@ -136,6 +114,11 @@ local function kable_raw_latex_fixups(content, identifier)
136
114
137
115
-- we found a table, a label, and a caption. This is a FloatRefTarget.
138
116
matches = matches + 1
117
+
118
+ -- other FloatRefTarget constructions below go through
119
+ -- a recursion step to identify subfloats, but we don't have
120
+ -- to do that here, since we know that the content of this FloatRefTarget
121
+ -- is a single table.
139
122
return quarto .FloatRefTarget ({
140
123
identifier = label_identifier ,
141
124
type = " Table" ,
165
148
166
149
function parse_floatreftargets ()
167
150
151
+ local filter
152
+
153
+ local function construct (tbl )
154
+ local new_content = _quarto .ast .walk (tbl .content , filter )
155
+
156
+ -- #7045: pull fig-pos and fig-env attributes from subfloat to parent
157
+ local pulled_attrs = {}
158
+ local attrs_to_pull = {
159
+ " fig-pos" ,
160
+ " fig-env" ,
161
+ }
162
+ new_content = _quarto .ast .walk (new_content , {
163
+ FloatRefTarget = function (subfloat )
164
+ for _ , attr in ipairs (attrs_to_pull ) do
165
+ if subfloat .attributes [attr ] then
166
+ pulled_attrs [attr ] = subfloat .attributes [attr ]
167
+ subfloat .attributes [attr ] = nil
168
+ end
169
+ end
170
+ return subfloat
171
+ end
172
+ })
173
+ local inner_tbl = {}
174
+ for k , v in pairs (tbl ) do
175
+ inner_tbl [k ] = v
176
+ end
177
+ for k , v in pairs (pulled_attrs ) do
178
+ inner_tbl .attr .attributes [k ] = v
179
+ end
180
+ inner_tbl .content = new_content
181
+ return quarto .FloatRefTarget (inner_tbl )
182
+ end
183
+
168
184
local function handle_subcells_as_subfloats (params )
169
185
local identifier = params .identifier
170
186
local div = params .div
@@ -182,10 +198,10 @@ function parse_floatreftargets()
182
198
return nil
183
199
end
184
200
subcap_index = subcap_index + 1
185
- local subfloat = quarto . FloatRefTarget ({
201
+ local subfloat = construct ({
186
202
attr = pandoc .Attr (identifier .. " -" .. tostring (subcap_index ), {}, {}),
187
203
type = category .name ,
188
- content = {subdiv },
204
+ content = pandoc . Blocks {subdiv },
189
205
caption_long = {pandoc .Plain (string_to_quarto_ast_inlines (subcaps [subcap_index ]))},
190
206
})
191
207
subcells :insert (subfloat )
@@ -274,6 +290,7 @@ function parse_floatreftargets()
274
290
275
291
local identifier = div .identifier
276
292
local attr = pandoc .Attr (identifier , div .classes , div .attributes )
293
+ assert (content )
277
294
if (# content == 1 and content [1 ].t == " Para" and
278
295
content [1 ].content [1 ].t == " Image" ) then
279
296
-- if the div contains a single image, then we simply use the image as
@@ -367,7 +384,7 @@ function parse_floatreftargets()
367
384
return_cell .content = coalesce_code_blocks (return_cell .content )
368
385
return_cell .classes = div .classes
369
386
return_cell .attributes = div .attributes
370
- local reftarget = quarto . FloatRefTarget ({
387
+ local reftarget = construct ({
371
388
attr = attr ,
372
389
type = category .name ,
373
390
content = final_content .content ,
@@ -416,15 +433,15 @@ function parse_floatreftargets()
416
433
}
417
434
end
418
435
419
- return quarto . FloatRefTarget ({
436
+ return construct ({
420
437
attr = attr ,
421
438
type = category .name ,
422
439
content = content ,
423
440
caption_long = {pandoc .Plain (caption .content )},
424
441
}), false
425
442
end
426
443
427
- return {
444
+ filter = {
428
445
traverse = " topdown" ,
429
446
Figure = function (fig )
430
447
local key_prefix = refType (fig .identifier )
@@ -463,7 +480,7 @@ function parse_floatreftargets()
463
480
end
464
481
}) or fig .content [1 ] -- this shouldn't be needed but the lua analyzer doesn't know it
465
482
466
- return quarto . FloatRefTarget ({
483
+ return construct ({
467
484
attr = fig_attr ,
468
485
type = category .name ,
469
486
content = new_content .content ,
@@ -502,7 +519,7 @@ function parse_floatreftargets()
502
519
503
520
local combined = merge_attrs (el .attr , attr )
504
521
505
- return quarto . FloatRefTarget ({
522
+ return construct ({
506
523
identifier = label ,
507
524
classes = combined .classes ,
508
525
attributes = as_plain_table (combined .attributes ),
@@ -586,7 +603,7 @@ function parse_floatreftargets()
586
603
-- warn("Figure with invalid crossref category: " .. identifier .. "\nWon't be able to cross-reference this figure.")
587
604
return nil
588
605
end
589
- return quarto . FloatRefTarget ({
606
+ return construct ({
590
607
identifier = identifier ,
591
608
classes = {},
592
609
attributes = as_plain_table (img .attributes ),
@@ -617,7 +634,7 @@ function parse_floatreftargets()
617
634
return
618
635
end
619
636
local combined = merge_attrs (img .attr , link .attr )
620
- return quarto . FloatRefTarget ({
637
+ return construct ({
621
638
identifier = identifier ,
622
639
classes = combined .classes ,
623
640
attributes = as_plain_table (combined .attributes ),
@@ -642,10 +659,10 @@ function parse_floatreftargets()
642
659
643
660
local attr = code .attr
644
661
-- code.attr = pandoc.Attr("", {}, {})
645
- return quarto . FloatRefTarget ({
662
+ return construct ({
646
663
attr = attr ,
647
664
type = " Listing" ,
648
- content = { decorated_code .__quarto_custom_node }, -- this custom AST impedance mismatch here is unfortunate
665
+ content = pandoc . Blocks { decorated_code .__quarto_custom_node }, -- this custom AST impedance mismatch here is unfortunate
649
666
caption_long = caption ,
650
667
}), false
651
668
end ,
@@ -671,10 +688,10 @@ function parse_floatreftargets()
671
688
672
689
local attr = code .attr
673
690
code .attr = pandoc .Attr (" " , {}, {})
674
- return quarto . FloatRefTarget ({
691
+ return construct ({
675
692
attr = attr ,
676
693
type = " Listing" ,
677
- content = { content },
694
+ content = pandoc . Blocks ( { content }) ,
678
695
caption_long = caption_inlines ,
679
696
}), false
680
697
end ,
@@ -749,15 +766,17 @@ function parse_floatreftargets()
749
766
raw .text = matched [2 ]
750
767
end
751
768
752
- return quarto . FloatRefTarget ({
769
+ return construct ({
753
770
attr = pandoc .Attr (identifier , {}, {}),
754
771
type = " Table" ,
755
- content = { raw },
772
+ content = pandoc . Blocks ( { raw }) ,
756
773
caption_long = quarto .utils .as_blocks (caption )
757
774
}), false
758
775
end
759
776
760
777
}
778
+
779
+ return filter
761
780
end
762
781
763
782
function forward_cell_subcaps ()
0 commit comments