From fb5d998cd08e28ab9f37b3af00789614398e3ac2 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 21 Apr 2024 14:06:33 +0300 Subject: [PATCH] Allow all macro in story strings --- public/scripts/macros.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/public/scripts/macros.js b/public/scripts/macros.js index 74c89b715..05f3f7b66 100644 --- a/public/scripts/macros.js +++ b/public/scripts/macros.js @@ -1,4 +1,4 @@ -import { chat, chat_metadata, main_api, getMaxContextSize, getCurrentChatId } from '../script.js'; +import { chat, chat_metadata, main_api, getMaxContextSize, getCurrentChatId, substituteParams } from '../script.js'; import { timestampToMoment, isDigitsOnly, getStringHash } from './utils.js'; import { textgenerationwebui_banned_in_macros } from './textgen-settings.js'; import { replaceInstructMacros } from './instruct-mode.js'; @@ -6,6 +6,12 @@ import { replaceVariableMacros } from './variables.js'; // Register any macro that you want to leave in the compiled story string Handlebars.registerHelper('trim', () => '{{trim}}'); +// Catch-all helper for any macro that is not defined for story strings +Handlebars.registerHelper('helperMissing', function () { + const options = arguments[arguments.length - 1]; + const macroName = options.name; + return substituteParams(`{{${macroName}}}`); +}); /** * Gets a hashed id of the current chat from the metadata.