Merge branch 'send-commands-return-value' of https://github.com/SillyTavern/SillyTavern into send-commands-return-value

d96bb3dcea9b5439d608ef444135b798f7d9996e

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +9 -7Ignore whitespace
public/scripts/slash-commands/SlashCommandReturnHelper.js+9 -7
@@ -41,10 +41,13 @@ export const slashCommandReturnHelper = {
4141 * @param {object|number|string} value The value to return
4242 * @param {object} [options={}] Options
4343 * @param {(o: object) => string} [options.objectToStringFunc=null] Function to convert the object to a string, if object was provided and 'object' was not the chosen return type
44+ * @param {(o: object) => string} [options.objectToHtmlFunc=null] Analog to 'objectToStringFunc', which will be used here if not provided - but can do a different string layout if HTML is requested
4445 * @returns {Promise<*>} The processed return value
4546 */
4647 async doReturn(type, value, { objectToStringFunc = o => o?.toString(), objectToHtmlFunc = null } = {}) {
47- const stringValue = typeof value !== 'string' ? objectToStringFunc(value) : value;
48+ const shouldHtml = type.endsWith('html');
49+ const actualConverterFunc = shouldHtml && objectToHtmlFunc ? objectToHtmlFunc : objectToStringFunc;
50+ const stringValue = typeof value !== 'string' ? actualConverterFunc(value) : value;
4851
4952 switch (type) {
5053 case 'popup-html':
@@ -53,12 +56,11 @@ export const slashCommandReturnHelper = {
5356 case 'chat-html':
5457 case 'toast-text':
5558 case 'toast-html': {
56- const shouldHtml = type.endsWith('html');
59+ const htmlOrNotHtml = shouldHtml ? (new showdown.Converter()).makeHtml(stringValue) : escapeHtml(stringValue);
57- const makeHtml = (str) => (new showdown.Converter()).makeHtml(str);
5860
5961 if (type.startsWith('popup')) await callGenericPopup(shouldHtml ? makeHtml(stringValue) : escapeHtml(stringValue)htmlOrNotHtml, POPUP_TYPE.TEXT);
6062 if (type.startsWith('chat')) sendSystemMessage(system_message_types.GENERIC, shouldHtml ? makeHtml(stringValue) : escapeHtml(stringValue)htmlOrNotHtml);
6163 if (type.startsWith('toast')) toastr.info(shouldHtml ? makeHtml(stringValue) : escapeHtml(stringValue)htmlOrNotHtml, null, { escapeHtml: !shouldHtml });
6264
6365 return '';
6466 }