export const highlight = (message: string): string => {
    const replaceRegex = /(\*\*?|")/ig;
    const splitToken = '___SPLIT_AWOORWA___';

    const preparedMessage = message.replace(replaceRegex, `${splitToken}$1${splitToken}`);
    const parts = preparedMessage.split(splitToken);

    const stack: string[] = [];

    let resultHTML = '';

    for (const part of parts) {
        const isClose = stack.at(-1) === part;
        if (isClose) {
            stack.pop();
            if (part === '*' || part === '**' || part === '"') {
                resultHTML += `${part}</span>`;
            }
        } else {
            if (part === '*') {
                stack.push(part);
                resultHTML += `<span style="font-style:italic;color:var(--italicColor)">`;
            } else if (part === '**') {
                stack.push(part);
                resultHTML += `<span style="font-weight:bold">`;
            } else if (part === '"') {
                stack.push(part);
                resultHTML += `<span style="color:var(--quoteColor)">`;
            }
            resultHTML += part;
        }
    }

    while (stack.length) {
        const part = stack.pop();
        if (part === '*' || part === '**' || part === '"') {
            resultHTML += `</span>`;
        }
    }

    return resultHTML;
}