term
This commit is contained in:
@@ -256,6 +256,17 @@ function parseColorTokens(message: string, renderColor: boolean): ColorToken[] {
|
||||
let chars: string[] = [];
|
||||
let startedColors: string[] = [];
|
||||
const messageLength = message.length;
|
||||
const _isAllSlashOrEmpty = function (chars: string): {
|
||||
result: boolean;
|
||||
count: number;
|
||||
} {
|
||||
for (const char of chars) {
|
||||
if (char !== "/") {
|
||||
return { result: false, count: -1 };
|
||||
}
|
||||
}
|
||||
return { result: true, count: chars.length };
|
||||
};
|
||||
for (let i = 0; i < messageLength; i++) {
|
||||
const c = message.charAt(i);
|
||||
const nextC = (i + 1) < messageLength
|
||||
@@ -308,7 +319,21 @@ function parseColorTokens(message: string, renderColor: boolean): ColorToken[] {
|
||||
break;
|
||||
case "]":
|
||||
if (inColorStart || inColorEnd) {
|
||||
if (chars.length > 0) {
|
||||
const isAllSlashOrEmpty = _isAllSlashOrEmpty(chars);
|
||||
if (isAllSlashOrEmpty.result && inColorEnd) {
|
||||
const popCount = isAllSlashOrEmpty.count + 1;
|
||||
for (let _i = 0; _i < popCount; _i++) {
|
||||
const poppedColor = startedColors.pop();
|
||||
if (poppedColor) {
|
||||
tokens.push({
|
||||
type: "color",
|
||||
colorStart: false,
|
||||
color: poppedColor,
|
||||
});
|
||||
}
|
||||
}
|
||||
chars = [];
|
||||
} else if (chars.length > 0) {
|
||||
tokens.push({
|
||||
type: "color",
|
||||
colorStart: inColorStart,
|
||||
@@ -320,15 +345,6 @@ function parseColorTokens(message: string, renderColor: boolean): ColorToken[] {
|
||||
startedColors.pop();
|
||||
}
|
||||
chars = [];
|
||||
} else if (chars.length === 0 && inColorEnd) {
|
||||
const poppedColor = startedColors.pop();
|
||||
if (poppedColor) {
|
||||
tokens.push({
|
||||
type: "color",
|
||||
colorStart: false,
|
||||
color: poppedColor,
|
||||
});
|
||||
}
|
||||
}
|
||||
inColorStart = false;
|
||||
inColorEnd = false;
|
||||
|
||||
Reference in New Issue
Block a user