Skip to content

Commit c2d7723

Browse files
authored
Merge pull request #12356 from quarto-dev/typst/listing-highlight
typst - forward class and attributes on codeblock in listing
2 parents da02c68 + 2daa9f9 commit c2d7723

File tree

7 files changed

+56
-31
lines changed

7 files changed

+56
-31
lines changed

news/changelog-1.7.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ All changes included in 1.7:
5252
- ([#11860](https://github.com/quarto-dev/quarto-cli/issues/11860)): ES6 modules that import other local JS modules in documents with `embed-resources: true` are now correctly embedded.
5353
- ([#1325](https://github.com/quarto-dev/quarto-cli/issues/1325)): Dark Mode pages should not flash light on reload. (Nor should Light Mode pages flash dark.)
5454
- ([#12307](https://github.com/quarto-dev/quarto-cli/issues/12307)): Tabsets using `tabby.js` in non-boostrap html (`theme: pandoc`, `theme: none` or `minimal: true`) now correctly render reactive content when `server: shiny` is used.
55+
- ([#12356](https://github.com/quarto-dev/quarto-cli/issues/12356)): Remove duplicate id in HTML document when using `#lst-` prefix label for using Quarto crossref.
5556

5657
## `pdf` format
5758

@@ -73,6 +74,7 @@ All changes included in 1.7:
7374
- ([#11676](https://github.com/quarto-dev/quarto-cli/pull/11676)): Convert unitless image widths from pixels to inches for column layouts.
7475
- ([#11835](https://github.com/quarto-dev/quarto-cli/issues/11835)): Take markdown structure into account when detecting minimum heading level.
7576
- ([#11964](https://github.com/quarto-dev/quarto-cli/issues/11964)): Using panel layout without a crossref label now correctly do not add an empty `#block[]` that was leading to an unnecessary space in output.
77+
- ([#12354](https://github.com/quarto-dev/quarto-cli/issues/12354)): CodeBlock in Listing with `#lst-` prefix are now correctly highlighted.
7678

7779
## Interactive Shiny Document
7880

src/resources/filters/customnodes/floatreftarget.lua

Lines changed: 0 additions & 25 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

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

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ _quarto:
77
typst:
88
ensureTypstFileRegexMatches:
99
-
10-
- "#ref\\(<lst-customers>, supplement: \\[Listing\\]\\)"
11-
- "Customers Query"
10+
- '#figure\(\[\s+#set align\(left\)'
11+
- '```sql\s+SELECT \* FROM Customers\s+```'
12+
- '#ref\(<lst-customers>, supplement: \[Listing\]\)'
13+
- 'Customers Query'
1214
- []
1315
---
1416

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: Listings Test
3+
format: typst
4+
keep-typ: true
5+
_quarto:
6+
tests:
7+
typst:
8+
ensureTypstFileRegexMatches:
9+
-
10+
- '#figure\(\[\s+#set align\(left\)'
11+
- '```sql\s+SELECT \* FROM Customers\s+```'
12+
- '#ref\(<lst-customers>, supplement: \[Listing\]\)'
13+
- 'Customers Query'
14+
- []
15+
---
16+
17+
::: {#lst-customers}
18+
19+
```{.sql}
20+
SELECT * FROM Customers
21+
```
22+
Customers Query
23+
24+
:::
25+
26+
Then we query the customers database (@lst-customers).

0 commit comments

Comments
 (0)