-
Notifications
You must be signed in to change notification settings - Fork 436
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 break-on-newline option #130
Conversation
This changeset adds the option for "break-on-newline" which adds a <br /> tag on each newline inside a paragraph. This makes the library behave more like [GitHubs markdown](http://github.github.com/github-flavored-markdown/).
I would very much against this PR. Many people want to use Markdown for writing in their Moreover, this project has been very much (AFAIUI) about doing the “standard” compliant implementation. Well, this isn’t. |
This is an option (which isn't enabled by default) and you can enable it if you find it advantageous. For example if your users are also GitHub users, they might expect this way of working. I also simplifies the case when the user doesn't know what markdown is and pastes a chunk of code into a (markdown) editor - having this option ensures that at least the linebreaks are preserved as opposed to everything being put on one line. |
if "break-on-newline" in self.extras: | ||
text = re.sub(r" *\n", "<br%s\n" % self.empty_element_suffix, text) | ||
else: | ||
text = re.sub(r" {2,}\n", " <br%s\n" % self.empty_element_suffix, text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of repeating the entire sub, could we just switch out the pattern? For example:
if "break-on-newline" in self.extras:
_break_re = r" *\n"
else:
_break_re = r" {2,}\n"
text = re.sub(_break_re, " <br%s\n" % self.empty_element_suffix, text)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, simplified it.
@cdman I cherry picked the initial commit into master. You were correct in your original patch, as the break tags needed the preceding space toggled. Thanks! |
This changeset adds the option for "break-on-newline" which adds a
tag on each newline inside a paragraph. This makes the library behave more like GitHubs markdown.