From 0db460d24724e9d6fd96704d9322abf51bc61706 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Mon, 27 Nov 2023 20:39:53 +0000 Subject: [PATCH] bibliography entry in Rmd document is not code --- src/jupytext/cell_reader.py | 4 +++- .../simple_notebooks/test_read_simple_rmd.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/jupytext/cell_reader.py b/src/jupytext/cell_reader.py index e4ea21c13..9e7dedfcb 100644 --- a/src/jupytext/cell_reader.py +++ b/src/jupytext/cell_reader.py @@ -443,7 +443,9 @@ def find_cell_end(self, lines): return i - 1, i, False return i, i, False - if self.start_code_re.match(line): + if self.start_code_re.match(line) and not line.startswith( + "```{bibliography}" + ): # 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 ee10f3ba9..56958a19b 100644 --- a/tests/functional/simple_notebooks/test_read_simple_rmd.py +++ b/tests/functional/simple_notebooks/test_read_simple_rmd.py @@ -264,3 +264,20 @@ def test_commented_triple_quote_1060(line): compare(rmd2, rmd) nb2 = jupytext.reads(rmd, fmt="Rmd") compare_notebooks(nb2, nb) + + +def test_bibliography_in_rmd( + rmd="""Issue #1161 + +The bibliography section below should not +become a code cell + +```{bibliography} +``` +""", +): + nb = jupytext.reads(rmd, fmt="Rmd") + assert len(nb.cells) == 1, nb.cells + assert nb.cells[0].cell_type == "markdown" + rmd2 = jupytext.writes(nb, fmt="Rmd") + compare(rmd2, rmd)