1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-02-01 19:15:01 +02:00

Electron: Fixes #933: Handle internal links from HTML and from MD

This commit is contained in:
Laurent Cozic 2018-11-16 18:39:11 +00:00
parent a3d64d0a90
commit 71d9b1d441

View File

@ -276,24 +276,32 @@
}
});
function handleInternalLink(event, anchorNode) {
const href = anchorNode.getAttribute('href');
if (href.indexOf('#') === 0) {
event.preventDefault();
location.hash = href;
return true;
}
return false;
}
document.addEventListener('click', function(event) {
const t = event.target;
// Prevent URLs added via <a> tags from being opened within the application itself
// otherwise it would open the whole website within the WebView.
if (t && t.nodeName === 'A' && !t.hasAttribute('data-from-md')) {
if (handleInternalLink(event, t)) return;
event.preventDefault();
ipcProxySendToHost(t.getAttribute('href'));
return;
}
// IF this is an internal link, jump to the anchor directly
// If this is an internal link, jump to the anchor directly
if (t && t.nodeName === 'A' && t.hasAttribute('data-from-md')) {
const href = t.getAttribute('href');
if (href.indexOf('#') === 0) {
event.preventDefault();
location.hash = href;
return;
}
if (handleInternalLink(event, t)) return;
}
});