Skip to content

Commit 6ec1848

Browse files
authored
Merge pull request #5116 from quarto-dev/bugfix/5112
markdown formats: handle code blocks with filenames as in v1.2
2 parents 71696a6 + 3290a2c commit 6ec1848

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/resources/filters/customnodes/decoratedcodeblock.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,22 @@ _quarto.ast.add_handler({
103103
return listingDiv
104104
end
105105
return el
106+
elseif _quarto.format.isMarkdownOutput() then
107+
-- see https://github.com/quarto-dev/quarto-cli/issues/5112
108+
--
109+
-- This is a narrow fix for the 1.3 regression.
110+
-- We still don't support listings output in markdown since that wasn't supported in 1.2 either.
111+
-- But that'll be done in 1.4 with crossrefs overhaul.
112+
113+
if node.filename then
114+
-- if we have a filename, add it as a header
115+
return pandoc.Div(
116+
{ pandoc.Plain{pandoc.Strong{pandoc.Str(node.filename)}}, el },
117+
pandoc.Attr("", {"code-with-filename"})
118+
)
119+
else
120+
return el
121+
end
106122
else
107123
-- return the code block unadorned
108124
-- this probably could be improved
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: foo
3+
format: commonmark
4+
keep-md: true
5+
_quarto:
6+
tests:
7+
commonmark:
8+
ensureFileRegexMatches:
9+
- ["this-is-the-filename.py"]
10+
- []
11+
---
12+
13+
```{.python filename="this-is-the-filename.py"}
14+
import matplotlib.pyplot as plt
15+
plt.plot([1,23,2,4])
16+
plt.show()
17+
```

0 commit comments

Comments
 (0)