diff --git a/nbdime/prettyprint.py b/nbdime/prettyprint.py index ba5cd2b4..79beef32 100644 --- a/nbdime/prettyprint.py +++ b/nbdime/prettyprint.py @@ -647,8 +647,6 @@ def c(): # Write cell type and optionally number: numstr = "" if i is None else " %d" % i k = "%s cell%s" % (cell.get("cell_type"), numstr) - if "id" in cell: - k += f" [{cell['id']}]" pretty_print_key(k, prefix, config) c.called = True c.called = False @@ -656,6 +654,12 @@ def c(): if force_header: c() + id = cell.get("id") + if id and config.details: + # Write execution count if there (only source cells) + c() + pretty_print_item("id", id, key_prefix, config) + execution_count = cell.get("execution_count") if execution_count and config.details: # Write execution count if there (only source cells) diff --git a/nbdime/tests/filters/add_helper.py b/nbdime/tests/filters/add_helper.py index 82aa9e95..4444c48d 100644 --- a/nbdime/tests/filters/add_helper.py +++ b/nbdime/tests/filters/add_helper.py @@ -34,7 +34,8 @@ def _build_arg_parser(): def clean(notebook): if get_marker_cell(notebook) is None: notebook['cells'].append(nbformat.v4.new_raw_cell( - source=MARKER + source=MARKER, + id='filtered-cell', )) def smudge(notebook): diff --git a/nbdime/tests/test_git_diffdriver.py b/nbdime/tests/test_git_diffdriver.py index d8c48194..36384147 100644 --- a/nbdime/tests/test_git_diffdriver.py +++ b/nbdime/tests/test_git_diffdriver.py @@ -173,6 +173,7 @@ ## inserted before /cells/6: + raw cell: ++ id: filtered-cell + source: + nbdime test filter marker diff --git a/nbdime/tests/test_prettyprint.py b/nbdime/tests/test_prettyprint.py index 87092c2c..ae425277 100644 --- a/nbdime/tests/test_prettyprint.py +++ b/nbdime/tests/test_prettyprint.py @@ -200,6 +200,7 @@ def test_pretty_print_markdown_cell(): def test_pretty_print_code_cell(): cell = v4.new_code_cell(source='def foo():\n return 4', execution_count=3, + id='code-cell-id', outputs=[ v4.new_output('stream', name='stdout', text='some\ntext'), v4.new_output('display_data', {'text/plain': 'hello display'}), @@ -213,6 +214,7 @@ def test_pretty_print_code_cell(): assert lines == [ '+code cell:', + '+ id: code-cell-id', '+ execution_count: 3', '+ source:', '+ def foo():',