Files
SillyTavern/public/scripts/showdown-dinkus.js
kingbri fa9df8f22e Markdown: Fix dinkus formatter with codefences
Change how the formatter is applied to use an invisible null unicode
character instead of div tags and add a newline to preserve the DOM
tree so codeblocks and child elements aren't altered.

Signed-off-by: kingbri <bdashore3@proton.me>
2023-06-22 17:58:57 -04:00

26 lines
858 B
JavaScript

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
// No dinkus? No extension!
if (!savedDinkus || savedDinkus.trim().length === 0) {
return []
}
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, `\u0000${savedDinkus} \n`)
}];
}