Skip to content

Commit c995268

Browse files
authored
Merge pull request #1349 from 190km/fix/logs-highlight-search-terms
fix: fixed highligh search terms color
2 parents c8828b5 + 2470d67 commit c995268

File tree

1 file changed

+23
-34
lines changed

1 file changed

+23
-34
lines changed

apps/dokploy/components/dashboard/docker/logs/terminal-line.tsx

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,45 +35,34 @@ export function TerminalLine({ log, noTimestamp, searchTerm }: LogLineProps) {
3535
})
3636
: "--- No time found ---";
3737

38-
const highlightMessage = (text: string, term: string) => {
39-
if (!term) {
38+
const highlightMessage = (text: string, term: string) => {
39+
if (!term) {
40+
return (
41+
<span
42+
className="transition-colors"
43+
dangerouslySetInnerHTML={{
44+
__html: fancyAnsi.toHtml(text),
45+
}}
46+
/>
47+
);
48+
}
49+
50+
const htmlContent = fancyAnsi.toHtml(text);
51+
const searchRegex = new RegExp(`(${escapeRegExp(term)})`, "gi");
52+
53+
const modifiedContent = htmlContent.replace(
54+
searchRegex,
55+
(match) =>
56+
`<span class="bg-orange-200/80 dark:bg-orange-900/80 font-bold">${match}</span>`,
57+
);
58+
4059
return (
4160
<span
4261
className="transition-colors"
43-
dangerouslySetInnerHTML={{
44-
__html: fancyAnsi.toHtml(text),
45-
}}
62+
dangerouslySetInnerHTML={{ __html: modifiedContent }}
4663
/>
4764
);
48-
}
49-
50-
const htmlContent = fancyAnsi.toHtml(text);
51-
const modifiedContent = htmlContent.replace(
52-
/<span([^>]*)>([^<]*)<\/span>/g,
53-
(match, attrs, content) => {
54-
const searchRegex = new RegExp(`(${escapeRegExp(term)})`, "gi");
55-
if (!content.match(searchRegex)) return match;
56-
57-
const segments = content.split(searchRegex);
58-
const wrappedSegments = segments
59-
.map((segment: string) =>
60-
segment.toLowerCase() === term.toLowerCase()
61-
? `<span${attrs} class="bg-yellow-200/50 dark:bg-yellow-900/50">${segment}</span>`
62-
: segment,
63-
)
64-
.join("");
65-
66-
return `<span${attrs}>${wrappedSegments}</span>`;
67-
},
68-
);
69-
70-
return (
71-
<span
72-
className="transition-colors"
73-
dangerouslySetInnerHTML={{ __html: modifiedContent }}
74-
/>
75-
);
76-
};
65+
};
7766

7867
const tooltip = (color: string, timestamp: string | null) => {
7968
const square = (

0 commit comments

Comments
 (0)