Skip to content

Commit 60e508c

Browse files
committed
html,listings - avoid duplicate ids, keep classes on codeblocks
1 parent cc23659 commit 60e508c

File tree

4 files changed

+24
-36
lines changed

4 files changed

+24
-36
lines changed

src/resources/filters/customnodes/floatreftarget.lua

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -335,18 +335,6 @@ end, function(float)
335335
float.content.caption.long = float.caption_long
336336
float.content.attr = pandoc.Attr(float.identifier, float.classes or {}, float.attributes or {})
337337
return float.content
338-
elseif float_type == "lst" then
339-
local handle_code_block = function(codeblock)
340-
codeblock.attr = merge_attrs(codeblock.attr, pandoc.Attr("", float.classes or {}, float.attributes or {}))
341-
return codeblock
342-
end
343-
if float.content.t == "CodeBlock" then
344-
float.content = handle_code_block(float.content)
345-
else
346-
float.content = _quarto.ast.walk(float.content, {
347-
CodeBlock = handle_code_block
348-
})
349-
end
350338
end
351339

352340
local fig_scap = attribute(float, kFigScap, nil)
@@ -630,19 +618,6 @@ _quarto.ast.add_renderer("FloatRefTarget", function(_)
630618
return _quarto.format.isHtmlOutput()
631619
end, function(float)
632620
decorate_caption_with_crossref(float)
633-
634-
------------------------------------------------------------------------------------
635-
-- Special handling for listings
636-
local found_listing = get_node_from_float_and_type(float, "CodeBlock")
637-
if found_listing then
638-
found_listing.attr = merge_attrs(found_listing.attr, pandoc.Attr("", float.classes or {}, float.attributes or {}))
639-
-- FIXME this seems to be necessary for our postprocessor to kick in
640-
-- check this out later
641-
found_listing.identifier = float.identifier
642-
end
643-
644-
------------------------------------------------------------------------------------
645-
646621
return float_reftarget_render_html_figure(float)
647622
end)
648623

@@ -1017,13 +992,6 @@ end, function(float)
1017992
-- Listings shouldn't emit centered blocks.
1018993
-- We don't know how to disable that right now using #show rules for #figures in template.
1019994
content:insert(1, pandoc.RawBlock("typst", "#set align(left)"))
1020-
1021-
-- Classes and attributes for the CodeBlocks needs to be set from the parsed floats to the CodeBlock
1022-
local found_listing = get_node_from_float_and_type(float, "CodeBlock")
1023-
if found_listing then
1024-
found_listing.attr = merge_attrs(found_listing.attr, pandoc.Attr("", float.classes or {}, float.attributes or {}))
1025-
end
1026-
1027995
end
1028996

1029997
if float.has_subfloats then

src/resources/filters/quarto-pre/parsefiguredivs.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,8 @@ function parse_floatreftargets()
656656
end
657657
code.attr.attributes['lst-cap'] = nil
658658

659-
local attr = code.attr
660-
-- code.attr = pandoc.Attr("", {}, {})
659+
local attr = pandoc.Attr(code.identifier, code.attr.classes, code.attr.attributes)
660+
code.attr = pandoc.Attr("", code.classes, code.attr.attributes)
661661
return construct({
662662
attr = attr,
663663
type = "Listing",
@@ -686,7 +686,7 @@ function parse_floatreftargets()
686686
end
687687

688688
local attr = code.attr
689-
code.attr = pandoc.Attr("", {}, {})
689+
code.attr = pandoc.Attr("", code.classes, code.attr.attributes)
690690
return construct({
691691
attr = attr,
692692
type = "Listing",
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
format:
3+
typst: default
4+
html: default
5+
_quarto:
6+
tests:
7+
html:
8+
ensureHtmlElements:
9+
- ['div#lst-1.listing', 'div#lst-2.listing']
10+
- ['div#lst-1.sourceCode', 'div#lst-2.sourceCode']
11+
---
12+
13+
```{#lst-1 .r filename="asdfoasdf.R" lst-cap="A listing." my-key="value"}
14+
print("Hello, world!")
15+
```
16+
17+
18+
```{#lst-2 .r lst-cap="A listing." my-key="value"}
19+
print("Hello, world!")
20+
```

tests/docs/smoke-all/crossrefs/float/latex/latex-listings-1.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ _quarto:
55
tests:
66
latex:
77
ensureFileRegexMatches:
8-
- []
8+
- [Shaded]
99
- []
1010
---
1111

0 commit comments

Comments
 (0)