Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Jupyter Notebook automatic hyperlink

In my notebook, I print some data from scraped web pages. Some of these are hyperlinks without tags e.g. https://stackoverflow.com. Unfortunately, Notebook prints these out as an actual hyperlink (i.e. wraps it in tags) on the output page and shortens it. (So the final result in HTML looks like this: <a href="https://stackoverflow.com">https://stacko...</a>.) The field is set to code, but this still happens. Is there a way to disable this behaviour?

like image 663
Bram Vanroy Avatar asked May 26 '17 08:05

Bram Vanroy


1 Answers

Solution:

Enter the following text in the empty cell of your Jupyter notebook:

%%javascript
Jupyter.utils.autoLinkUrls = function (txt) {
    return txt;
}

Explanation:

The ability to locate URLs in text output and convert them to hyperlinks appeared in IPython notebook (a Jupyter's predecessor) as a result of a merge request in Oct' 2012. Since then every piece of output is scanned for URLs and each found URL is replaced with an anchor <a href=.../>. There's no easy way to alter this behavior because function autoLinkUrls(...) doesn't provide any configuration parameters.

So, the only way to disable URL "autolinking" is to simply replace JavaScript function autoLinkUrls, which is exposed through global Jupyter object, and %%javascript magic command makes the job done.

like image 173
dekin Avatar answered Sep 18 '22 23:09

dekin