diff --git a/news/changelog-1.7.md b/news/changelog-1.7.md index daec9d8d52c..831514bbdcc 100644 --- a/news/changelog-1.7.md +++ b/news/changelog-1.7.md @@ -24,4 +24,5 @@ All changes included in 1.7: ## Other Fixes and Improvements +- ([#11441](https://github.com/quarto-dev/quarto-cli/issues/11441)): Don't add newlines around shortcodes during processing. - ([#11643](https://github.com/quarto-dev/quarto-cli/issues/11643)): Improve highlighting of nested code block inside markdown code block, i.e. using ` ```{{python}} ` or ` ```python ` inside ` ````markdown` fenced code block. diff --git a/src/core/handlers/base.ts b/src/core/handlers/base.ts index 9cbb1593e08..4792e177c9c 100644 --- a/src/core/handlers/base.ts +++ b/src/core/handlers/base.ts @@ -405,9 +405,7 @@ export async function expandIncludes( const newCells: MappedString[] = []; for (let i = 0; i < mdCells.length; ++i) { const cell = mdCells[i]; - newCells.push( - i === 0 ? cell.sourceVerbatim : mappedConcat(["\n", cell.sourceVerbatim]), - ); + newCells.push(cell.sourceVerbatim); } await processMarkdownIncludes(newCells, options, filename); @@ -437,9 +435,7 @@ export async function handleLanguageCells( for (let i = 0; i < mdCells.length; ++i) { const cell = mdCells[i]; - newCells.push( - i === 0 ? cell.sourceVerbatim : mappedConcat(["\n", cell.sourceVerbatim]), - ); + newCells.push(cell.sourceVerbatim); if ( cell.cell_type === "raw" || cell.cell_type === "markdown" @@ -483,7 +479,6 @@ export async function handleLanguageCells( (innerLanguageHandler.stage !== "any" && innerLanguageHandler.stage !== options.stage) ) { // we're in the wrong stage, so we don't actually do anything - newCells[cell.index] = mappedConcat([newCells[cell.index], "\n"]); continue; } if ( @@ -492,7 +487,6 @@ export async function handleLanguageCells( ) { // if no handler is present (or a directive was included for something // that responds to cells instead), we're a no-op - newCells[cell.index] = mappedConcat([newCells[cell.index], "\n"]); continue; } if (innerLanguageHandler.directive === undefined) { diff --git a/src/core/lib/break-quarto-md.ts b/src/core/lib/break-quarto-md.ts index fdf46f8f843..0f517ad675b 100644 --- a/src/core/lib/break-quarto-md.ts +++ b/src/core/lib/break-quarto-md.ts @@ -76,7 +76,6 @@ export async function breakQuartoMd( mappedChunks, fileName, ); - const makeCellType = () => { if (cell_type === "code") { return { language }; @@ -148,13 +147,7 @@ export async function breakQuartoMd( // directives only carry tag source in sourceVerbatim, analogously to code cell.source = mappedString(src, mappedChunks.slice(1, -1), fileName); } - // if the source is empty then don't add it - if ( - mdTrimEmptyLines(lines(cell.sourceVerbatim.value)).length > 0 || - cell.options !== undefined - ) { - nb.cells.push(cell); - } + nb.cells.push(cell); lineBuffer.splice(0, lineBuffer.length); } @@ -254,27 +247,3 @@ export async function breakQuartoMd( return nb; } - -function mdTrimEmptyLines(lines: string[]) { - // trim leading lines - const firstNonEmpty = lines.findIndex((line) => line.trim().length > 0); - if (firstNonEmpty === -1) { - return []; - } - lines = lines.slice(firstNonEmpty); - - // trim trailing lines - let lastNonEmpty = -1; - for (let i = lines.length - 1; i >= 0; i--) { - if (lines[i].trim().length > 0) { - lastNonEmpty = i; - break; - } - } - - if (lastNonEmpty > -1) { - lines = lines.slice(0, lastNonEmpty + 1); - } - - return lines; -} diff --git a/src/resources/pandoc/datadir/readqmd.lua b/src/resources/pandoc/datadir/readqmd.lua index 2e75fc90b88..0026783dddb 100644 --- a/src/resources/pandoc/datadir/readqmd.lua +++ b/src/resources/pandoc/datadir/readqmd.lua @@ -126,6 +126,7 @@ local function urldecode(url) end local function readqmd(txt, opts) + local tags txt = md_fenced_div.attempt_to_fix_fenced_div(txt) txt, tags = escape_invalid_tags(txt) txt = md_shortcode.parse_md_shortcode(txt) diff --git a/tests/docs/smoke-all/2024/11/14/issue-11441.qmd b/tests/docs/smoke-all/2024/11/14/issue-11441.qmd new file mode 100644 index 00000000000..e6747003fc0 --- /dev/null +++ b/tests/docs/smoke-all/2024/11/14/issue-11441.qmd @@ -0,0 +1,14 @@ +--- +format: html +hello: world +_quarto: + tests: + html: + ensureHtmlElements: + - [] + - ["main p:nth-child(3)"] +--- + +1 +{{< meta hello >}} +3 diff --git a/tests/docs/smoke-all/lightbox/addtl/example.qmd b/tests/docs/smoke-all/lightbox/addtl/example.qmd index d6514bfc42a..605914672f2 100644 --- a/tests/docs/smoke-all/lightbox/addtl/example.qmd +++ b/tests/docs/smoke-all/lightbox/addtl/example.qmd @@ -8,7 +8,6 @@ _quarto: - [".glightbox-desc.lightbox-desc-1",".glightbox-desc.lightbox-desc-5",".glightbox-desc.lightbox-desc-10", "a[data-gallery='elsewhere']"] ensureFileRegexMatches: - ['title="Figure 1', "Chilmark has a reputation as having some of the best beaches on Martha’s Vineyard."] - --- ## Chilmark @@ -73,6 +72,7 @@ plot(mtcars) ``` It is possible to create several plots, and group them in a lightbox gallery. Use list in YAML for options when you have several plots, on per plot. + ```{r} #| fig-cap: #| - Caption for first plot diff --git a/tests/unit/break-quarto-md/break-quarto-md.test.ts b/tests/unit/break-quarto-md/break-quarto-md.test.ts index 09aa5f39849..2e2a8ee1db3 100644 --- a/tests/unit/break-quarto-md/break-quarto-md.test.ts +++ b/tests/unit/break-quarto-md/break-quarto-md.test.ts @@ -19,7 +19,7 @@ unitTest("break-quarto-md - empty code cells", async () => { ); const result = await breakQuartoMd(qmd); - assert(result.cells.length === 9); + assert(result.cells.length === 10); }); unitTest("break-quarto-md - indented code cells", async () => {