feat(browse): conversion links open in a new tab

Drops the `download` attribute and adds `target="_blank"`. Click now
opens the conversion URL in a new tab; the server's
Content-Disposition: inline routes each format to a sensible
behavior in that tab:

  • HTML → renders as a web page
  • PDF  → opens in the browser's PDF viewer
  • DOCX → auto-downloads (browser can't render Office Open XML),
           tab is transient

Right-click → "Save Link As" still works for explicit save-to-disk.

Side benefit for debugging: when the conversion endpoint returns
422 or 503, the response body appears as a plain-text page in the
new tab, which is easier to triage than a transient toast.
This commit is contained in:
ZDDC 2026-05-13 13:06:44 -05:00
parent 95c6feed16
commit b8c6b98823

View file

@ -456,12 +456,21 @@
var a = document.createElement('a');
a.className = 'btn btn-sm btn-secondary md-shell__download';
a.href = node.url + '?convert=' + encodeURIComponent(fmt);
a.download = node.name.replace(/\.md$/i, '') + '.' + fmt;
a.textContent = fmt.toUpperCase();
a.title = 'Download as ' + fmt.toUpperCase()
+ ' (right-click to copy link or open in new tab)';
a.dataset.fmt = fmt;
// target=_blank: clicks open in a new tab. The server
// sends Content-Disposition: inline, so the new tab
// either renders (HTML → web page; PDF → browser's
// PDF viewer) or auto-downloads (DOCX, since browsers
// can't render Office Open XML). Right-click "Save
// Link As" still gives a download-to-disk path for
// any format. Errors from the server (422, 503, …)
// appear as a plain-text page in the new tab, which
// is more diagnostic than a transient toast.
a.target = '_blank';
a.rel = 'noopener';
a.textContent = fmt.toUpperCase();
a.title = 'Open ' + fmt.toUpperCase()
+ ' in a new tab (right-click for Save Link As / Copy Link)';
a.dataset.fmt = fmt;
convertBtns.push(a);
});
}