Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.

Add NSAttributedString render format #33

Open
larryonoff opened this issue Jul 29, 2021 · 3 comments
Open

Add NSAttributedString render format #33

larryonoff opened this issue Jul 29, 2021 · 3 comments

Comments

@larryonoff
Copy link

Hey @mattt!

What do you think about adding support for NSAttributedString?

@mattt
Copy link
Contributor

mattt commented Jul 29, 2021

I have another project that does just that: https://github.com/mattt/commonmarkattributedstring.

@larryonoff
Copy link
Author

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)

@mattt
Copy link
Contributor

mattt commented Jul 29, 2021

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants