Skip to content

Commit

Permalink
fix: remove html log message parsing (#100)
Browse files Browse the repository at this point in the history
There is no HTML message, so parsing is not required.
  • Loading branch information
rahulyadav-57 authored Sep 4, 2024
1 parent caa38d1 commit 52b7623
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 30 deletions.
3 changes: 1 addition & 2 deletions src/hooks/logActivity.hooks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { LogEntry, LogType } from '@/interfaces/log.interface';
import { logState } from '@/state/log.state';
import EventEmitter from '@/utility/eventEmitter';
import { htmlToAnsi, isHTML } from '@/utility/utils';
import { useRecoilState } from 'recoil';

export function useLogActivity() {
Expand Down Expand Up @@ -40,7 +39,7 @@ export function useLogActivity() {
return;
}
const logEntry: LogEntry = {
text: isHTML(text.trim()) ? htmlToAnsi(text.trim()) : text,
text,
type,
timestamp: !disableTimestamp ? new Date().toISOString() : '',
};
Expand Down
28 changes: 0 additions & 28 deletions src/utility/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,34 +88,6 @@ export const getContractURL = (
}tonviewer.com/${contractAddress}`;
};

export const htmlToAnsi = (html: string) => {
// Replace <b> and <i> tags with ANSI escape codes for bold and italic
html = html.replace(/<b>(.*?)<\/b>/g, '\x1b[1m$1\x1b[22m'); // Bold
html = html.replace(/<i>(.*?)<\/i>/g, '\x1b[3m$1\x1b[23m'); // Italic

// Replace <span> elements with ANSI escape codes for color
html = html.replace(
/<span style="color:(.*?)">(.*?)<\/span>/g,
(_, color, content) => {
const colorMap: Record<string, string> = {
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
reset: '\x1b[0m',
};
return `${colorMap[color]}${content}${colorMap.reset}`;
},
);

// Remove other HTML tags
html = html.replace(/<\/?[^>]+(>|$)/g, '');

return html;
};

export const isHTML = RegExp.prototype.test.bind(/(<([^>]+)>)/i);

export const getFileNameFromPath = (filePath: string): string => {
const pathArray = filePath.split('/');

Expand Down

0 comments on commit 52b7623

Please sign in to comment.