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

Issues/23 clickable links #26

Merged
merged 5 commits into from
Jun 9, 2022
Merged

Issues/23 clickable links #26

merged 5 commits into from
Jun 9, 2022

Conversation

paolosimone
Copy link
Owner

@paolosimone paolosimone commented May 29, 2022

Automatically detect URLs in text and make them clickable

  • Include a library to detect URLs
  • Render URLs as html links and handle overlapping with <mark> tags from search query
  • Add a setting flag to opt-out from this feature
  • Add basic auto-update mechanism for stored settings

URL detection

After a quick google search it was obvious that this is not a simple task and I should rely on battle-tested external libraries.

The top 3 npm packages in this regard are:

Autolinker

By far the most used and still maintained, but it has a size footprint of 2MB. Now the whole Virtual Json Viewer plugin, including the compiled JQ binary is 2.3MB. While it's true that the size is not a concern for browser plugin I didn't feel like doubling it just to linkify some urls.

Linkify

Second from the top and reasonable size. I gave it a try, but wasn't satisfied by the results both missing (e.g. no ipv6 links) and spurious (e.g. _localhost).

Anchorme <- the winner!

The underdog (just like my plugin!). It claims to be extremely fast, it's small and worked well on all input test cases. Even though it seems abandoned I still decided to use it and confine it to an easy-to modify class if the need will ever arise.

Merge search with links

Since both search and links "cut" the text independently, their results must be merged and the tags must be rebalanced.
e.g. ab(cd)e + a[bc]de = a[b(c)](d)e

image

@paolosimone paolosimone merged commit 6f700ed into main Jun 9, 2022
@paolosimone paolosimone deleted the issues/23-clickable-links branch June 9, 2022 06:20
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.

Feature request: Make links clickable by pressing Alt/Option + click
1 participant