Skip to content

Commit a35d0c9

Browse files
authored
Merge pull request #11442 from quarto-dev/bugfix/11441
Don't add stray spaces in breakQuartoMd
2 parents 6de2ca7 + 8e358e9 commit a35d0c9

File tree

7 files changed

+21
-42
lines changed

7 files changed

+21
-42
lines changed

news/changelog-1.7.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ All changes included in 1.7:
2424

2525
## Other Fixes and Improvements
2626

27+
- ([#11441](https://github.com/quarto-dev/quarto-cli/issues/11441)): Don't add newlines around shortcodes during processing.
2728
- ([#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.

src/core/handlers/base.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,7 @@ export async function expandIncludes(
405405
const newCells: MappedString[] = [];
406406
for (let i = 0; i < mdCells.length; ++i) {
407407
const cell = mdCells[i];
408-
newCells.push(
409-
i === 0 ? cell.sourceVerbatim : mappedConcat(["\n", cell.sourceVerbatim]),
410-
);
408+
newCells.push(cell.sourceVerbatim);
411409
}
412410

413411
await processMarkdownIncludes(newCells, options, filename);
@@ -437,9 +435,7 @@ export async function handleLanguageCells(
437435

438436
for (let i = 0; i < mdCells.length; ++i) {
439437
const cell = mdCells[i];
440-
newCells.push(
441-
i === 0 ? cell.sourceVerbatim : mappedConcat(["\n", cell.sourceVerbatim]),
442-
);
438+
newCells.push(cell.sourceVerbatim);
443439
if (
444440
cell.cell_type === "raw" ||
445441
cell.cell_type === "markdown"
@@ -483,7 +479,6 @@ export async function handleLanguageCells(
483479
(innerLanguageHandler.stage !== "any" &&
484480
innerLanguageHandler.stage !== options.stage)
485481
) { // we're in the wrong stage, so we don't actually do anything
486-
newCells[cell.index] = mappedConcat([newCells[cell.index], "\n"]);
487482
continue;
488483
}
489484
if (
@@ -492,7 +487,6 @@ export async function handleLanguageCells(
492487
) {
493488
// if no handler is present (or a directive was included for something
494489
// that responds to cells instead), we're a no-op
495-
newCells[cell.index] = mappedConcat([newCells[cell.index], "\n"]);
496490
continue;
497491
}
498492
if (innerLanguageHandler.directive === undefined) {

src/core/lib/break-quarto-md.ts

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ export async function breakQuartoMd(
7676
mappedChunks,
7777
fileName,
7878
);
79-
8079
const makeCellType = () => {
8180
if (cell_type === "code") {
8281
return { language };
@@ -148,13 +147,7 @@ export async function breakQuartoMd(
148147
// directives only carry tag source in sourceVerbatim, analogously to code
149148
cell.source = mappedString(src, mappedChunks.slice(1, -1), fileName);
150149
}
151-
// if the source is empty then don't add it
152-
if (
153-
mdTrimEmptyLines(lines(cell.sourceVerbatim.value)).length > 0 ||
154-
cell.options !== undefined
155-
) {
156-
nb.cells.push(cell);
157-
}
150+
nb.cells.push(cell);
158151

159152
lineBuffer.splice(0, lineBuffer.length);
160153
}
@@ -254,27 +247,3 @@ export async function breakQuartoMd(
254247

255248
return nb;
256249
}
257-
258-
function mdTrimEmptyLines(lines: string[]) {
259-
// trim leading lines
260-
const firstNonEmpty = lines.findIndex((line) => line.trim().length > 0);
261-
if (firstNonEmpty === -1) {
262-
return [];
263-
}
264-
lines = lines.slice(firstNonEmpty);
265-
266-
// trim trailing lines
267-
let lastNonEmpty = -1;
268-
for (let i = lines.length - 1; i >= 0; i--) {
269-
if (lines[i].trim().length > 0) {
270-
lastNonEmpty = i;
271-
break;
272-
}
273-
}
274-
275-
if (lastNonEmpty > -1) {
276-
lines = lines.slice(0, lastNonEmpty + 1);
277-
}
278-
279-
return lines;
280-
}

src/resources/pandoc/datadir/readqmd.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ local function urldecode(url)
126126
end
127127

128128
local function readqmd(txt, opts)
129+
local tags
129130
txt = md_fenced_div.attempt_to_fix_fenced_div(txt)
130131
txt, tags = escape_invalid_tags(txt)
131132
txt = md_shortcode.parse_md_shortcode(txt)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
format: html
3+
hello: world
4+
_quarto:
5+
tests:
6+
html:
7+
ensureHtmlElements:
8+
- []
9+
- ["main p:nth-child(3)"]
10+
---
11+
12+
1
13+
{{< meta hello >}}
14+
3

tests/docs/smoke-all/lightbox/addtl/example.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ _quarto:
88
- [".glightbox-desc.lightbox-desc-1",".glightbox-desc.lightbox-desc-5",".glightbox-desc.lightbox-desc-10", "a[data-gallery='elsewhere']"]
99
ensureFileRegexMatches:
1010
- ['title="Figure&nbsp;1', "Chilmark has a reputation as having some of the best beaches on Martha’s Vineyard."]
11-
1211
---
1312

1413
## Chilmark
@@ -73,6 +72,7 @@ plot(mtcars)
7372
```
7473

7574
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.
75+
7676
```{r}
7777
#| fig-cap:
7878
#| - Caption for first plot

tests/unit/break-quarto-md/break-quarto-md.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ unitTest("break-quarto-md - empty code cells", async () => {
1919
);
2020

2121
const result = await breakQuartoMd(qmd);
22-
assert(result.cells.length === 9);
22+
assert(result.cells.length === 10);
2323
});
2424

2525
unitTest("break-quarto-md - indented code cells", async () => {

0 commit comments

Comments
 (0)