Add :yank markdown
This commit is contained in:
parent
9645b2ed0d
commit
08278138c4
@ -32,6 +32,8 @@ Added
|
|||||||
dict/list setting.
|
dict/list setting.
|
||||||
- New `hints.selectors` setting which allows to configure what CSS selectors
|
- New `hints.selectors` setting which allows to configure what CSS selectors
|
||||||
are used for hints, and also allows adding custom hint groups.
|
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
|
Changed
|
||||||
~~~~~~~
|
~~~~~~~
|
||||||
|
@ -1472,6 +1472,7 @@ Yank something to the clipboard or primary selection.
|
|||||||
- `title`: The current page's title.
|
- `title`: The current page's title.
|
||||||
- `domain`: The current scheme, domain, and port number.
|
- `domain`: The current scheme, domain, and port number.
|
||||||
- `selection`: The selection under the cursor.
|
- `selection`: The selection under the cursor.
|
||||||
|
- `markdown`: Yank title and URL in markdown format.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -640,10 +640,12 @@ Default:
|
|||||||
* +pass:[xO]+: +pass:[set-cmd-text :open -b -r {url:pretty}]+
|
* +pass:[xO]+: +pass:[set-cmd-text :open -b -r {url:pretty}]+
|
||||||
* +pass:[xo]+: +pass:[set-cmd-text -s :open -b]+
|
* +pass:[xo]+: +pass:[set-cmd-text -s :open -b]+
|
||||||
* +pass:[yD]+: +pass:[yank domain -s]+
|
* +pass:[yD]+: +pass:[yank domain -s]+
|
||||||
|
* +pass:[yM]+: +pass:[yank markdown -s]+
|
||||||
* +pass:[yP]+: +pass:[yank pretty-url -s]+
|
* +pass:[yP]+: +pass:[yank pretty-url -s]+
|
||||||
* +pass:[yT]+: +pass:[yank title -s]+
|
* +pass:[yT]+: +pass:[yank title -s]+
|
||||||
* +pass:[yY]+: +pass:[yank -s]+
|
* +pass:[yY]+: +pass:[yank -s]+
|
||||||
* +pass:[yd]+: +pass:[yank domain]+
|
* +pass:[yd]+: +pass:[yank domain]+
|
||||||
|
* +pass:[ym]+: +pass:[yank markdown]+
|
||||||
* +pass:[yp]+: +pass:[yank pretty-url]+
|
* +pass:[yp]+: +pass:[yank pretty-url]+
|
||||||
* +pass:[yt]+: +pass:[yank title]+
|
* +pass:[yt]+: +pass:[yank title]+
|
||||||
* +pass:[yy]+: +pass:[yank]+
|
* +pass:[yy]+: +pass:[yank]+
|
||||||
|
@ -796,7 +796,7 @@ class CommandDispatcher:
|
|||||||
|
|
||||||
def _yank_url(self, what):
|
def _yank_url(self, what):
|
||||||
"""Helper method for yank() to get the URL to copy."""
|
"""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
|
flags = QUrl.RemovePassword
|
||||||
if what == 'pretty-url':
|
if what == 'pretty-url':
|
||||||
flags |= QUrl.DecodeReserved
|
flags |= QUrl.DecodeReserved
|
||||||
@ -816,7 +816,7 @@ class CommandDispatcher:
|
|||||||
|
|
||||||
@cmdutils.register(instance='command-dispatcher', scope='window')
|
@cmdutils.register(instance='command-dispatcher', scope='window')
|
||||||
@cmdutils.argument('what', choices=['selection', 'url', 'pretty-url',
|
@cmdutils.argument('what', choices=['selection', 'url', 'pretty-url',
|
||||||
'title', 'domain'])
|
'title', 'domain', 'markdown'])
|
||||||
def yank(self, what='url', sel=False, keep=False, quiet=False):
|
def yank(self, what='url', sel=False, keep=False, quiet=False):
|
||||||
"""Yank something to the clipboard or primary selection.
|
"""Yank something to the clipboard or primary selection.
|
||||||
|
|
||||||
@ -828,6 +828,7 @@ class CommandDispatcher:
|
|||||||
- `title`: The current page's title.
|
- `title`: The current page's title.
|
||||||
- `domain`: The current scheme, domain, and port number.
|
- `domain`: The current scheme, domain, and port number.
|
||||||
- `selection`: The selection under the cursor.
|
- `selection`: The selection under the cursor.
|
||||||
|
- `markdown`: Yank title and URL in markdown format.
|
||||||
|
|
||||||
sel: Use the primary selection instead of the clipboard.
|
sel: Use the primary selection instead of the clipboard.
|
||||||
keep: Stay in visual mode after yanking the selection.
|
keep: Stay in visual mode after yanking the selection.
|
||||||
@ -853,6 +854,12 @@ class CommandDispatcher:
|
|||||||
caret = self._current_widget().caret
|
caret = self._current_widget().caret
|
||||||
caret.selection(callback=_selection_callback)
|
caret.selection(callback=_selection_callback)
|
||||||
return
|
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
|
else: # pragma: no cover
|
||||||
raise ValueError("Invalid value {!r} for `what'.".format(what))
|
raise ValueError("Invalid value {!r} for `what'.".format(what))
|
||||||
|
|
||||||
|
@ -2615,6 +2615,8 @@ bindings.default:
|
|||||||
yD: yank domain -s
|
yD: yank domain -s
|
||||||
yp: yank pretty-url
|
yp: yank pretty-url
|
||||||
yP: yank pretty-url -s
|
yP: yank pretty-url -s
|
||||||
|
ym: yank markdown
|
||||||
|
yM: yank markdown -s
|
||||||
pp: open -- {clipboard}
|
pp: open -- {clipboard}
|
||||||
pP: open -- {primary}
|
pP: open -- {primary}
|
||||||
Pp: open -t -- {clipboard}
|
Pp: open -t -- {clipboard}
|
||||||
|
@ -41,6 +41,13 @@ Feature: Yanking and pasting.
|
|||||||
Then the message "Yanked title to clipboard: Test title" should be shown
|
Then the message "Yanked title to clipboard: Test title" should be shown
|
||||||
And the clipboard should contain "Test title"
|
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
|
Scenario: Yanking domain to clipboard
|
||||||
When I open data/title.html
|
When I open data/title.html
|
||||||
And I run :yank domain
|
And I run :yank domain
|
||||||
|
Loading…
Reference in New Issue
Block a user