Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't add stray spaces in breakQuartoMd #11442

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/core/handlers/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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 (
Expand All @@ -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) {
Expand Down
33 changes: 1 addition & 32 deletions src/core/lib/break-quarto-md.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export async function breakQuartoMd(
mappedChunks,
fileName,
);

const makeCellType = () => {
if (cell_type === "code") {
return { language };
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions src/resources/pandoc/datadir/readqmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions tests/docs/smoke-all/2024/11/14/issue-11441.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
format: html
hello: world
_quarto:
tests:
html:
ensureHtmlElements:
- []
- ["main p:nth-child(3)"]
---

1
{{< meta hello >}}
3
2 changes: 1 addition & 1 deletion tests/docs/smoke-all/lightbox/addtl/example.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -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&nbsp;1', "Chilmark has a reputation as having some of the best beaches on Martha’s Vineyard."]

---

## Chilmark
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/break-quarto-md/break-quarto-md.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Loading