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:
parent
95c6feed16
commit
b8c6b98823
1 changed files with 14 additions and 5 deletions
|
|
@ -456,12 +456,21 @@
|
||||||
var a = document.createElement('a');
|
var a = document.createElement('a');
|
||||||
a.className = 'btn btn-sm btn-secondary md-shell__download';
|
a.className = 'btn btn-sm btn-secondary md-shell__download';
|
||||||
a.href = node.url + '?convert=' + encodeURIComponent(fmt);
|
a.href = node.url + '?convert=' + encodeURIComponent(fmt);
|
||||||
a.download = node.name.replace(/\.md$/i, '') + '.' + fmt;
|
// target=_blank: clicks open in a new tab. The server
|
||||||
a.textContent = fmt.toUpperCase();
|
// sends Content-Disposition: inline, so the new tab
|
||||||
a.title = 'Download as ' + fmt.toUpperCase()
|
// either renders (HTML → web page; PDF → browser's
|
||||||
+ ' (right-click to copy link or open in new tab)';
|
// PDF viewer) or auto-downloads (DOCX, since browsers
|
||||||
a.dataset.fmt = fmt;
|
// 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.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);
|
convertBtns.push(a);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue