From 919461fbea10dddecff48195400dba3a0aab5c19 Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Tue, 20 Jun 2023 20:37:14 +0100 Subject: [PATCH] Reproduce and fix #1070 --- docs/CHANGELOG.md | 9 ++++++++- jupytext/formats.py | 2 ++ tests/test_read_simple_markdown.py | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 9ce2d6bcd..9b7d6c4d5 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,12 +1,19 @@ Jupytext ChangeLog ================== +1.14.7-dev (2023-06-??) +------------------- + +**Fixed** +- Fix opening of notebooks with empty YAML header ([#1070](https://github.com/mwouts/jupytext/issues/1070)) + + 1.14.6 (2023-06-04) ------------------- **Changed** - This version comes with a build requirement `jupyterlab>=3,<4`, as the Jupyterlab -extension for Jupytext is not compatible with JupyterLab 4 yet (#1054) +extension for Jupytext is not compatible with JupyterLab 4 yet ([#1054](https://github.com/mwouts/jupytext/issues/1054)) - The JupyterLab extension was released to `npm` in version 1.3.9. 1.14.5 (2023-02-25) diff --git a/jupytext/formats.py b/jupytext/formats.py index a5adc3100..d9a481768 100644 --- a/jupytext/formats.py +++ b/jupytext/formats.py @@ -280,6 +280,8 @@ def read_metadata(text, ext): # MyST has the metadata at the root level if not metadata and ext in myst_extensions() and text.startswith("---"): for header in yaml.safe_load_all(text): + if not isinstance(header, dict): + continue if ( header.get("jupytext", {}) .get("text_representation", {}) diff --git a/tests/test_read_simple_markdown.py b/tests/test_read_simple_markdown.py index 9ad0ab0b2..8a01f8cd8 100644 --- a/tests/test_read_simple_markdown.py +++ b/tests/test_read_simple_markdown.py @@ -941,3 +941,18 @@ def test_hide_notebook_metadata( compare(md2, md) nb2 = jupytext.reads(md, "md") compare_notebooks(nb2, nb) + + +def test_notebook_with_empty_header_1070( + md="""--- + +--- + +This file has empty frontmatter. +""", +): + nb = jupytext.reads(md, fmt="md:markdown") + md2 = jupytext.writes(nb, "md") + compare(md2, md) + nb2 = jupytext.reads(md, "md") + compare_notebooks(nb2, nb)