gonzalezreal / swift-markdown-ui

Display and customize Markdown text in SwiftUI
MIT License
2.53k stars 318 forks source link

[Feature Request] Helper functions to convert the markdown string to attributed text? #189

Closed moophis closed 1 year ago

moophis commented 1 year ago

Hi, thanks for making this excellent library that my apps heavily rely on!

Is it possible to expose helper functions that transform the raw markdown string into an NSAttributedString/ AttributedString which contains the styles used for the corresponding Markdown view?

My use case is to dump some markdown texts into a PDF file. Currently, the PDF generation library I'm using can accept NSAttributedString type to format the text content. Ideally, I'd like to keep the same UI style as if they are rendered in my app.

Thanks in advance!

gonzalezreal commented 1 year ago

Hi @moophis,

MarkdownUI renders content to a SwiftUI view. It could render an AttributedString at the cost of losing the styling and other capabilities. Additionally, it will be a daunting task to do this.

A new API on macOS 13 / iOS 16 allows rendering a SwiftUI view to a PDF, which may be helpful for your use case. See this post for more info: https://www.hackingwithswift.com/quick-start/swiftui/how-to-render-a-swiftui-view-to-a-pdf.

If you have further feature requests or questions, please use the discussions, so that others can participate and have visibility. Issues should be used exclusively for reporting bugs. Thanks for understanding 🙂.

aehlke commented 11 months ago

If anyone found a good practical solution to this that'd be great - I can use another lib but then the rendering decisions might be different