Skip to content

Commit

Permalink
Fix the round trip conversion issue
Browse files Browse the repository at this point in the history
Code cell was transformed to a markdown cell in py format
#339
  • Loading branch information
mwouts committed Oct 13, 2019
1 parent 54fac2d commit 4576d6a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion jupytext/cell_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def paragraph_is_fully_commented(lines, comment, main_language):
"""Is the paragraph fully commented?"""
for i, line in enumerate(lines):
if line.startswith(comment):
if line.startswith((comment + ' %', comment + ' ?', comment + ' !')) and is_magic(line, main_language):
if line[len(comment):].lstrip().startswith(comment):
continue
if is_magic(line, main_language):
return False
continue
return i > 0 and _BLANK_LINE.match(line)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -958,3 +958,12 @@ def test_warn_only_skips_incorrect_notebook(tmpdir, capsys):

assert not os.path.exists(incorrect_md)
assert os.path.exists(correct_md)


@pytest.mark.parametrize('fmt', ['md', 'Rmd', 'py', 'py:percent', 'py:hydrogen'])
def test_339_ipynb(tmpdir, fmt):
tmp_ipynb = str(tmpdir.join('test.ipynb'))
nb = new_notebook(cells=[new_code_cell('cat = 42')])
nbformat.write(nb, tmp_ipynb)

assert jupytext([tmp_ipynb, '--to', fmt, '--test-strict']) == 0

0 comments on commit 4576d6a

Please sign in to comment.