Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lua: use as_blocks(el.code_block) consistently in DecoratedCodeBlock #7409

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/resources/filters/customnodes/decoratedcodeblock.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@ _quarto.ast.add_renderer("DecoratedCodeBlock",
-- But that'll be done in 1.4 with crossrefs overhaul.

if node.filename then
-- a user filter could have replaced
-- a single code block in a decorated code block with a list of elements,
-- so we need to handle that.
local blocks = quarto.utils.as_blocks(el) or pandoc.Blocks({})
-- if we have a filename, add it as a header
blocks:insert(1, pandoc.Plain{pandoc.Strong{pandoc.Str(node.filename)}})
return pandoc.Div(
{ pandoc.Plain{pandoc.Strong{pandoc.Str(node.filename)}}, el },
blocks,
pandoc.Attr("", {"code-with-filename"})
)
else
Expand All @@ -74,7 +79,6 @@ _quarto.ast.add_renderer("DecoratedCodeBlock",
local el = node.code_block
-- add listing class to the code block
el.attr.classes:insert("listing")

-- if we are use the listings package we don't need to do anything
-- further, otherwise generate the listing div and return it
if not param("listings", false) then
Expand Down Expand Up @@ -112,7 +116,10 @@ _quarto.ast.add_renderer("DecoratedCodeBlock",
listingDiv.content:insert(listingCaption)
end

listingDiv.content:insert(el)
-- a user filter could have replaced
-- a single code block in a decorated code block with a list of elements,
-- so we need to handle that.
listingDiv.content:extend(quarto.utils.as_blocks(el) or {})
listingDiv.content:insert(pandoc.RawBlock("latex", "\\end{codelisting}"))
return listingDiv
end
Expand Down Expand Up @@ -150,7 +157,7 @@ _quarto.ast.add_renderer("DecoratedCodeBlock",
if filenameEl ~= nil then
blocks:insert(filenameEl)
end
blocks:insert(el)
blocks:extend(quarto.utils.as_blocks(el) or {})

return pandoc.Div(blocks, pandoc.Attr("", classes))
end)
12 changes: 12 additions & 0 deletions tests/docs/smoke-all/2023/10/29/6985-b.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
code-fold: true
---

```{r}
#| file: script.R
#| filename: script.R
```

```{js}
#| file: script.js
```
1 change: 1 addition & 0 deletions tests/docs/smoke-all/2023/10/29/script.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 + 1
1 change: 1 addition & 0 deletions tests/docs/smoke-all/2023/10/29/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Hello World!");