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

remove newlines from comment block #15

Open
jeisner opened this issue Nov 18, 2023 · 4 comments
Open

remove newlines from comment block #15

jeisner opened this issue Nov 18, 2023 · 4 comments

Comments

@jeisner
Copy link

jeisner commented Nov 18, 2023

Code is often formatted to 80 columns or some similar width.
It would be nice to have a flag so that a word-wrapped comment block like

# The data that we are interested in is made of 8x8 images of digits.
# Let's have a look at the first 4 images, which is of course
# stored in the `images` attribute of the dataset.  

appears like this, where Jupyter gets to wrap to the width of the cell:

The data that we are interested in is made of 8x8 images of digits. Let's have a look at the first 4 images, which is of course stored in the `images` attribute of the dataset.  

Note that the underlying Markdown would still have the line breaks, in case the user wants to edit it to restore any intended line break.

The data that we are interested in is made of 8x8 images of digits. 
Let's have a look at the first 4 images, which is of course 
stored in the `images` attribute of the dataset.  
@jeisner
Copy link
Author

jeisner commented Nov 18, 2023

Currently I do this by postprocessing. You can correct the output file output.ipynb by removing the line breaks <br> that p2j inserts before the newline at the end of each markdown string:
perl -i -pe 's/<br>(?=\\n")//g' output.ipynb
Here's a better version that preserves a line break before an indented line.
perl -i -pe 's/<br>(?=\\n", "\S)//g' output.ipynb
Either version will preserve blank lines, e.g., between paragraphs.

However, this solution isn't bulletproof because it just does local pattern matching. It would be better to have a command-line option to p2j that avoids inserting <br> in the first place. That's also more user-friendly.

@jeisner jeisner closed this as completed Nov 18, 2023
@jeisner jeisner reopened this Nov 18, 2023
@remykarem
Copy link
Owner

remykarem commented Dec 1, 2023 via email

@jeisner
Copy link
Author

jeisner commented Dec 1, 2023

Looking at your p2j.py code and specifically at the part that adds <br>, it looks like you already included some logic that tries to determine where to add line breaks?

I might disagree with your choices there, but I'm afraid that if I just got rid of <br>, I would be breaking some cases where you deliberately wanted (which I may not have encountered).

@AdrianSosic
Copy link

I would be also interested in this feature 👍🏼

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

No branches or pull requests

3 participants