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 markdown links. #835

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

skilldeliver
Copy link

This PR introduces markdown link detection and rendering. To achieve this, the regex has been updated, and an additional property, link, has been added to the tokens. If it's a URL, the URL remains the same, with the actual text rendered. However, for markdown, we aim to have a named link where the text differs from the link.

Screenshot examples:

Here is the raw text content
image

Here is the rendered
image

Special thanks to Darius for recognizing the need for named links.

@georgegevoian georgegevoian self-requested a review January 31, 2024 16:31
Copy link
Contributor

@georgegevoian georgegevoian left a comment

Choose a reason for hiding this comment

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

Thanks for opening the PR @skilldeliver.

Would you be up for adding some unit tests to test/client/lib/textUtils.ts?

// Match http or https then domain name (with optional port) then any text that ends with letter or number.
export const urlRegex = /(https?:\/\/[A-Za-z\d][A-Za-z\d-.]*(?!\.)(?::\d+)?(?:\/[^\s]*)?[\w\d/])/;
// Match http or https then domain name and capture markdown link text and URL separately
const urlRegex = /(?:\[(.*?)\]\()?https?:\/\/[A-Za-z\d][A-Za-z\d-.]*\.[A-Za-z]{2,}(?::\d+)?(?:\/[^\s)]*)?(?:\))?/;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would match strings like [Google](https://www.google.com or https://www.google.com).

Copy link
Author

Choose a reason for hiding this comment

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

You are right @georgegevoian - the regex needs fix;
I will take a look how can I add tests.

Btw one of the CI tests of nbrowser is failing and I can't understand why.

Copy link
Contributor

Choose a reason for hiding this comment

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

DetailView does not opens cell for editing when clicked on link looks to be failing because a localhost URL isn't being treated as a link (most likely a regression in the regex).

The other failures look unrelated - we'll be landing a fix on main soon.

Thanks.

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.

None yet

2 participants