Obsidian Publish - Hiding the hover preview on selected links

Hi, I am posting this here in case it helps anyone else.

I have produced some code with the help of ChatGPT to remove the hover preview from specific links when publishing with Obsidian Publish.

Add the class to the link in Obsidian either with html in source view

<a class="internal-link no-preview" href="">

or by adding the class to the markdown link:

[Link](link.md){.no-preview}

Add this Javascript to your publish.js file:

// blocks hover from selected links
(() => {
  const block = evt => {
    // ‘closest’ lets you hit <svg>, <span>, etc. inside the <a>
    const link = evt.target.closest('a.no-preview');
    if (link) {
      evt.stopImmediatePropagation();
    }
  };

  // Window-level capture fires before document-level capture
  window.addEventListener('mouseover', block, true);
  window.addEventListener('focusin',  block, true); // keyboard nav

  // Optional sanity check – remove once you see it in DevTools console
  console.log('[publish.js] selective hover-preview blocking active');
})();

Optionally remove the trigger class as well by adding:

document.addEventListener('DOMContentLoaded', () => {
  document.querySelectorAll('a.no-preview')
          .forEach(a => a.classList.remove('internal-link'));
});