Hi I am unable to override the default link color for links when I use markdown. Here is my code
func markdown(textElement: TextElement) -> AttributedString {
var attributedString = try! AttributedString(markdown: textElement.content)
for run in attributedString.runs {
if run.attributes[AttributeScopes.FoundationAttributes.LinkAttribute.self] != nil {
let linkColor: NSColor = .red
let linkAttributes: [NSAttributedString.Key: Any] = [
.foregroundColor: linkColor,
]
let attributeContainer = AttributeContainer(linkAttributes)
attributedString[run.range].mergeAttributes(attributeContainer, mergePolicy: .keepNew)
}
}
return attributedString
}
When I put this attributed string into the following Text View and render it
Text(markdown(textElement: textElement))
.foregroundColor(textElement.fill)
.tint(.black)
Markdown links still come out in the default blue. I've tried a bunch of different things and the closest I've gotten is using replaceAttributes instead of mergeAttributes but that destroys the link.
Please let me know how I'm supposed to do this. This is critical functionality in my app