AttributedString Markdown initializer with custom styling
- There is no styling (not even bold or italic) when drawing the
AttributedStringin a custom view.
AttributedStringdoes have some styling applied when it’s assigned to a
UILabelor to a
UITextView, but they are noticeably different and weird things happen with the font sizes.
- All line breaks that should separate the content blocks are missing.
AttributedStringcolors don’t react to toggling between dark and light mode.
What’s going on?
There is not a lot of information about Markdown in
AttributedString out there yet, but I think I was just holding it wrong:
The Markdown initializer merely adds semantic (not visual) markup to the
UITextView interpret these to a certain extent, while drawing a raw
The Markdown initializer merely puts the Markdown parsing results as Presentation Intents into the
- There are
.stronglyEmphasizedfor bold text.
- There are
presentationIntents for blocks like headlines (like
This sample project
This sample project shows how you can find these intents and replace them with actual
AttributedString styling information like font weights and foreground colors.
I don’t know if there’s a more elegant way to solve this.
Do let me know if you have a better solution!
© 2021 Frank Rausch