Skip to content

Commit

Permalink
Reproduce and fix #164
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Jan 30, 2019
1 parent 8b6ed3d commit e532ca3
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 1 deletion.
2 changes: 2 additions & 0 deletions jupytext/cell_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ def find_code_cell_end(self, lines):

if self.start_code_re.match(line) or (self.markdown_prefix and line.startswith(self.markdown_prefix)):
if i > 1 and _BLANK_LINE.match(lines[i - 1]):
if i > 2 and _BLANK_LINE.match(lines[i - 2]):
return i - 2, i, False
return i - 1, i, False
return i, i, False

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 + 1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A markdown cell\n",
"And below, the cell for function f has non trivial cell metadata. And the next cell as well."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"attributes": {
"classes": [],
"id": "",
"n": "10"
}
},
"outputs": [],
"source": [
"def f(x):\n",
" return x"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"attributes": {
"classes": [],
"id": "",
"n": "10"
}
},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f(5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"More text"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2 + 2"
]
}
],
"metadata": {
"celltoolbar": "Edit Metadata",
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.6"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
jupyter:
kernelspec:
display_name: Python 3
language: python
name: python3
---

```{python}
1 + 1
```

A markdown cell
And below, the cell for function f has non trivial cell metadata. And the next cell as well.

```{python attributes={'classes': [], 'id': '', 'n': '10'}}
def f(x):
return x
```

```{python attributes={'classes': [], 'id': '', 'n': '10'}}
f(5)
```

More text

```{python}
2 + 2
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
jupyter:
kernelspec:
display_name: Python 3
language: python
name: python3
---

```python
1 + 1
```

A markdown cell
And below, the cell for function f has non trivial cell metadata. And the next cell as well.

```python
def f(x):
return x
```

```python
f(5)
```

More text

```python
2 + 2
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# ---
# jupyter:
# kernelspec:
# display_name: Python 3
# language: python
# name: python3
# ---

# %%
1 + 1


# %% [markdown]
# A markdown cell
# And below, the cell for function f has non trivial cell metadata. And the next cell as well.

# %% {"attributes": {"classes": [], "id": "", "n": "10"}}
def f(x):
return x


# %% {"attributes": {"classes": [], "id": "", "n": "10"}}
f(5)

# %% [markdown]
# More text

# %%
2 + 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# ---
# jupyter:
# kernelspec:
# display_name: Python 3
# language: python
# name: python3
# ---

1 + 1


# A markdown cell
# And below, the cell for function f has non trivial cell metadata. And the next cell as well.

# + {"attributes": {"classes": [], "id": "", "n": "10"}}
def f(x):
return x


# + {"attributes": {"classes": [], "id": "", "n": "10"}}
f(5)
# -

# More text

2 + 2
2 changes: 1 addition & 1 deletion tests/test_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def test_spin_to_ipynb(nb_file):
assert_conversion_same_as_mirror(nb_file, 'ipynb:spin', 'script_to_ipynb')


@pytest.mark.parametrize('nb_file', list_notebooks('ipynb_py', skip='(raw|hash|frozen|magic)'))
@pytest.mark.parametrize('nb_file', list_notebooks('ipynb_py', skip='(raw|hash|frozen|magic|164)'))
def test_ipynb_to_python_sphinx(nb_file):
assert_conversion_same_as_mirror(nb_file, 'py:sphinx', 'ipynb_to_sphinx')

Expand Down

0 comments on commit e532ca3

Please sign in to comment.