diff --git a/app.js b/app.js index a7e2bea..ef0a5b3 100644 --- a/app.js +++ b/app.js @@ -284,15 +284,15 @@ function ansiToHtml(text) { } out += s.slice(last); if (spans > 0) out += ''.repeat(spans); - // Linkify — detect images/video for inline preview toggle - return out.replace(/(https?:\/\/[^\s<>"&]+)/g, (url) => { - const clean = url.replace(/&/g,'&'); - const isImg = /\.(png|jpe?g|gif|webp|svg|bmp)(\?.*)?$/i.test(clean); - const isVid = /\.(mp4|webm|ogv|mov)(\?.*)?$/i.test(clean); - const preview = (isImg || isVid) - ? `` + // Linkify URLs; match through & so query strings aren't cut short + return out.replace(/https?:\/\/(?:[^\s<>"\']|&)+/g, (url) => { + const href = url.replace(/&/g, '&'); + const isImg = /\.(png|jpe?g|gif|webp|svg|bmp)(\?.*)?$/i.test(href); + const isVid = /\.(mp4|webm|ogv|mov)(\?.*)?$/i.test(href); + const btn = (isImg || isVid) + ? ` ` : ''; - return `${url}${preview}`; + return `${url}${btn}`; }); }