vimium icon indicating copy to clipboard operation
vimium copied to clipboard

Add yank (copy) markdown link of current tab

Open johanna-a opened this issue 1 year ago • 8 comments

This adds a new command, copyCurrentMarkdown, with a default keybinding ym, to copy a link to the current tab in markdown format, i.e. "title".

Description

Firstly, this has been suggested and implemented before, see PR #2054. However, that pull request was never merged. Having a way to copy a link in markdown format is implemented in other projects for keyboard-based browsing, for example qutebrowser. It is typically something a user expects to be able to do easily. It relates to issues #131 #889 #2474 #3611 #4133

johanna-a avatar Mar 30 '23 09:03 johanna-a

I'd love to see this ym PR merged! It would be a big help for my note-taking workflow.

ooloth avatar Oct 30 '23 14:10 ooloth

Could everyone who's interested in this elaborate on your use cases?

  1. Are you pasting this information into your markdown files, into Github, into social media sites?
  2. Why just Markdown? Why not HTML -- or rich text, so the link can be copied into editors like Google Docs or Slack?
  3. Do you ever want the title and not the URL? Many of the older bugs which were referenced were requesting a shortcut to copy the title of the page, not the combination of title and URL.
  4. Why is this needed for the current page only, and not for link hints? Note that there is an existing command yf (LinkHints.activateModeToCopyLinkUrl) which copies a link URL to the clipboard. Should there be a similar command to copy the link+title to the clipboard?

I'm concerned about adding a feature which is too narrow.

Note that @gdh1995 has an implementation where the format of the copied text / URL can be customized, which allows the command to cover all use cases. If we went with a similar approach, then the command should probably be called copyCurrentUrlAndTitle (even if the default formatter is Markdown), rather than copyCurrentMarkdown.

philc avatar Jan 25 '24 05:01 philc

Could everyone who's interested in this elaborate on your use cases?

  1. Pasting into markdown notes (Obsidian)
  2. Additional powers sound fun (though would be used rarely)
  3. No
  4. Copying markdown links for link hints instead of having to visit those pages first would be great

ooloth avatar Jan 27 '24 17:01 ooloth

Could everyone who's interested in this elaborate on your use cases?

1. Are you pasting this information into your markdown files, into Github, into social media sites?
2. Why just Markdown? Why not HTML -- or rich text, so the link can be copied into editors like Google Docs or Slack?

Right now I use a simple Word file for notes - so HTML would be great. But for my workflow, the clipboard needs to have the content type text/html.

3. Do you ever want the title and not the URL? Many of the older bugs which were referenced were requesting a shortcut to copy the title of the page, not the combination of title and URL.

I use the command copyCurrentTitle to create the link in Word by hand. I think I wouldn't need it, if there was a command copyCurrentInfo

4. Why is this needed for the current page only, and not for link hints? Note that there is an existing command `yf` (`LinkHints.activateModeToCopyLinkUrl`) which copies a link URL to the clipboard. Should there be a similar command to copy the link+title to the clipboard?

I need this for the current page and link hints.

PS: I know Word is terrible in every way, but for now this is the easiest solution for me.

boesi avatar Feb 01 '24 08:02 boesi

Could everyone who's interested in this elaborate on your use cases?

  1. I'm often pasting links text editors that supports Markdown syntax, and I feel that using the page title is more readable than just pasting the link.
  2. Markdown-compatible text editors are quite common: Github issues/PRs, Slack (you need to activate an option for this), Google Docs (you need to activate an option for this), JIRA. I generally feel more "in control" when using plain text as opposed to rich text.
  3. No, when I paste a page title, I always want the URL with it.
  4. Having it for link hints would be great as well!

glostis avatar Feb 01 '24 08:02 glostis

My use-case is also to paste it into Slack or rich text documents (google Docs/Sheet, confluence, etc) or markdown editors.

I think a better way would be to copy rich text (text/html) instead of the markdown as text/plain. Most markdown editors support pasting rich text links and automatically convert them into markdown links or whatever format they support.

Using native clipboard API, I can do it easily as

const data = [new ClipboardItem({
    'text/html': new Blob([`<a href="${document.location.href}">${document.title}</a>`], {type: 'text/html'}),
    'text/plain': new Blob([document.title], {type: 'text/plain'})
})]
navigator.clipboard.write(data)

Pasting this clipboard item into most markdown/rich-text editors works and they render it as they like. It further has the advantage of using Ctrl+Shift+V to paste as plain text.

80avin avatar Feb 08 '24 17:02 80avin

Use VimiumC like this:

map ye copyWindowInfo format="[[${url}][${title}]]" type="tab"

Ref: https://github.com/gdh1995/vimium-c/wiki/Substitute-URLs-and-text-during-commands#copy-information-of-tabs

Note: Change format as per your need.

zzeitt avatar Mar 23 '24 05:03 zzeitt