diff --git a/news/changelog-1.6.md b/news/changelog-1.6.md index 031785e216..c7e8ef1743 100644 --- a/news/changelog-1.6.md +++ b/news/changelog-1.6.md @@ -87,3 +87,4 @@ All changes included in 1.6: - ([#10552](https://github.com/quarto-dev/quarto-cli/issues/10552)): Add `contents` shortcode. - ([#10581](https://github.com/quarto-dev/quarto-cli/issues/10581)): Add `.landscape` div processing to `typst`, `docx` and `pdf` formats to support pages in landscape orientation. - ([#10591](https://github.com/quarto-dev/quarto-cli/issues/10591)): Make fenced div syntax slightly more robust by removing spaces around the `=` sign ahead of Pandoc's reader. +- ([#10821](https://github.com/quarto-dev/quarto-cli/issues/10821)): Be more conservative in stripping `echo: fenced` from fenced output. diff --git a/src/core/jupyter/jupyter.ts b/src/core/jupyter/jupyter.ts index ee86aaa445..f246c0a4e3 100644 --- a/src/core/jupyter/jupyter.ts +++ b/src/core/jupyter/jupyter.ts @@ -1464,7 +1464,7 @@ async function mdFromCodeCell( let source = ld.cloneDeep(cell.source); if (fenced) { const optionsSource = cell.optionsSource.filter((line) => - line.search(/echo:\s+fenced/) === -1 + line.search(/\|\s+echo:\s+fenced\s*$/) === -1 ); if (optionsSource.length > 0) { source = trimEmptyLines(source, "trailing"); diff --git a/src/resources/rmd/hooks.R b/src/resources/rmd/hooks.R index 6982d47280..530cbd11b3 100644 --- a/src/resources/rmd/hooks.R +++ b/src/resources/rmd/hooks.R @@ -462,7 +462,7 @@ knitr_hooks <- function(format, resourceDir, handledLanguages) { lang <- NULL yamlCode <- lastYamlCode if (!is.null(yamlCode)) { - yamlCode <- Filter(function(line) !grepl("echo:\\s+fenced", line), yamlCode) + yamlCode <- Filter(function(line) !grepl("\\|\\s+echo:\\s+fenced\\s*$", line), yamlCode) yamlCode <- paste(yamlCode, collapse = "\n") if (!nzchar(yamlCode)) { x <- trimws(x, "left") diff --git a/tests/docs/smoke-all/2024/09/24/issue-10821-b.qmd b/tests/docs/smoke-all/2024/09/24/issue-10821-b.qmd new file mode 100644 index 0000000000..434e98a14c --- /dev/null +++ b/tests/docs/smoke-all/2024/09/24/issue-10821-b.qmd @@ -0,0 +1,19 @@ +--- +title: issue-10821 +format: html +_quarto: + tests: + html: + ensureFileRegexMatches: + - ['#\| fig-cap: ''This figure will have ''''echo: fenced'''' in its caption.'''] + - [] + # - ['fig-cap'] +--- + +```{python} +#| echo: fenced +#| label: fig-1 +#| fig-cap: "This figure will have 'echo: fenced' in its caption." +import matplotlib.pyplot as plt +plt.plot([1,2,3]) +``` diff --git a/tests/docs/smoke-all/2024/09/24/issue-10821.qmd b/tests/docs/smoke-all/2024/09/24/issue-10821.qmd new file mode 100644 index 0000000000..5fb8830a28 --- /dev/null +++ b/tests/docs/smoke-all/2024/09/24/issue-10821.qmd @@ -0,0 +1,18 @@ +--- +title: issue-10821 +format: html +_quarto: + tests: + html: + ensureFileRegexMatches: + - ['#\| fig-cap: "This figure will have ''echo: fenced'' in its caption."'] + - [] +--- + +```{r} +#| echo: fenced +#| whatever: "echo: fenced" +#| fig-cap: "This figure will have 'echo: fenced' in its caption." +#| label: fig-1 +plot(1:100) +```