Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for links in markdown #5406

Closed
wants to merge 3 commits into from
Closed

Add support for links in markdown #5406

wants to merge 3 commits into from

Conversation

pronebird
Copy link
Contributor

@pronebird pronebird commented Nov 8, 2023

This PR revamps the markdown parser which previously was limited to supporting bold text and paragraphs, but with this PR it gets extended to support links too. Our previous implementation was very simple and to support links I had to make a more formal parser.

The syntax for links looks as following:

[Mullvad VPN](https://mullvad.net/)

Typically NSAttributedString uses NSLinkAttributeName attribute to highlight links within the attributed string, however when such attribute is used with UILabel, the color of the link is impossible to change as it's somehow fixed to default blue. MarkdownStylingOptions offers a way to customize the attribute that's being used, a custom .hyperlink attribute is offered as alternative.

Standard link attribute with custom UILabel supporting touch on links:

Screenshot 2023-11-08 at 10 45 39

Custom hyperlink attribute with custom UILabel supporting touch on links:

Screenshot 2023-11-08 at 10 09 57

This change is Reviewable

Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't properly looked at the code yet, but I'm wondering if we really need a more complex parser for this. Having a more full-fledged markdown parser could come in handy, sure, but if the only use case right now is the one above can't we just use a UITextView with attributed text and call it a day?

Reviewable status: 0 of 24 files reviewed, all discussions resolved

Copy link
Contributor Author

@pronebird pronebird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you mean to use UITextView and call it a day?

Reviewable status: 0 of 24 files reviewed, all discussions resolved

Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant that by setting a link attribute (.setAttributes([.link: <some url>], range: <some range>)) on an attributed string for the link portion, and then assigning it to a UITextView, will make the link clickable by default.

Reviewable status: 0 of 24 files reviewed, all discussions resolved

@pronebird pronebird closed this Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants