Skip to content

Commit

Permalink
Escape common magics #35
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Aug 22, 2018
1 parent d5457dc commit 158ed63
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions nbrmd/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
'%timeit %unalias %unload_ext %who %who_ls %whos ' \
'%xdel %xmode'.split(' ')

# Add classical line magics
_LINE_MAGICS += ('%autoreload %aimport ' # autoreload
'%R %Rpush %Rpull %Rget ' # rmagic
'%store ' # storemagic
).split(' ')

# Remove any blank line
_LINE_MAGICS = [magic for magic in _LINE_MAGICS if magic.startswith('%')]

# A magic expression is a line or cell magic escaped zero, or multiple times
_PERCENT_RE = re.compile(r"^(# |#)*%")
_FORCE_ESC_RE = re.compile(r"^(# |#)*%(.*)(#| )escape")
Expand Down
3 changes: 2 additions & 1 deletion tests/test_escape_magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@


@pytest.mark.parametrize('line', ['%matplotlib inline', '#%matplotlib inline',
'##%matplotlib inline', '%%HTML'])
'##%matplotlib inline', '%%HTML',
'%autoreload', '%store'])
def test_escape(line):
assert escape_magic([line]) == ['# ' + line]
assert unescape_magic(escape_magic([line])) == [line]
Expand Down

0 comments on commit 158ed63

Please sign in to comment.