Skip to content

Commit 9bd7c1f

Browse files
authored
Bugfix/issue 4034 (#4116)
* cellcleanup filter * add cellcleanup to chain * add filter to cleanup empty cell. Closes #4034 * changelog
1 parent 0e9addd commit 9bd7c1f

File tree

6 files changed

+42
-1
lines changed

6 files changed

+42
-1
lines changed

news/changelog-1.3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
- Support parsing markdown in table captions in LaTeX and HTML tables ([#2573](https://github.com/quarto-dev/quarto-cli/issues/2573)).
119119
- Improve parsing of include shortcodes ([#3159](https://github.com/quarto-dev/quarto-cli/issues/3159)).
120120
- Add support for Youtube privacy-enhanced urls in `video` shortcodes ([#4060](https://github.com/quarto-dev/quarto-cli/issues/4060)).
121+
- Don't emit empty cells ([#4034](https://github.com/quarto-dev/quarto-cli/issues/4034)).
121122

122123
## Pandoc filter changes
123124

src/command/render/pandoc.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,11 @@ export async function runPandoc(
970970
delete pandocPassedMetadata.format;
971971
delete pandocPassedMetadata.project;
972972
delete pandocPassedMetadata.website;
973+
if (pandocPassedMetadata._quarto) {
974+
// these shouldn't be visible because they are emitted on markdown output
975+
// and it breaks ensureFileRegexMatches
976+
delete pandocPassedMetadata._quarto.tests;
977+
}
973978

974979
Deno.writeTextFileSync(
975980
metadataTemp,

src/resources/filters/main.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import("./quarto-post/responsive.lua")
7373
import("./quarto-post/reveal.lua")
7474
import("./quarto-post/tikz.lua")
7575
import("./quarto-post/pdf-images.lua")
76+
import("./quarto-post/cellcleanup.lua")
7677

7778
import("./quarto-finalize/dependencies.lua")
7879
import("./quarto-finalize/book-cleanup.lua")
@@ -219,6 +220,7 @@ local quartoPre = {
219220

220221
local quartoPost = {
221222
-- quarto-post
223+
{ name = "post-cell-cleanup", filter = cell_cleanup() },
222224
{ name = "post-cites", filter = indexCites() },
223225
{ name = "post-foldCode", filter = foldCode() },
224226
{ name = "post-figureCleanupCombined", filter = combineFilters({
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- cellcleanup.lua
2+
-- Copyright (C) 2020-2023 Posit Software, PBC
3+
4+
function cell_cleanup()
5+
return {
6+
Div = function(div)
7+
if (#div.classes == 1 and
8+
div.classes[1] == "cell" and
9+
#div.content == 0) then
10+
return {}
11+
end
12+
end
13+
}
14+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: "4034"
3+
format: markdown
4+
_quarto:
5+
tests:
6+
markdown:
7+
ensureFileRegexMatches:
8+
- []
9+
- [".cell"]
10+
---
11+
12+
```{r}
13+
#| echo: false
14+
#| warning: false
15+
#| message: false
16+
#| output: false
17+
z=3+4
18+
z
19+
```

tests/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function outputForInput(input: string, to: string) {
2929
if (baseFormat === "revealjs") {
3030
outputExt = "html";
3131
}
32-
if (baseFormat === "commonmark" || baseFormat === "gfm") {
32+
if (["commonmark", "gfm", "markdown"].some((f) => f === baseFormat)) {
3333
outputExt = "md";
3434
}
3535
if (baseFormat === "csljson") {

0 commit comments

Comments
 (0)