Haring
Haring copied to clipboard
Link/Code text colour doesn't work
Setting the colour attribute for Link/Code doesn't work:
To recreate just add the following code to example project in Exemple2ViewController
:
markdownParser.link.color = UIColor.red
markdownParser.code.color = UIColor.red
Yes, I confirm the bug. link colors and font just won't work.
markdownParser is returning an NSAttributedString. Colors for link will depend on the UI element: UILabel
, UITextView
and NSTextView
all behave differently.
See what I wrote in this other project: https://github.com/laptobbe/TSMarkdownParser/blob/3.x/TSMarkdownParser/TSMarkupParser.h:
/**
* markupParser setting for NSLinkAttributeName
*
* When YES, references to URL are lost and you have freedom to customize the appearance of text.
*
* When NO, reference to URL are kept with NSLinkAttributeName and restrictions to customize the appearance of links apply:
*
* * UILabel is forcing all links to be displayed blue and underline, links aren't clickable
*
* * UITextView's tintColor property is controlling all links color, links are clickable
*
* * NSTextView's linkTextAttributes property is controlling all links attributes
*
* If you want clickable links with an UILabel subclass, you should leave skipLinkAttribute to NO and consider using KILabel, TTTAttributedLabel, FRHyperLabel, ... As a bonus, all will lift off the UILabel appearance restrictions for links.
*/
@property (nonatomic, assign) BOOL skipLinkAttribute;
So, you need:
- to specify if you need your link to be clickable or not
- to specify what is the UI container that you use
And only then I may be able to help.
@swaterfall the example that you've pinpointed at is using UITextView
. So you got the choices:
a. UITextView's tintColor property is controlling all links color, links are clickable.
b. You remove NSLinkAttributeName, and you can get a mix of colors, but links are no more clickable.
c. You subclass UITextView
and you add your own magic (you'll need your own UIGestureRecognizer) to make links both clickable and with different colors. It's complex, but you may get a partial idea from the second part of this answer: https://stackoverflow.com/a/49443814/1033581
@Coeur in my case, the markdown was applied to a UILabel. Links remains blue. In my particular case, I don't need a clicable link.
I cannot find any equivalent of TSMarkdownParser.skipLinkAttribute
in Haring.
Beyond of this, what is the point about restricting the style of a link? I mean : if I explicitely set parser.link.color
, why to prevent the expected behaviour?
Thanks.