mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Some chat separators (or dinkuses) cause markdown to be rendered on the chat window. Examples include "###" -> h3 and "---" -> metadata. This can look jarring to the end user as it can interrupt a pleasant chat experience. Therefore, it makes sense to ignore these lines with div tags that indicate to Showdown that this string doesn't need markdown. Signed-off-by: kingbri <bdashore3@proton.me>
19 lines
749 B
JavaScript
19 lines
749 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
|
|
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, `<div>${savedDinkus}</div>`).trim()
|
|
}];
|
|
} |