From e42bdb7b2959a9eba586be64eb8599012f486572 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Sat, 2 Dec 2023 17:22:54 +0000 Subject: [PATCH] Fix the handling of bibliography sections (#1180) in R Markdown notebooks --- src/jupytext/cell_reader.py | 9 ++++++--- .../functional/simple_notebooks/test_read_simple_rmd.py | 8 +++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/jupytext/cell_reader.py b/src/jupytext/cell_reader.py index 738cd24a..ba09b83b 100644 --- a/src/jupytext/cell_reader.py +++ b/src/jupytext/cell_reader.py @@ -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] diff --git a/tests/functional/simple_notebooks/test_read_simple_rmd.py b/tests/functional/simple_notebooks/test_read_simple_rmd.py index 56958a19..0a15cf69 100644 --- a/tests/functional/simple_notebooks/test_read_simple_rmd.py +++ b/tests/functional/simple_notebooks/test_read_simple_rmd.py @@ -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)