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

Support for custom link handler in Markdown Cell and Webviews #98100

Closed
DonJayamanne opened this issue May 18, 2020 · 10 comments
Closed

Support for custom link handler in Markdown Cell and Webviews #98100

DonJayamanne opened this issue May 18, 2020 · 10 comments
Assignees
Labels
feature-request Request for new features or functionality notebook verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@DonJayamanne
Copy link
Contributor

DonJayamanne commented May 18, 2020

  • VSCode Version:
  • OS Version:

1. Add support to handle Notebook output link clicks in extension code
2. Add support to handle Notebook Markdown cell link clicks in extension code.

  • Currently we (Python Extension) displays custom links in the webviews (our notebook implementation).
    • We do this in the Markdown of a cell
    • We do this in output of a cell.
  • We handle these clicks by monitoring the click event of the document.
  • Any link clicked that has an href starting with vscode is handled by our code in webview and then passed onto the extension.

With the new VS Code notebooks, we'll need to do the same to handle links displayed in the output. I can see two solutions (for outputs):

  • Use our own renderer when rendering HTML & and highjack all clicks to handle our custom links (not preferred, as I'd prefer to use VS Code renderers as much as possible).
  • Add links in HTML using href=javascript:acquireVsCodeAPI().postMessage(....).

However, we won't be able to handle click events in markdown

  • At least not with the above approach
  • Open to alternatives

Had a chat with @rebornix and it was suggested that VSCode could provide a custom API that works in Markdown + Output rendered in WebViews as well as Notebooks

@DonJayamanne DonJayamanne changed the title Support for custom links in Notebooks & webviews Support for custom links in HTML and Markdown of Notebooks & Webviews May 18, 2020
@kieferrm
Copy link
Member

@DonJayamanne what is the use case for this. How would another notebook tool handle these notebook files?

@DonJayamanne
Copy link
Contributor Author

DonJayamanne commented May 20, 2020

This wouldn't work across another notebook tool.
We were planning on are adding these cells or output temporarily when displaying nb in VS Code (when saving to disc that cell wouldn't be persisted).
Our goal was to use Markdown to render some content and have the same look and feel as VSCode markdown renderer, & have ability to include links that can trigger some code in the extension.

E.g. we add a cell with markdown (containing) instructions for user with links in the cell (clicking that triggers extension code).
Similarly when output text > certain limit), we truncate it and add a message with a link allowing user to change the value.

@rebornix rebornix added the feature-request Request for new features or functionality label May 25, 2020
@rebornix rebornix added this to the May 2020 milestone May 25, 2020
@rebornix rebornix changed the title Support for custom links in HTML and Markdown of Notebooks & Webviews Support for custom link handler in Markdown Cell and Webviews May 25, 2020
@roblourens
Copy link
Member

Is this solved by supporting command: type links that will invoke a command when clicked? Or do you need to intercept the user's click on an arbitrary link like http://microsoft.com?

@roblourens
Copy link
Member

And changing the URLs to that type of link is a vscode-specific solution, is that a problem?

@DonJayamanne
Copy link
Contributor Author

Is this solved by supporting command: type links that will invoke a command when clicked?

Yes that would work.

And changing the URLs to that type of link is a vscode-specific solution, is that a problem?

No, that would work.

Today we handle all link click handlers and if the link starts with http://command, then we execute the command (provided its a link we generated - by looking at a white list).

@roblourens
Copy link
Member

Ok, in markdown cells it will work in tomorrow's build. I'll have to think about it for output.

@rebornix rebornix modified the milestones: May 2020, June 2020 May 29, 2020
@rebornix
Copy link
Member

Moving this to June and we still need to discuss what's the right solution for this problem. Command links work well in VS Code but they are not platform agnostic.

@rebornix
Copy link
Member

@DonJayamanne we discussed this offline and command links are good as Python extension is already pre-processing the data, following links will work

  • [link](command:COMMANDID) in markdown cell
  • <a href="command:COMMANDID"></a> in outputs

We can continue discussion if we find the solution not feasible.

@roblourens
Copy link
Member

These don't actually work in outputs currently though, I need to hook that up.

@roblourens roblourens reopened this Jun 16, 2020
rebornix added a commit that referenced this issue Jun 25, 2020
@rebornix
Copy link
Member

I tested command: links are working fine in outputs in webview and pushed a change to text/markdown static output to support it as well.

@rebornix rebornix added the verification-needed Verification of issue is requested label Jul 1, 2020
@connor4312 connor4312 added the verified Verification succeeded label Jul 1, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Aug 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality notebook verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

5 participants