sampsyo / autolink.vim

automatically search for & insert URL targets for links in Markdown & ReST
http://www.vim.org/scripts/script.php?script_id=4023
11 stars 4 forks source link

Link auto-complete always results in None #5

Open justinmayer opened 5 years ago

justinmayer commented 5 years ago

Hey Adrian! I just came across AutoLink, and being a big fan of Beets, I immediately needed to try it out. 😁

When I type the following, move the cursor to the last line, and tap <leader>ac

[Beets][beets music]

[beets music]:

… the returned URL is None (and it's always None, for any search terms):

[Beets][beets music]

[beets music]: None

I opened a Python REPL and tested the underlying get_link function to retrieve the result for the "beets music" search terms, and the resulting html variable seems to contain the expected search result:

[...]
            <div class="result results_links results_links_deep web-result ">

          <div class="links_main links_deep result__body"> <!-- This is the visible part -->

          <h2 class="result__title">

            <a rel="nofollow" class="result__a" href="/l/?kh=-1&amp;uddg=http%3A%2F%2Fbeets.io%2F"><b>beets</b>: the <b>music</b> geek&#x27;s media organizer</a>

          </h2>
[...]

Perhaps the markup has changed, and the regex needs to be updated? What do you think?

sampsyo commented 5 years ago

Hey; thanks for checking this out! The DDG markup has indeed changed. When I looked into this before, I actually thought it was a lost cause—that the URLs were no longer available obviously in the HTML.

But it looks like there might be a way to do it by getting that href attribute and decoding the URL parameters. Cool! Any interest in giving that a shot?