fix(logs): rebuild legacy HTML safely
This commit is contained in:
@@ -1,26 +1,3 @@
|
||||
const logRegex = /<([RBGMCLSODYW]1?|1|\/)>/g;
|
||||
import { formatLegacyLogHtml } from '@sammo-ts/common';
|
||||
|
||||
const colorMap: Record<string, string> = {
|
||||
R: 'red',
|
||||
B: 'blue',
|
||||
G: 'green',
|
||||
M: 'magenta',
|
||||
C: 'cyan',
|
||||
L: 'limegreen',
|
||||
S: 'skyblue',
|
||||
O: 'orangered',
|
||||
D: 'orangered',
|
||||
Y: 'yellow',
|
||||
W: 'white',
|
||||
};
|
||||
|
||||
export const formatLog = (text: string): string =>
|
||||
text.replace(logRegex, (_all, tag: string) => {
|
||||
if (tag === '/') {
|
||||
return '</span>';
|
||||
}
|
||||
const color = colorMap[tag[0] ?? ''];
|
||||
const small = tag.includes('1');
|
||||
const styles = [color ? `color: ${color}` : '', small ? 'font-size: 0.9em' : ''].filter(Boolean).join('; ');
|
||||
return `<span style="${styles}">`;
|
||||
});
|
||||
export const formatLog = (text: string): string => formatLegacyLogHtml(text);
|
||||
|
||||
@@ -181,7 +181,7 @@ const handlePasswordReset = async (): Promise<void> => {
|
||||
<li>{{ info.turnTerm }}분 턴 서버</li>
|
||||
</ul>
|
||||
<div v-if="mapData?.history?.length" class="status-history">
|
||||
<!-- 레거시 색상 tag만 formatLog가 span으로 변환한다. -->
|
||||
<!-- 레거시 로그의 허용된 색상·강조·전투 구조만 안전한 HTML로 재구성한다. -->
|
||||
<!-- eslint-disable-next-line vue/no-v-html -->
|
||||
<div v-for="entry in mapData.history" :key="entry.id" v-html="formatLog(entry.text)" />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user