Skip to content

Commit a120c2a

Browse files
committed
include empty code cells. fixes #1034
1 parent d330ccb commit a120c2a

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,7 @@ export async function breakQuartoMd(
7171
| "directive",
7272
index: number,
7373
) => {
74-
if (lineBuffer.length) {
75-
// TODO understand why was this here. This makes our line
76-
// count computations wrong
77-
//
78-
// if (lineBuffer[lineBuffer.length - 1].substring === "") {
79-
// lineBuffer.splice(lineBuffer.length - 1, 1);
80-
// }
81-
74+
if (lineBuffer.length || cell_type === "code") {
8275
const mappedChunks: Range[] = [];
8376
for (const line of lineBuffer) {
8477
mappedChunks.push(line.range);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
execute:
3+
echo: true
4+
---
5+
6+
The original chunk:
7+
8+
```{r}
9+
#| label: foo
10+
1 + 2
11+
```
12+
13+
Using `ref.label` does not work with an empty body:
14+
15+
```{r, ref.label = "foo"}
16+
```
17+
18+
Using `ref.label` does work with a blank line body:
19+
20+
```{r, ref.label = "foo"}
21+
22+
```
23+
24+
Using `<<...>>` noweb notation does work:
25+
26+
```{r}
27+
<<foo>>
28+
```

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,24 @@
55
*
66
*/
77

8-
import { breakQuartoMd } from "../../src/core/lib/break-quarto-md.ts";
9-
import { unitTest } from "../test.ts";
8+
import { breakQuartoMd } from "../../../src/core/lib/break-quarto-md.ts";
9+
import { unitTest } from "../../test.ts";
1010
import { assert } from "testing/asserts.ts";
11+
import { docs } from "../../utils.ts";
12+
import { initYamlIntelligenceResourcesFromFilesystem } from "../../../src/core/schema/utils.ts";
13+
14+
unitTest("break-quarto-md - empty code cells", async () => {
15+
await initYamlIntelligenceResourcesFromFilesystem();
16+
const qmd = Deno.readTextFileSync(
17+
docs("break-quarto-md/github-issue-1034.qmd"),
18+
);
19+
20+
const result = await breakQuartoMd(qmd);
21+
assert(result.cells.length === 9);
22+
});
1123

1224
unitTest("break-quarto-md - indented code cells", async () => {
25+
await initYamlIntelligenceResourcesFromFilesystem();
1326
const qmd = `---
1427
title: Blah
1528
---
@@ -37,6 +50,7 @@ Blah blah
3750
});
3851

3952
unitTest("break-quarto-md - math", async () => {
53+
await initYamlIntelligenceResourcesFromFilesystem();
4054
const qmd = `---
4155
title: foo
4256
---
@@ -56,6 +70,7 @@ Some more text;
5670
});
5771

5872
unitTest("break-quarto-md - code", async () => {
73+
await initYamlIntelligenceResourcesFromFilesystem();
5974
const qmd = `---
6075
title: mermaid test
6176
format: html
@@ -86,6 +101,7 @@ Do not touch this, please.
86101
});
87102

88103
unitTest("break-quarto-md - nested code", async () => {
104+
await initYamlIntelligenceResourcesFromFilesystem();
89105
const qmd = `---
90106
title: mermaid test
91107
format: html

0 commit comments

Comments
 (0)