mirror of
https://github.com/xoofx/markdig.git
synced 2026-02-15 14:05:39 +00:00
How to preserve empty lines? #594
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Jinjinov on GitHub (Mar 3, 2023).
Would it be possible to preserve empty lines?
Using
UseSoftlineBreakAsHardlineBreak()preserves new lines, but not empty lines.I tried using
text.Replace("\n", "<br>")but then titles and lists don't work.I tried using
text.Replace("\n", "<br>\n")then titles and lists work, but there are too many empty lines.I tried using
text.Replace("\n\n", "<br><br>")but then all markdown after a list is wrong.I tried using
text.Replace("\n\n", "<br>\n")then titles and lists work, but not all empty lines are preserved.I tried using
text.Replace("\n\n", "<br><br>\n")then titles and lists work, but everything else is wrong.Would it be possible to specify my own rule for this?
@xoofx commented on GitHub (Mar 3, 2023):
Probably duplicate of #698.
The CommonMark specs are treating empty lines in a specific way (e.g they are used to stop processing list..etc.) and they have many associated rules with them.
Changing this behavior (even with an opt-in switch) is not something I would like to maintain, and I'm not even sure it is practical, feasible without conflicting with existing rules. As you realized yourself, empty lines have a context dependent behavior.
So my main advice would be to not pursue this road 🙂
@Jinjinov commented on GitHub (Mar 3, 2023):
I understand that this is not compliant with CommonMark and would make no sense in implementing it in Markdig.
I am writing a note editor with these specifications:
<a href>I decided to use Markdig, because it covers 1. and 3. but the most important features are detecting links in simple text and preserving empty lines.
Can you give me a few starting points how could I write a custom Markdig extension that would preserve empty lines?
@Jinjinov commented on GitHub (Mar 3, 2023):
This is what ChatGPT wrote, but it doesn't work:
@xoofx commented on GitHub (Mar 3, 2023):
This more likely not trivial and unlikely possible by extending Markdig. You would have to fork it and modify its internals.
@Jinjinov commented on GitHub (Mar 3, 2023):
Thank you for your explanations.