Skip to content

Commit

Permalink
Ignore line breaks in markdown cells when using pandoc
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Mar 27, 2019
1 parent c3fce8a commit cfe613e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion jupytext/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down

0 comments on commit cfe613e

Please sign in to comment.