-
Notifications
You must be signed in to change notification settings - Fork 620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a command to extract <title> from external links #837
Comments
This might be a better fit for something in utils. |
I managed to hack something: nnoremap <Leader>u :call FormatCurrentURL()<CR>
" ...
function! FormatCurrentURL()
let l:url = expand("<cWORD>")
let l:esc_url = shellescape(l:url)
let l:useragent = shellescape('Mozilla/5.0')
let l:pycode = 'import bs4, urllib.request;'
let l:pycode .= 'req = urllib.request.Request('.l:esc_url.', headers={''User-Agent'': '.l:useragent.'});'
let l:pycode .= 'print(bs4.BeautifulSoup(urllib.request.urlopen(req)).head.title.contents[0])'
let l:cmd = 'python -c "'.l:pycode.'"'
let l:title = substitute(substitute(trim(system(l:cmd)), '[', '<', ''), ']', '>', '')
execute "normal! viW\<ESC>`>a)\<ESC>`<i[".l:title."]("
endfunction So If i have the following under my cursor:
And I press [GitHub - vimwiki/vimwiki: Personal Wiki for Vim](https://github.com/vimwiki/vimwiki) It doesn't:
But so far it's already very useful for me as I paste a lot of URLs in my wiki. |
Vimwiki is a standalone plugin. So no python dependent code will be added. As you have a custom solution, I advise you to keep it. enew
NRead https://github.com/vimwiki/vimwiki Then:
4h work: If you make a PR, it will be accepted <= useful feature. |
Hi @tinmarino I'm willing to have a look at this one. As I'm a complete beginner in vimscript, I don't see how you can get the result of When I try to do this, the content of the page gets inserted in the current buffer. I've been looking around, including in vim default autoload scripts where Do I have to use a hidden buffer or is there a better way? Cheers, |
Hi @jeromg, Thanks for the willing to implement this very nice feature, I would quote from Top Gun: 1 AnalyseAs the
" netrw#NetRead: responsible for reading a file over the net {{{2
" mode: =0 read remote file and insert before current line
" =1 read remote file and insert after current line
" =2 replace with remote file
" =3 obtain file, but leave in temporary format
fun! netrw#NetRead(mode,...) 2 SolutionsSo you have to write in a file as far as I know. To get the content in a variable you have an easy solution (quick and dirty for testing) and a harder but cleaner one (for produciton because have no side effect as moving cursor, save the buffer, modifining the undolist ...) 2.1 Dirty
dG
:let net_content = @" 2.2 Clean
and get the content of the file in a variable as this answer :let buff=join(getline(1, '$'), "\n") In your case, it will be a little harder, you'll have to load a file and use 3 Note on VimDocThe best part of vimdoc for:
Libre sourcement votre, |
If I may, here is a list of things to be aware of while working on this feature:
|
@jeromg glad to see people for different activities (project manager => CTO, in your case) using some secret deep tools like vimwiki. You are an interesting customer for being between computerists (your co-workers) and computer noobs (your clients). This leads to an obviously different use than me (working 100% in Vim) so feel free to raise some issues, potentially with screenshot of your config. |
Colorscheme Advice (Just for refernce <= not related to this issue ... )If I may: it took me 10 years to gather the motivation to invest in searching good colorscheme, now there is a vimcolor site. A nice colorscheme changes your life and may make you loyal ("fideliser") you to vim. try the gruvbox-material colorscheme or the list I forked (I added 800 more) or directly from rafi, the source of the fork From net advice and tested
From my experience
|
Hi there, quick update: I do have a working prototype that seems to work reasonably well in pure vimscript. I still need to add some error handling and also need to do some testing with vim7/8 (I developed and tested the prototype with neovim). Where shall I add the two functions needed in the vimwiki source tree for the PR? I was thinking of Cheers, |
@jeromg yes base.vim : there is no other places already. |
Fixed by #PR #982 that got integrated by hand |
A feature I miss in Vimwiki is the ability to name external links in a more meaningful way by basically remotely query the URL to extract the
<title>
.One typical use-case is that I tend to aggregate many external links into my notes. Unfortunately, many URLs have no meaning whatsoever. Pick for example Youtube, where I sometime come across a music I want to downl^Wbuy. I need to manually write
[Foobar - Blabaz](https://youtube.com/...)
. A trigger command to insert that automatically from the URL would help a lot. And if the link dies somehow, at least I have the reference.There are various oneliners available to do that, but here is mine as a PoC:
python -c 'import bs4,urllib;print(bs4.BeautifulSoup(urllib.request.urlopen("https://wikipedia.org/")).head.title.contents[0])'
Python and BeautifulSoup are generally packaged by distro, I think it's not much of a requirement as optional dependencies. Of course, some
curl
and regex magic could do as well.The text was updated successfully, but these errors were encountered: