sindresorhus/refined-github

Transform text to Markdown links by pasting #4310

kidonng posted onGitHub

<!-- 1. Make sure your requested feature makes sense for Refined GitHub: https://github.com/sindresorhus/refined-github/issues/2960 2. Include a REAL URL where the feature should appear. e.g. Do you want a feature to appear on the main page of a repo? Paste a link to a repo -->

I did a brief searching and didn't find this request, so here I am.

Many text editors supports transforming text to Markdown links by pasting, for example, if I select GitHub and paste https://github.com, it becomes [GitHub](https://github.com).

This can already achieved by pressing <kbd>ctrl</kbd>/<kbd>cmd</kbd> + <kbd>k</kbd> then pasting, but it can be a nice addition to one-key-formatting (or its own feature).


Not a bad idea, GitHub already seems to do it in a few cases, for example when you copy an image from internet and paste it, it will automatically generate the right markdown code.

The problem for us is that to do this we need access to the clipboard, which means adding an extra "This extension will be able to read your clipboard" permission, which is pretty scary.

posted by fregante almost 4 years ago

The problem for us is that to do this we need access to the clipboard, which means adding an extra "This extension will be able to read your clipboard" permission, which is pretty scary.

I see some applications (for example Notion) achieves this without asking for clipboard permission. Is this because they have control of the text field or some magic? Are browser extensions limited to use those methods?

posted by kidonng almost 4 years ago

Are browser extensions limited to use those methods?

We had some limitations that required us to use clipboardWrite at some point but they were lifted because we no longer have that permission. It might be worth a try, but then we still have another problem: GitHub already handles some pastes, so we need to make sure we don't override them. For example:

  1. Right-click on this image <img width="77" alt="Screen Shot" src="https://user-images.githubusercontent.com/1402241/118354855-44916300-b597-11eb-9213-df4247a0b583.png">
  2. Click "Copy image"
  3. Paste into a field, you will already get markdown
posted by fregante almost 4 years ago

I’m a bit conflicted on this one. It seems to make sense and not require a markdown parser to get this right, but also the same is achievable with a single additional key press:

+ ctrl k
  ctrl v 

The main problem is that Firefox does not support undoing programmatic changes so changing the content unnecessarily will further limit the ability to undo

posted by fregante almost 4 years ago

Rereading this thread, I think it’s not worth the many “just one problem”

posted by fregante almost 4 years ago

@KSH-code

To override the default behavior (for example to insert some different data or a transformation of the clipboard contents) an event handler must cancel the default action using event.preventDefault(), and then insert its desired data manually.

posted by fregante almost 4 years ago

Thanks for my misunderstanding to be corrected.

posted by KSH-code almost 4 years ago

Fund this Issue

$0.00
Funded

Pull requests