CommonMark
CommonMark copied to clipboard
Add NSAttributedString render format
Hey @mattt!
What do you think about adding support for NSAttributedString
?
I have another project that does just that: https://github.com/mattt/commonmarkattributedstring.
I have another project that does just that: https://github.com/mattt/commonmarkattributedstring.
It looks great, but there's no way to style CommonMark elements separately in one string, e.g.
var attributes = CommonMark.Attributes()
attributes.body = [
.font: NSFont.systemFont(ofSize: NSFont.systemFontSize),
.foregroundColor: NSColor.textColor,
.backgroundColor: NSColor.textBackgroundColor,
]
attributes.h1 = [
.font: NSFont.systemFont(ofSize: NSFont.systemFontSize),
.foregroundColor: NSColor.textColor,
.backgroundColor: NSColor.textBackgroundColor,
]
let attributedString = try NSAttributedString(commonmark: commonmark, attributes: attributes)
@larryonoff There's no API for it (yet), but it would be pretty straightforward to customize how things render by modifying this file in a fork: https://github.com/mattt/CommonMarkAttributedString/blob/master/Sources/CommonMarkAttributedString/CommonMark%2BExtensions.swift
Alternatively, you could use the visitor API to build up an attributed string block by block.