Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encapsulate code cells with triple backticks with +1 backtick in Markdown #726

Merged
merged 6 commits into from
Jan 27, 2021

Conversation

mwouts
Copy link
Owner

@mwouts mwouts commented Jan 24, 2021

This PR will close #712 .

@rsokl I am considering taking this opportunity to remove the parsing of Python strings inside code cells (since now the cell marker is non-ambiguous), but that may break some of your notebooks, cf. #419 . Do you have many of them?

Also @chrisjsewell I have not yet ported this to md:myst but I intend to do so before merging.

@mwouts
Copy link
Owner Author

mwouts commented Jan 25, 2021

I am considering taking this opportunity to remove the parsing of Python strings inside code cells

FYI I changed my mind, and finally prefer to keep the parsing of the code cell, for a while at least, to provide backward compatibility.

@chrisjsewell
Copy link
Contributor

Heya yeh that looks good to me 👍

@codecov
Copy link

codecov bot commented Jan 25, 2021

Codecov Report

Merging #726 (1449249) into master (41b7e9c) will decrease coverage by 0.00%.
The diff coverage is 99.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #726      +/-   ##
==========================================
- Coverage   99.12%   99.12%   -0.01%     
==========================================
  Files          95       97       +2     
  Lines        9502     9591      +89     
==========================================
+ Hits         9419     9507      +88     
- Misses         83       84       +1     
Impacted Files Coverage Δ
jupytext/metadata_filter.py 99.13% <ø> (ø)
tests/test_auto_ext.py 100.00% <ø> (ø)
tests/test_cells.py 100.00% <ø> (ø)
tests/test_config.py 100.00% <ø> (ø)
tests/test_hide_remove_input_outputs_rmarkdown.py 100.00% <ø> (ø)
tests/test_ipynb_to_py.py 100.00% <ø> (ø)
tests/test_ipynb_to_rmd.py 100.00% <ø> (ø)
tests/test_jupytext_errors.py 100.00% <ø> (ø)
tests/test_jupytext_nbconvert_round_trip.py 100.00% <ø> (ø)
tests/test_jupytext_read.py 100.00% <ø> (ø)
... and 80 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 75cba9e...1449249. Read the comment docs.

@mwouts
Copy link
Owner Author

mwouts commented Jan 25, 2021

Heya yeh that looks good to me +1

@chrisjsewell you're too fast! You did not even leave me the time to ask 😆

So just to be sure you're also OK with the version bump on the MyST format (to 0.13)? Thanks!

@mwouts mwouts force-pushed the triple_backticks_in_code_cell branch from c4b5a4a to 3cdd2dc Compare January 26, 2021 00:58
@rsokl
Copy link

rsokl commented Jan 27, 2021

@mwouts thank you for keeping me posted on this.

I don't think that #419 pops up too much. That being said, with the present change, would upgrading the jupytext-markdown version of my document (i.e. old-md -> ipynb -> new-md) ensure that everything is ok in the future?

@mwouts
Copy link
Owner Author

mwouts commented Jan 27, 2021

I don't think that #419 pops up too much. That being said, with the present change, would upgrading the jupytext-markdown version of my document (i.e. old-md -> ipynb -> new-md) ensure that everything is ok in the future?

Indeed! The markdown code blocks with triple backticks that encapsulate a code cell with triple backticks in a string will become markdown code blocks with quadruple backticks, like in this test (look at line 784)

def test_markdown_cell_with_code_inside_multiline_string_419(
text='''```python
readme = """
above
```python
x = 2
```
below
"""
```
''',
):
"""A code cell containing triple backticks is converted to a code cell encapsulated with four backticks"""
nb = jupytext.reads(text, "md")
compare(jupytext.writes(nb, "md"), "`" + text[:-1] + "`\n")
assert len(nb.cells) == 1

@mwouts mwouts merged commit a2f1409 into master Jan 27, 2021
@mwouts mwouts deleted the triple_backticks_in_code_cell branch January 27, 2021 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

triple backticks in a cell
3 participants