Skip to content

Commit

Permalink
Fix the handling of bibliography sections (mwouts#1180)
Browse files Browse the repository at this point in the history
in R Markdown notebooks
  • Loading branch information
mwouts authored Dec 2, 2023
1 parent 40643de commit e42bdb7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/jupytext/cell_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,12 @@ def find_cell_end(self, lines):
return i - 1, i, False
return i, i, False

if self.start_code_re.match(line) and not line.startswith(
"```{bibliography}"
):
if self.start_code_re.match(line):
if line.startswith("```{bibliography}"):
in_explicit_code_block = True
prev_blank = 0
continue

# Cells with a .noeval attribute are markdown cells #347
_, metadata = self.options_to_metadata(
self.start_code_re.findall(line)[0]
Expand Down
8 changes: 7 additions & 1 deletion tests/functional/simple_notebooks/test_read_simple_rmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,16 @@ def test_bibliography_in_rmd(
```{bibliography}
```
```{r}
6
```
""",
):
nb = jupytext.reads(rmd, fmt="Rmd")
assert len(nb.cells) == 1, nb.cells
assert len(nb.cells) == 2, nb.cells
assert nb.cells[0].cell_type == "markdown"
assert nb.cells[1].cell_type == "code"
assert nb.cells[1].source == "6"
rmd2 = jupytext.writes(nb, fmt="Rmd")
compare(rmd2, rmd)

0 comments on commit e42bdb7

Please sign in to comment.