vimium
vimium copied to clipboard
Add yank (copy) markdown link of current tab
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
I'd love to see this ym
PR merged! It would be a big help for my note-taking workflow.
Could everyone who's interested in this elaborate on your use cases?
- Are you pasting this information into your markdown files, into Github, into social media sites?
- Why just Markdown? Why not HTML -- or rich text, so the link can be copied into editors like Google Docs or Slack?
- 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.
- 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
.
Could everyone who's interested in this elaborate on your use cases?
- Pasting into markdown notes (Obsidian)
- Additional powers sound fun (though would be used rarely)
- No
- Copying markdown links for link hints instead of having to visit those pages first would be great
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.
Could everyone who's interested in this elaborate on your use cases?
- 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.
- 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.
- No, when I paste a page title, I always want the URL with it.
- Having it for link hints would be great as well!
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.
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.