mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Fix markdown on replies & no scroll to bottom
This commit is contained in:
@ -1068,8 +1068,8 @@ function addOneMessage(mes, { type = "normal", insertAfter = null, scroll = true
|
||||
}
|
||||
|
||||
function scrollChatToBottom() {
|
||||
var $textchat = $("#chat");
|
||||
$textchat.scrollTop(($textchat[0].scrollHeight));
|
||||
// var $textchat = $("#chat");
|
||||
// $textchat.scrollTop(($textchat[0].scrollHeight));
|
||||
}
|
||||
|
||||
function substituteParams(content, _name1, _name2) {
|
||||
@ -2213,6 +2213,38 @@ function extractMessageFromData(data) {
|
||||
return getMessage;
|
||||
}
|
||||
|
||||
|
||||
function fixMarkdown(text) {
|
||||
// fix formatting problems in markdown
|
||||
// e.g.:
|
||||
// "^example * text*\n" -> "^example *text*\n"
|
||||
// "^*example * text\n" -> "^*example* text\n"
|
||||
// "^example *text *\n" -> "^example *text*\n"
|
||||
// "^* example * text\n" -> "^*example* text\n"
|
||||
// take note that the side you move the asterisk depends on where its pairing is
|
||||
// i.e. both of the following strings have the same broken asterisk ' * ', but you move the first to the left and the second to the right, to match the non-broken asterisk "^example * text*\n" "^*example * text\n"
|
||||
// and you HAVE to handle the cases where multiple pairs of asterisks exist in the same line
|
||||
// i.e. "^example * text* * harder problem *\n" -> "^example *text* *harder problem*\n"
|
||||
|
||||
// Find pairs of asterisks and capture the text in between them
|
||||
const asterisks = /\*{2}|(\*\s*\S.*?\S\s*\*)/g;
|
||||
let matches = [];
|
||||
let match;
|
||||
while ((match = asterisks.exec(text)) !== null) {
|
||||
matches.push(match);
|
||||
}
|
||||
|
||||
// Iterate through the matches and replace spaces immediately beside asterisks
|
||||
let newText = text;
|
||||
for (let i = matches.length - 1; i >= 0; i--) {
|
||||
let matchText = matches[i][0];
|
||||
let replacementText = matchText.replace(/\s*(?<=\*)\s|\s(?=\*)\s*/g, '');
|
||||
newText = newText.slice(0, matches[i].index) + replacementText + newText.slice(matches[i].index + matchText.length);
|
||||
}
|
||||
|
||||
return newText;
|
||||
}
|
||||
|
||||
function cleanUpMessage(getMessage, isImpersonate) {
|
||||
const nameToTrim = isImpersonate ? name2 : name1;
|
||||
if (power_user.collapse_newlines) {
|
||||
@ -2220,6 +2252,7 @@ function cleanUpMessage(getMessage, isImpersonate) {
|
||||
}
|
||||
|
||||
getMessage = $.trim(getMessage);
|
||||
getMessage = getMessage.replace(/\s+$/gm, "");
|
||||
if (is_pygmalion) {
|
||||
getMessage = getMessage.replace(/<USER>/g, name1);
|
||||
getMessage = getMessage.replace(/<BOT>/g, name2);
|
||||
@ -2253,7 +2286,7 @@ function cleanUpMessage(getMessage, isImpersonate) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getMessage = fixMarkdown(getMessage);
|
||||
return getMessage;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user