diff --git a/public/index.html b/public/index.html index 1d864afde..9b67dac38 100644 --- a/public/index.html +++ b/public/index.html @@ -2130,6 +2130,9 @@ + +
diff --git a/public/script.js b/public/script.js index d443a8887..75f2b6e29 100644 --- a/public/script.js +++ b/public/script.js @@ -148,6 +148,7 @@ import { } from "./scripts/secrets.js"; import { EventEmitter } from './scripts/eventemitter.js'; import { context_settings, loadContextTemplatesFromSettings } from "./scripts/context-template.js"; +import { dinkusExtension } from "./scripts/showdown-dinkus.js"; //exporting functions and vars for mods export { @@ -533,6 +534,14 @@ function reloadMarkdownProcessor(render_formulas = false) { }); } + // Inject the dinkus extension after creating the converter + // Maybe move this into power_user init? + setTimeout(() => { + if (power_user) { + converter.addExtension(dinkusExtension(), 'dinkus'); + } + }, 1) + return converter; } diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index 376136782..e69f5ef9b 100644 --- a/public/scripts/power-user.js +++ b/public/scripts/power-user.js @@ -11,6 +11,7 @@ import { updateVisibleDivs, eventSource, event_types, + getCurrentChatId, } from "../script.js"; import { favsToHotswap } from "./RossAscends-mods.js"; import { @@ -933,6 +934,7 @@ $(document).ready(() => { $("#custom_chat_separator").on('input', function () { power_user.custom_chat_separator = $(this).val(); saveSettingsDebounced(); + reloadMarkdownProcessor(power_user.render_formulas); }); $("#multigen").change(function () { @@ -1155,6 +1157,13 @@ $(document).ready(() => { saveSettingsDebounced(); }); + $("#reload_chat").on('click', function () { + const currentChatId = getCurrentChatId(); + if (currentChatId !== undefined && currentChatId !== null) { + reloadCurrentChat(); + } + }); + $("#allow_name1_display").on("input", function () { power_user.allow_name1_display = !!$(this).prop('checked'); reloadCurrentChat(); diff --git a/public/scripts/showdown-dinkus.js b/public/scripts/showdown-dinkus.js new file mode 100644 index 000000000..597e40965 --- /dev/null +++ b/public/scripts/showdown-dinkus.js @@ -0,0 +1,19 @@ +import { power_user } from './power-user.js'; + +// Showdown extension to make chat separators (dinkuses) ignore markdown formatting +export const dinkusExtension = () => { + if (!power_user) { + console.log("Showdown-dinkus extension: power_user wasn't found! Returning."); + return [] + } + + // Create an escaped sequence so the regex can work with any character + const savedDinkus = power_user.custom_chat_separator + const escapedDinkus = savedDinkus.split('').map((e) => `\\${e}`).join(''); + const replaceRegex = new RegExp(`^(${escapedDinkus})\n`, "gm") + return [{ + type: "lang", + regex: replaceRegex, + replace: (match) => match.replace(replaceRegex, `
${savedDinkus}
`).trim() + }]; +} \ No newline at end of file