From b8c6b98823ff92a097255767131ed03d49844326 Mon Sep 17 00:00:00 2001 From: ZDDC Date: Wed, 13 May 2026 13:06:44 -0500 Subject: [PATCH] feat(browse): conversion links open in a new tab MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- browse/js/preview-markdown.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/browse/js/preview-markdown.js b/browse/js/preview-markdown.js index d32126d..a97ba13 100644 --- a/browse/js/preview-markdown.js +++ b/browse/js/preview-markdown.js @@ -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); }); }