From cfe613ee9ad085b39effcfb05a7704f41dc9f48f Mon Sep 17 00:00:00 2001 From: Marc Wouts Date: Wed, 27 Mar 2019 22:59:51 +0100 Subject: [PATCH] Ignore line breaks in markdown cells when using pandoc #208 --- jupytext/compare.py | 8 +++++++- tests/test_mirror.py | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/jupytext/compare.py b/jupytext/compare.py index acf9c5cdd..1db792b10 100644 --- a/jupytext/compare.py +++ b/jupytext/compare.py @@ -83,6 +83,7 @@ def compare_notebooks(notebook_expected, allow_missing_code_cell_metadata = allow_expected_differences and format_name == 'sphinx' allow_missing_markdown_cell_metadata = allow_expected_differences and format_name in ['sphinx', 'spin'] allow_removed_final_blank_line = allow_expected_differences + allow_different_line_breaks_in_markdown_cells = format_name == 'pandoc' cell_metadata_filter = notebook_actual.get('jupytext', {}).get('cell_metadata_filter') @@ -142,6 +143,10 @@ def compare_notebooks(notebook_expected, test_lines.extend([line for line in test_cell.source.splitlines() if not _BLANK_LINE.match(line)]) # 3. test cell content + if allow_different_line_breaks_in_markdown_cells and ref_cell.cell_type == 'markdown': + ref_lines = [' '.join(ref_lines)] + test_lines = [' '.join(test_lines)] + if ref_lines != test_lines: if raise_on_first_difference: try: @@ -153,7 +158,8 @@ def compare_notebooks(notebook_expected, modified_cells.add(i) # 3. bis test entire cell content - if not same_content(ref_cell.source, test_cell.source, allow_removed_final_blank_line): + if not same_content(ref_cell.source, test_cell.source, allow_removed_final_blank_line) and \ + not allow_different_line_breaks_in_markdown_cells: try: compare(ref_cell.source, test_cell.source) except AssertionError as error: diff --git a/tests/test_mirror.py b/tests/test_mirror.py index f5a6d3fec..734a6a2a7 100644 --- a/tests/test_mirror.py +++ b/tests/test_mirror.py @@ -76,10 +76,10 @@ def assert_conversion_same_as_mirror(nb_file, fmt, mirror_name, compare_notebook for cell in nb_mirror.cells: cell.metadata = {} - compare_notebooks(notebook, nb_mirror, ext) + compare_notebooks(notebook, nb_mirror, fmt) combine_inputs_with_outputs(nb_mirror, notebook) - compare_notebooks(notebook, nb_mirror, ext, compare_outputs=True) + compare_notebooks(notebook, nb_mirror, fmt, compare_outputs=True) @pytest.mark.parametrize('nb_file', list_notebooks('julia') + list_notebooks('python') + list_notebooks('R'))