Skip to content

Commit

Permalink
fix(console): json coloring in logs (#6898)
Browse files Browse the repository at this point in the history
Parses the log entries in order to reduce the false positives for the JSON coloring algorithm.

Closes #2248.
  • Loading branch information
skyrpex authored Jul 12, 2024
1 parent 2acec76 commit 33f231b
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions apps/wing-console/console/design-system/src/text-highlight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,22 @@ const highlightJson = (value: string, theme: Theme) => {
return `${value
.slice(0, CHAR_LIMIT)
.replaceAll(
/("(\\u[\dA-Za-z]{4}|\\[^u]|[^"\\])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[Ee][+\-]?\d+)?)/g,
/{(?:[^"\\{}]|"(?:\\.|[^"\\])*"|{(?:[^"\\{}]|"(?:\\.|[^"\\])*")*})*}/g,
(match) => {
let className = palette.number;
if (match.startsWith('"')) {
className = match.endsWith(":") ? theme.text1 : palette.string;
} else if (/true|false/.test(match)) {
className = palette.boolean;
} else if (/null/.test(match)) {
className = palette.null;
}
return `<span class="${className}">${escape(match)}</span>`;
return `<span class="italic">${match.replaceAll(
/("(\\u[\dA-Za-z]{4}|\\[^u]|[^"\\])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[Ee][+\-]?\d+)?)/g,
(match) => {
let className = palette.number;
if (match.startsWith('"')) {
className = match.endsWith(":") ? theme.text1 : palette.string;
} else if (/true|false/.test(match)) {
className = palette.boolean;
} else if (/null/.test(match)) {
className = palette.null;
}
return `<span class="${className}">${escape(match)}</span>`;
},
)}</span>`;
},
)}${value.slice(CHAR_LIMIT)}`;
};
Expand Down

0 comments on commit 33f231b

Please sign in to comment.