Regex: Change how MD formatting works

Previously, there was a checkbox to select placement as MD display.
This was counterintuitive since some users believed MD display
enclosed the other placement options.

Now, add a universal switch to finely tune what parts of a chat should
be excluded with MD formatting. For example a regex with the option
enabled with AI output selected will only format replies from the
character.

This is an improvement since users can now choose what parts of a
chat to format rather than sticking with a global display specifier.

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri
2023-07-08 14:06:35 -04:00
parent 68551ae15c
commit 3c3eed0996
4 changed files with 68 additions and 15 deletions

View File

@@ -7,6 +7,7 @@ export {
}
const regex_placement = {
// MD Display is deprecated. Do not use.
MD_DISPLAY: 0,
USER_INPUT: 1,
AI_OUTPUT: 2,
@@ -38,13 +39,17 @@ function regexFromString(input) {
}
// Parent function to fetch a regexed version of a raw string
function getRegexedString(rawString, placement, { characterOverride } = {}) {
function getRegexedString(rawString, placement, { characterOverride, isMarkdown } = {}) {
let finalString = rawString;
if (extension_settings.disabledExtensions.includes("regex") || !rawString || placement === undefined) {
return finalString;
}
extension_settings.regex.forEach((script) => {
if (script.markdownOnly && !isMarkdown) {
return;
}
if (script.placement.includes(placement)) {
finalString = runRegexScript(script, finalString, { characterOverride });
}