From 74f10d511b3e218adb42b6c377fcea7919a95b25 Mon Sep 17 00:00:00 2001 From: Jamal Mustafa Date: Thu, 12 Aug 2021 23:45:36 -0700 Subject: [PATCH 1/2] add support for parsing raw multiline strings --- jupytext/cell_reader.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/jupytext/cell_reader.py b/jupytext/cell_reader.py index 3c38aec4e..cf8680bb2 100644 --- a/jupytext/cell_reader.py +++ b/jupytext/cell_reader.py @@ -288,19 +288,24 @@ def extract_content(self, lines): content = "\n".join(lines).strip() for triple_quote in ['"""', "'''"]: if ( - content.startswith(triple_quote) + content.startswith((triple_quote, 'r'+triple_quote, 'R'+triple_quote)) and content.endswith(triple_quote) and len(content) >= 6 ): - left = right = triple_quote - content = content[3:-3] + if content.startswith(('r'+triple_quote, 'R'+triple_quote)): + left = content[:4] + right = triple_quote + content = content[4:-3] + else: + left = right = triple_quote + content = content[3:-3] # Trim first/last line return if content.startswith("\n"): content = content[1:] - left = triple_quote + "\n" + left = left + "\n" if content.endswith("\n"): content = content[:-1] - right = "\n" + triple_quote + right = "\n" + right if len(left) == len(right) == 4: self.metadata["cell_marker"] = left[:3] else: From 0577997108c266f0de42a3e7acb922fa717c78fb Mon Sep 17 00:00:00 2001 From: Jamal Mustafa Date: Mon, 16 Aug 2021 00:07:58 -0700 Subject: [PATCH 2/2] fix formatting to pass pre-commit checks --- jupytext/cell_reader.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/jupytext/cell_reader.py b/jupytext/cell_reader.py index cf8680bb2..252994aed 100644 --- a/jupytext/cell_reader.py +++ b/jupytext/cell_reader.py @@ -288,11 +288,13 @@ def extract_content(self, lines): content = "\n".join(lines).strip() for triple_quote in ['"""', "'''"]: if ( - content.startswith((triple_quote, 'r'+triple_quote, 'R'+triple_quote)) + content.startswith( + (triple_quote, "r" + triple_quote, "R" + triple_quote) + ) and content.endswith(triple_quote) and len(content) >= 6 ): - if content.startswith(('r'+triple_quote, 'R'+triple_quote)): + if content.startswith(("r" + triple_quote, "R" + triple_quote)): left = content[:4] right = triple_quote content = content[4:-3]