diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 9b7d6c4d5..092192bc5 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -5,7 +5,8 @@ Jupytext ChangeLog ------------------- **Fixed** -- Fix opening of notebooks with empty YAML header ([#1070](https://github.com/mwouts/jupytext/issues/1070)) +- Fix opening notebooks with empty YAML header ([#1070](https://github.com/mwouts/jupytext/issues/1070)) +- Fix single quote in double quote strings in R Markdown options ([#1079](https://github.com/mwouts/jupytext/issues/1079)) 1.14.6 (2023-06-04) diff --git a/jupytext/cell_metadata.py b/jupytext/cell_metadata.py index 21353c3fa..d49aa0c03 100644 --- a/jupytext/cell_metadata.py +++ b/jupytext/cell_metadata.py @@ -201,9 +201,9 @@ def count_special_chars(self, char, prev_char): 'Option line "{}" has too many ' "closing square brackets".format(self.line) ) - elif char == "'" and prev_char != "\\": + elif char == "'" and prev_char != "\\" and not self.in_double_quote: self.in_single_quote = not self.in_single_quote - elif char == '"' and prev_char != "\\": + elif char == '"' and prev_char != "\\" and not self.in_single_quote: self.in_double_quote = not self.in_double_quote diff --git a/tests/test_read_simple_rmd.py b/tests/test_read_simple_rmd.py index a374fa022..b37152ab3 100644 --- a/tests/test_read_simple_rmd.py +++ b/tests/test_read_simple_rmd.py @@ -232,3 +232,17 @@ def test_pair_rmd_file_with_cell_tags_and_options( # The new code chunk has the new code, and options are still there compare(rmd2, rmd.replace("3", "4")) + + +def test_apostrophe_in_parameter_1079( + no_jupytext_version_number, + rmd="""```{python some-name, param="Problem's"} +a = 1 +``` +""", +): + nb = jupytext.reads(rmd, fmt="Rmd") + rmd2 = jupytext.writes(nb, fmt="Rmd") + compare(rmd2, rmd) + nb2 = jupytext.reads(rmd, fmt="Rmd") + compare_notebooks(nb2, nb)