mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Better handling of message images
This commit is contained in:
@ -869,9 +869,6 @@ function messageFormating(mes, ch_name, isSystem, forceAvatar) {
|
|||||||
.replace(/\*\*(.+?)\*\*/g, "<b>$1</b>")
|
.replace(/\*\*(.+?)\*\*/g, "<b>$1</b>")
|
||||||
.replace(/\n/g, "<br/>");
|
.replace(/\n/g, "<br/>");
|
||||||
} else if (!isSystem) {
|
} else if (!isSystem) {
|
||||||
const image = /<img src="(.*?)".*?alt="(.*?)".*?>/g;
|
|
||||||
mes = mes.replace(image, '');
|
|
||||||
|
|
||||||
mes = converter.makeHtml(mes);
|
mes = converter.makeHtml(mes);
|
||||||
//mes = mes.replace(/{.*}/g, "");
|
//mes = mes.replace(/{.*}/g, "");
|
||||||
mes = mes.replace(/{{(\*?.+?\*?)}}/g, "");
|
mes = mes.replace(/{{(\*?.+?\*?)}}/g, "");
|
||||||
@ -2205,6 +2202,9 @@ function saveReply(type, getMessage, this_mes_is_name) {
|
|||||||
type = 'normal';
|
type = 'normal';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const img = extractImageFromMessage(getMessage);
|
||||||
|
getMessage = img.getMessage;
|
||||||
|
|
||||||
if (type === 'swipe') {
|
if (type === 'swipe') {
|
||||||
chat[chat.length - 1]['swipes'][chat[chat.length - 1]['swipes'].length] = getMessage;
|
chat[chat.length - 1]['swipes'][chat[chat.length - 1]['swipes'].length] = getMessage;
|
||||||
if (chat[chat.length - 1]['swipe_id'] === chat[chat.length - 1]['swipes'].length - 1) {
|
if (chat[chat.length - 1]['swipe_id'] === chat[chat.length - 1]['swipes'].length - 1) {
|
||||||
@ -2234,12 +2234,32 @@ function saveReply(type, getMessage, this_mes_is_name) {
|
|||||||
chat[chat.length - 1]['is_name'] = true;
|
chat[chat.length - 1]['is_name'] = true;
|
||||||
chat[chat.length - 1]['force_avatar'] = avatarImg;
|
chat[chat.length - 1]['force_avatar'] = avatarImg;
|
||||||
}
|
}
|
||||||
//console.log('runGenerate calls addOneMessage');
|
|
||||||
|
saveImageToMessage(img, chat[chat.length - 1]);
|
||||||
addOneMessage(chat[chat.length - 1]);
|
addOneMessage(chat[chat.length - 1]);
|
||||||
}
|
}
|
||||||
return { type, getMessage };
|
return { type, getMessage };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function saveImageToMessage(img, mes) {
|
||||||
|
if (mes && img.image) {
|
||||||
|
if (typeof mes.extra !== 'object') {
|
||||||
|
mes.extra = {};
|
||||||
|
}
|
||||||
|
mes.extra.image = img.image;
|
||||||
|
mes.title = img.title;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractImageFromMessage(getMessage) {
|
||||||
|
const regex = /<img src="(.*?)".*?alt="(.*?)".*?>/g;
|
||||||
|
const results = regex.exec(getMessage);
|
||||||
|
const image = results ? results[1] : '';
|
||||||
|
const title = results ? results[2] : '';
|
||||||
|
getMessage = getMessage.replace(regex, '');
|
||||||
|
return { getMessage, image, title };
|
||||||
|
}
|
||||||
|
|
||||||
function isMultigenEnabled() {
|
function isMultigenEnabled() {
|
||||||
return power_user.multigen && (main_api == 'textgenerationwebui' || main_api == 'kobold' || main_api == 'novel');
|
return power_user.multigen && (main_api == 'textgenerationwebui' || main_api == 'kobold' || main_api == 'novel');
|
||||||
}
|
}
|
||||||
|
@ -344,7 +344,6 @@ code {
|
|||||||
outline: none;
|
outline: none;
|
||||||
border: none;
|
border: none;
|
||||||
position: relative;
|
position: relative;
|
||||||
display: inline;
|
|
||||||
opacity: 0.7;
|
opacity: 0.7;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
z-index: 2001;
|
z-index: 2001;
|
||||||
@ -352,6 +351,8 @@ code {
|
|||||||
padding-top: 0;
|
padding-top: 0;
|
||||||
transition: 0.3s;
|
transition: 0.3s;
|
||||||
font-size: 30px;
|
font-size: 30px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.font-family-reset {
|
.font-family-reset {
|
||||||
@ -407,6 +408,7 @@ code {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
column-gap: 10px;
|
column-gap: 10px;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.options-content a div:first-child {
|
.options-content a div:first-child {
|
||||||
|
Reference in New Issue
Block a user