Skip to content

Commit

Permalink
Indented magic commands are supported
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Jan 14, 2021
1 parent 12fb00e commit f53facf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Jupytext ChangeLog
**Changed**
- Jupytext does not work properly with the new cell ids of the version 4.5 of `nbformat>=5.1.0` yet, so we added the requirement `nbformat<=5.0.8` (#715)

**Fixed**
- Indented magic commands are supported (#694)


1.9.1 (2021-01-06)
------------------
Expand Down
6 changes: 3 additions & 3 deletions jupytext/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
# A magic expression is a line or cell or metakernel magic (#94, #61) escaped zero, or multiple times
_MAGIC_RE = {
_SCRIPT_EXTENSIONS[ext]["language"]: re.compile(
r"^({0} |{0})*(%|%%|%%%)[a-zA-Z]".format(_SCRIPT_EXTENSIONS[ext]["comment"])
r"^\s*({0} |{0})*(%|%%|%%%)[a-zA-Z]".format(_SCRIPT_EXTENSIONS[ext]["comment"])
)
for ext in _SCRIPT_EXTENSIONS
}
_MAGIC_FORCE_ESC_RE = {
_SCRIPT_EXTENSIONS[ext]["language"]: re.compile(
r"^({0} |{0})*(%|%%|%%%)[a-zA-Z](.*){0}\s*escape".format(
r"^\s*({0} |{0})*(%|%%|%%%)[a-zA-Z](.*){0}\s*escape".format(
_SCRIPT_EXTENSIONS[ext]["comment"]
)
)
for ext in _SCRIPT_EXTENSIONS
}
_MAGIC_NOT_ESC_RE = {
_SCRIPT_EXTENSIONS[ext]["language"]: re.compile(
r"^({0} |{0})*(%|%%|%%%)[a-zA-Z](.*){0}\s*noescape".format(
r"^\s*({0} |{0})*(%|%%|%%%)[a-zA-Z](.*){0}\s*noescape".format(
_SCRIPT_EXTENSIONS[ext]["comment"]
)
)
Expand Down
3 changes: 3 additions & 0 deletions tests/test_escape_magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,5 +270,8 @@ def test_configure_magic(no_jupytext_version_number):
def test_indented_magic():
assert is_magic(" !rm file", "python")
assert is_magic(" # !rm file", "python")
assert is_magic(" %cd", "python")
assert comment_magic([" !rm file"]) == [" # !rm file"]
assert uncomment_magic([" # !rm file"]) == [" !rm file"]
assert comment_magic([" %cd"]) == [" # %cd"]
assert uncomment_magic([" # %cd"]) == [" %cd"]

0 comments on commit f53facf

Please sign in to comment.