Add :yank markdown

This commit is contained in:
Florian Bruhin 2018-11-03 07:54:37 +01:00
parent 9645b2ed0d
commit 08278138c4
6 changed files with 23 additions and 2 deletions

View File

@ -32,6 +32,8 @@ Added
dict/list setting.
- New `hints.selectors` setting which allows to configure what CSS selectors
are used for hints, and also allows adding custom hint groups.
- New `:yank markdown` feature which yanks the current URL and title in
markdown format.
Changed
~~~~~~~

View File

@ -1472,6 +1472,7 @@ Yank something to the clipboard or primary selection.
- `title`: The current page's title.
- `domain`: The current scheme, domain, and port number.
- `selection`: The selection under the cursor.
- `markdown`: Yank title and URL in markdown format.

View File

@ -640,10 +640,12 @@ Default:
* +pass:[xO]+: +pass:[set-cmd-text :open -b -r {url:pretty}]+
* +pass:[xo]+: +pass:[set-cmd-text -s :open -b]+
* +pass:[yD]+: +pass:[yank domain -s]+
* +pass:[yM]+: +pass:[yank markdown -s]+
* +pass:[yP]+: +pass:[yank pretty-url -s]+
* +pass:[yT]+: +pass:[yank title -s]+
* +pass:[yY]+: +pass:[yank -s]+
* +pass:[yd]+: +pass:[yank domain]+
* +pass:[ym]+: +pass:[yank markdown]+
* +pass:[yp]+: +pass:[yank pretty-url]+
* +pass:[yt]+: +pass:[yank title]+
* +pass:[yy]+: +pass:[yank]+

View File

@ -796,7 +796,7 @@ class CommandDispatcher:
def _yank_url(self, what):
"""Helper method for yank() to get the URL to copy."""
assert what in ['url', 'pretty-url'], what
assert what in ['url', 'pretty-url', 'markdown'], what
flags = QUrl.RemovePassword
if what == 'pretty-url':
flags |= QUrl.DecodeReserved
@ -816,7 +816,7 @@ class CommandDispatcher:
@cmdutils.register(instance='command-dispatcher', scope='window')
@cmdutils.argument('what', choices=['selection', 'url', 'pretty-url',
'title', 'domain'])
'title', 'domain', 'markdown'])
def yank(self, what='url', sel=False, keep=False, quiet=False):
"""Yank something to the clipboard or primary selection.
@ -828,6 +828,7 @@ class CommandDispatcher:
- `title`: The current page's title.
- `domain`: The current scheme, domain, and port number.
- `selection`: The selection under the cursor.
- `markdown`: Yank title and URL in markdown format.
sel: Use the primary selection instead of the clipboard.
keep: Stay in visual mode after yanking the selection.
@ -853,6 +854,12 @@ class CommandDispatcher:
caret = self._current_widget().caret
caret.selection(callback=_selection_callback)
return
elif what == 'markdown':
idx = self._current_index()
title = self._tabbed_browser.widget.page_title(idx)
url = self._yank_url(what)
s = '[{}]({})'.format(title, url)
what = 'markdown URL' # For printing
else: # pragma: no cover
raise ValueError("Invalid value {!r} for `what'.".format(what))

View File

@ -2615,6 +2615,8 @@ bindings.default:
yD: yank domain -s
yp: yank pretty-url
yP: yank pretty-url -s
ym: yank markdown
yM: yank markdown -s
pp: open -- {clipboard}
pP: open -- {primary}
Pp: open -t -- {clipboard}

View File

@ -41,6 +41,13 @@ Feature: Yanking and pasting.
Then the message "Yanked title to clipboard: Test title" should be shown
And the clipboard should contain "Test title"
Scenario: Yanking markdown URL to clipboard
When I open data/title.html
And I wait for regex "Changing title for idx \d to 'Test title'" in the log
And I run :yank markdown
Then the message "Yanked markdown URL to clipboard: *" should be shown
And the clipboard should contain "[Test title](http://localhost:(port)/data/title.html)"
Scenario: Yanking domain to clipboard
When I open data/title.html
And I run :yank domain