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

Add breaks extra with ability to hard break on backslashes (issue #525) #529

Merged
merged 3 commits into from
Sep 19, 2023

Conversation

Crozzers
Copy link
Contributor

@Crozzers Crozzers commented Sep 5, 2023

This PR closes #525 by adding the ability to insert hard breaks when lines end in a backslash.

The feature

By passing extras={'breaks': {'on_backslash': True}}, users can now use backslashes to insert hard breaks, an example of which can be found in the break_on_backslash test case.

Implementation

This has been implemented via a new breaks extra, which contains this new functionality as well as the old break-on-newline functionality. The old extra name has been kept as an alias, so the two following examples are equivalent:

markdown2.convert(text, extras=['break-on-newline'])
markdown2.convert(text, extras={'breaks': {'on_newline': True}})
markdown2.convert(text, extras={'breaks': {'on_newline': True, 'on_backslash': False}})

This was done because I felt that having separate break-on-* extras was unnecessary and that grouping these similar extras made sense.

@nicholasserra
Copy link
Collaborator

Looks great, thank you!

@nicholasserra nicholasserra merged commit d61a7e1 into trentm:master Sep 19, 2023
18 checks passed
@m417z
Copy link
Contributor

m417z commented Dec 3, 2023

Thank you. I assume it should be mentioned here at some point, right? Especially now that a version with this feature was released.
https://github.com/trentm/python-markdown2/wiki/Extras

@Crozzers
Copy link
Contributor Author

Crozzers commented Dec 3, 2023

Good shout. I've added a quick page for it here: https://github.com/trentm/python-markdown2/wiki/breaks

@m417z
Copy link
Contributor

m417z commented Dec 3, 2023

Looks good. I think it makes sense to link it from the Extras page I mentioned.

@Crozzers
Copy link
Contributor Author

Crozzers commented Dec 4, 2023

Updated the list of implemented extras as well

@m417z
Copy link
Contributor

m417z commented Dec 9, 2023

Looks like the text in the wiki contradicts the actual behavior:

<p>This line will have a line break<br />
But not this one<br />
Because the backslash has to have a space before it</p>

A space before a backslash isn't required.

Also, I created a PR with some improvements: #544

@Crozzers
Copy link
Contributor Author

Crozzers commented Dec 9, 2023

Looks like the text in the wiki contradicts the actual behavior

Thanks for spotting this. Updated the wiki to reflect actual behaviour.

Also, I created a PR with some improvements

Very cool! Thank you

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.

Backslash at the end of a line for a newline
3 participants