Skip to content

Commit

Permalink
End of cell option renamed to 'endofcell' #31
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Aug 19, 2018
1 parent 425c6d0 commit 1aa1b95
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
20 changes: 10 additions & 10 deletions nbrmd/cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,23 @@ def code_to_text(self,
else: # py
# end of cell marker
if not active or need_end_cell_marker(self, source):
cellend = '-'
endofcell = '-'
while True:
cellend_re = re.compile(r'^#( )' + cellend + r'\s*$')
if list(filter(cellend_re.match, source)):
cellend = cellend + '-'
endofcell_re = re.compile(r'^#( )' + endofcell + r'\s*$')
if list(filter(endofcell_re.match, source)):
endofcell = endofcell + '-'
else:
break
metadata['cellend'] = cellend
metadata['endofcell'] = endofcell

options = metadata_to_json_options(metadata)
if options != '{}':
lines.append('# + ' + options)
if not active:
source = ['# ' + line for line in source]
lines.extend(source)
if 'cellend' in metadata:
lines.append('# ' + metadata['cellend'])
if 'endofcell' in metadata:
lines.append('# ' + metadata['endofcell'])

# Two blank lines before next code cell
if next_cell_is_code:
Expand Down Expand Up @@ -309,9 +309,9 @@ def code_to_cell(self, lines, parse_opt):

if self.ext == '.Rmd':
end_cell_re = _END_CODE_MD
elif self.ext == '.py' and 'cellend' in metadata:
end_cell_re = re.compile(r'^#( )' + metadata['cellend'] + r'\s*$')
del metadata['cellend']
elif self.ext == '.py' and 'endofcell' in metadata:
end_cell_re = re.compile(r'^#( )' + metadata['endofcell'] + r'\s*$')
del metadata['endofcell']
elif self.ext == '.R' and not is_active('.R', metadata):
end_cell_re = _BLANK_LINE
else:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_active_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_active_all(ext):
compare(ACTIVE_ALL[ext], nbrmd.writes(nb, ext=ext))


ACTIVE_IPYNB = {'.py': """# + {"active": "ipynb", "cellend": "-"}
ACTIVE_IPYNB = {'.py': """# + {"active": "ipynb", "endofcell": "-"}
# # This cell is active only in ipynb
# %matplotlib inline
# -
Expand Down Expand Up @@ -90,7 +90,7 @@ def test_active_py_ipynb(ext):
compare(ACTIVE_PY_IPYNB[ext], nbrmd.writes(nb, ext=ext))


ACTIVE_RMD = {'.py': """# + {"active": "Rmd", "cellend": "-"}
ACTIVE_RMD = {'.py': """# + {"active": "Rmd", "endofcell": "-"}
# # This cell is active in Rmd only
# -
""",
Expand Down
6 changes: 3 additions & 3 deletions tests/test_read_simple_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_read_cell_two_blank_lines(pynb="""# ---
# title: cell with two consecutive blank lines
# ---
# + {"cellend": "-"}
# + {"endofcell": "-"}
a = 1
Expand All @@ -136,7 +136,7 @@ def test_read_cell_two_blank_lines(pynb="""# ---

def test_read_cell_explicit_start_end(pynb='''
import pandas as pd
# + {"cellend": "-"}
# + {"endofcell": "-"}
def data():
return pd.DataFrame({'A': [0, 1]})
Expand All @@ -151,7 +151,7 @@ def data():

def test_read_prev_function(pynb="""def test_read_cell_explicit_start_end(pynb='''
import pandas as pd
# + {"cellend": "-"}
# + {"endofcell": "-"}
def data():
return pd.DataFrame({'A': [0, 1]})
Expand Down

0 comments on commit 1aa1b95

Please sign in to comment.