Repository: mwouts/jupytext (language: python)

Issue:
%magic can be after indent or tab
I have a code that I expect to work both in colab and jupyter, also in .py

```python

FROM_GOOGLE_COLAB = True
PROJECT_FOLDER = '/content/drive/MyDrive/SOME_REPO_NAME'
if FROM_GOOGLE_COLAB:
    !pip install somepackages

    from google.colab import drive
    drive.mount('/content/drive')
    %cd $PROJECT_FOLDER

```

But, jupytext didn't translate `%cd` as magic if it's indented or some white space exists before it.

```python
%cd
!pip install somepackages 

# become:
# %cd
# !pip install somepackages 


if True:
    %cd
    !pip install somepackages
    pass

# become:
if True:
    %cd # not works
    # !pip install somepackages 
    pass
```


Discussion / hints:
Hi @yasirroni , thank you for reporting this... I was not aware that one could use indented magic commands :smile: 
That should be pretty easy to fix, I'll have a look soon.

Fix patch:
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index abe4b7adf..b86ff3d49 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -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)
 ------------------
diff --git a/jupytext/magics.py b/jupytext/magics.py
index 4de898a84..9b7489d48 100644
--- a/jupytext/magics.py
+++ b/jupytext/magics.py
@@ -7,13 +7,13 @@
 # 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"]
         )
     )
@@ -21,7 +21,7 @@
 }
 _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"]
         )
     )


Test patch:
diff --git a/tests/test_escape_magics.py b/tests/test_escape_magics.py
index b483128c2..e25c9ac59 100644
--- a/tests/test_escape_magics.py
+++ b/tests/test_escape_magics.py
@@ -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"]