Update app.js
This commit is contained in:
@@ -284,15 +284,15 @@ function ansiToHtml(text) {
|
||||
}
|
||||
out += s.slice(last);
|
||||
if (spans > 0) out += '</span>'.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)
|
||||
? `<button class="media-toggle" data-url="${url}" data-type="${isImg?'img':'vid'}" title="Show/hide media">▶</button>`
|
||||
// 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)
|
||||
? ` <button class="media-toggle" data-url="${href}" data-type="${isImg?'img':'vid'}" title="Show/hide">▶</button>`
|
||||
: '';
|
||||
return `<a href="${url}" target="_blank" rel="noopener noreferrer">${url}</a>${preview}`;
|
||||
return `<a href="${href}" target="_blank" rel="noopener noreferrer">${url}</a>${btn}`;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user