Given the markdown string "**Line 1**\n\nLine 2" I expect an output of
Line 1
Line 2
Instead I get
Line 1Line 2
Surely this isn't a limitation of markdown or AttributedString. What am I missing?! How do I specify multiple paragraphs if not with two blank lines?
struct DemoView_Previews: PreviewProvider {
static var previews: some View {
Text(try! AttributedString(markdown: "**Line 1**\n\nLine 2"))
}
}
As discovered via the Apple Developer forums,
.inlineOnlyPreservingWhitespaceis needed:And, of course, for those that may come along this answer later, it's worth mentioning that if you don't need to use
AttributedStringdirectly or aren't passing a variable toText, you can use the string literal with markdown directly: