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

Convert URLs in cell output to clickable links #7393

Closed
tibdex opened this issue Oct 21, 2019 · 9 comments · Fixed by #8075
Closed

Convert URLs in cell output to clickable links #7393

tibdex opened this issue Oct 21, 2019 · 9 comments · Fixed by #8075
Labels
pkg:notebook status:resolved-locked tag:Feature Parity
Milestone

Comments

@tibdex
Copy link
Member

@tibdex tibdex commented Oct 21, 2019

Description

Related to #5489 (comment).

Reproduce

When an URL is in the output of a cell, today nothing special is done:

URL as plain string

Expected behavior

It would be nice to convert URLs as clickable links:

URL as link

Context

  • JupyterLab version: 1.1.4

Work around

An untasteful workaround is to use a custom URL class:

"""URL Wrapper."""

from dataclasses import dataclass


@dataclass(frozen=True)
class Url:
    """Wrapper around a URL string to provide nice display in IPython environments."""

    __url: str

    def _repr_html_(self):
        """HTML link to this URL."""
        return f'<a href="{self.__url}">{self.__url}</a>'

    def __str__(self):
        """Return the underlying string."""
        return self.__url

It has the drawback of forcing the user to do str(url) to actually get the wrapped URL as a string.

@mlucool
Copy link
Contributor

@mlucool mlucool commented Nov 19, 2019

This makes conversion from nb to lab much harder as many libraries print links.

@saulshanabrook
Copy link
Member

@saulshanabrook saulshanabrook commented Nov 25, 2019

I think the next step here would be to do some more research into how this is supported in the classic notebook and see what it would take for us to replicate it.

@saulshanabrook
Copy link
Member

@saulshanabrook saulshanabrook commented Nov 25, 2019

Thanks @jasongrout! What a lovely regex to find "URL"s :)

@jasongrout
Copy link
Contributor

@jasongrout jasongrout commented Nov 25, 2019

What a lovely regex to find "URL"s :)

Better than markdown-it's? https://github.com/markdown-it/markdown-it/blob/1ad3aec2041cd2defa7e299543cc1e42184b680d/lib/rules_inline/autolink.js

@kgryte
Copy link
Member

@kgryte kgryte commented Nov 26, 2019

@jasongrout Do you know if there was any particular reason why this was not included in core? Was there any expectation that users would rely on an extension for this behavior instead?

I suppose another workaround in the lab notebook environment might include creating an output Markdown cell, which would presumably require users to wrap existing libraries which generate links (e.g., to reports) with display calls.

@jasongrout jasongrout modified the milestones: Future, 2.0 Nov 26, 2019
@jasongrout
Copy link
Contributor

@jasongrout jasongrout commented Nov 26, 2019

I think most likely because we weren't aware of the behavior in classic Notebook :). You certainly could do it from an extension, but the question here is if we should do this in core JupyterLab.

I think the primary concerns at this point are:

  1. Is this useful? (I think you are answering the question that it is, and that libraries are relying on this?). Since it exists already in the classic notebook, that's a vote in favor, since we want to be compatible with the classic notebook. Similarly, did this cause problems? (Now would be the time to change it if it did.)
  2. How can we replicate it in a safe, secure manner? The regex the classic notebook uses looks a bit simplistic, and getting parsing of URLs right is I think is notoriously tricky. We want to take another look at making links clickable by default from a security perspective, since clicking on a link can have lots of ramifications.
  3. Just curious, do you know if other frontends like nteract or colaboratory or sagemath implement this behavior?

I'm bumping this to the 2.0 milestone so we can at least triage it next week in our dev meeting.

@blink1073 blink1073 modified the milestones: 2.0, Future Dec 19, 2019
@tibdex
Copy link
Member Author

@tibdex tibdex commented Feb 24, 2020

I've looked at other popular frontends and they do support it:

Colaboratory

Colab

You can see that they even linkify the input.

nteract

nteract

They use this regex /(https?:\/\/(?:www\.|(?!www))[^\s.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})/ for plain text.


Do you think this classic notebook behavior could be introduced back in JupyterLab in a minor version (without waiting for 2.0)?

@jasongrout
Copy link
Contributor

@jasongrout jasongrout commented Mar 23, 2020

I'll also add that xterm.js, for example, has a much more complicated regex: https://github.com/xtermjs/xterm.js/blob/fb5ff49008558f42050d4566f327cda5e578d059/addons/xterm-addon-web-links/src/WebLinksAddon.ts#L9-L27

@lock lock bot added the status:resolved-locked label Apr 25, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pkg:notebook status:resolved-locked tag:Feature Parity
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants