Last active
March 13, 2019 04:32
-
-
Save KainokiKaede/fb8ccbcfcb0680df25e9 to your computer and use it in GitHub Desktop.
Create Markdown hyperlink automatically. Usage: type ``:MDURL`` over a URL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Create Markdown Hyperlink Automatically | |
" Requires mattn/webapi-vim (or vital.vim), tpope/vim-surround, | |
" kana/vim-textobj-user, mattn/vim-textobj-url | |
command MDURL call CreateMarkdownHyperLink() | |
command MDURLTitle call CreateMarkdownHyperLinkWithTitle() | |
function! GetWebPageTitle(url) | |
let res = webapi#http#get(a:url) | |
let dom = webapi#html#parse(res.content) | |
return dom.childNode('head').childNode('title').value() | |
endfunction | |
function! CreateMarkdownHyperLinkWithTitle() | |
let areg = @a | |
execute 'normal "ayiu' | |
let url = @a | |
let title = GetWebPageTitle(url) | |
execute 'normal viuS)i['.title.']' | |
let @a = areg | |
endfunction | |
function! CreateMarkdownHyperLink() | |
execute 'normal viuS)i[]' | |
startinsert | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ブログの方でもコメントしましたが、こちらにも書かさせて頂きます。
使わさせて頂き加筆が楽になりました。ありがとうございます。
https://gist.github.com/nora75/bd3c5a58488baf1ba077efe88a06cdfa