Skip to content

Commit 23c7a99

Browse files
committed
Fix reading cells from rmd
1 parent a662a98 commit 23c7a99

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

src/notebook.ts

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -175,29 +175,33 @@ export class RNotebookProvider implements vscode.NotebookContentProvider, vscode
175175
cellType = 'yaml';
176176
cellStartLine = line;
177177
} else if (lines[line].startsWith('```{r')) {
178-
cells.push({
179-
cellKind: vscode.CellKind.Markdown,
180-
source: lines.slice(cellStartLine, line).join('\n'),
181-
language: 'markdown',
182-
outputs: [],
183-
metadata: {
184-
editable: true,
185-
runnable: false,
186-
},
187-
});
178+
if (line > cellStartLine) {
179+
cells.push({
180+
cellKind: vscode.CellKind.Markdown,
181+
source: lines.slice(cellStartLine, line).join('\n'),
182+
language: 'markdown',
183+
outputs: [],
184+
metadata: {
185+
editable: true,
186+
runnable: false,
187+
},
188+
});
189+
}
188190
cellType = 'r';
189191
cellStartLine = line;
190192
} else if (line === lines.length - 1) {
191-
cells.push({
192-
cellKind: vscode.CellKind.Markdown,
193-
source: lines.slice(cellStartLine, line).join('\n'),
194-
language: 'markdown',
195-
outputs: [],
196-
metadata: {
197-
editable: true,
198-
runnable: false,
199-
},
200-
});
193+
if (line > cellStartLine) {
194+
cells.push({
195+
cellKind: vscode.CellKind.Markdown,
196+
source: lines.slice(cellStartLine, line).join('\n'),
197+
language: 'markdown',
198+
outputs: [],
199+
metadata: {
200+
editable: true,
201+
runnable: false,
202+
},
203+
});
204+
}
201205
}
202206
} else if (cellType === 'yaml') {
203207
if (lines[line].startsWith('---')) {

0 commit comments

Comments
 (0)