Closed Urkman closed 2 years ago
Hi @Urkman,
You can have a look at the CommonMark spec to learn how to create hard line breaks in Markdown.
Thanks for you answer :) My Problem is, that I get the content from a backend and there we habe simple "\n" as our line breaks. So, there is no chance to convert them?
When I use the building markdown parser like this:
AttributedString(markdown: self, options: AttributedString.MarkdownParsingOptions(interpretedSyntax: .inlineOnlyPreservingWhitespace))
It is displayed fine, bat as we know, the building parser does noch display list and other stuff :(
Hi, Sorry, at the moment, that is not possible with MarkdownUI.
Might I suggest as a workaround until the library supports this, run the following regex before displaying.
I'd recommend eventually adding support for soft breaks as hard, since this is so highly demanded that it's even called out in the CommonMark spec section on soft breaks.
s/(?<! |\n)\n(?!\n|\* |\d\.)/ \n/g
how to do this
I had to manually fix my strings by doing:
str = str.replacingOccurrences(of: "\n", with: " \n")
This then renders newlines.
I had to manually fix my strings by doing:
str = str.replacingOccurrences(of: "\n", with: " \n")
This then renders newlines.
Great workaround.
replacingOccurrences(of: "\n", with: " \n", options: .regularExpression)
should be better😁
replacingOccurrences(of: "\n", with: " \n", options: .regularExpression)
Thank you for this great workaround.
For me MarkdownUI is not rendering line breaks correctly. A single line break is ignored and the text is displayed in one line. Double line breaks are looking fine.
How can I handle this?