Skip to content

Commit 5f5cffd

Browse files
authored
Merge pull request #301 from FlowiseAI/bugfix/Code-Block-Color
Bugfix/white color within code block
2 parents cd5f068 + d193f9b commit 5f5cffd

File tree

6 files changed

+51
-8
lines changed

6 files changed

+51
-8
lines changed

dist/components/bubbles/BotBubble.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/components/bubbles/GuestBubble.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/web.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/web.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/bubbles/BotBubble.tsx

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,26 @@ export const BotBubble = (props: Props) => {
5858
if (el) {
5959
el.innerHTML = Marked.parse(props.message.message);
6060

61-
// Apply textColor to all links, headings, and other markdown elements
61+
// Apply textColor to all links, headings, and other markdown elements except code
6262
const textColor = props.textColor ?? defaultTextColor;
63-
el.querySelectorAll('a, h1, h2, h3, h4, h5, h6, strong, em, blockquote, li, code, pre').forEach((element) => {
63+
el.querySelectorAll('a, h1, h2, h3, h4, h5, h6, strong, em, blockquote, li').forEach((element) => {
6464
(element as HTMLElement).style.color = textColor;
6565
});
6666

67+
// Code blocks (with pre) get white text
68+
el.querySelectorAll('pre').forEach((element) => {
69+
(element as HTMLElement).style.color = '#FFFFFF';
70+
// Also ensure any code elements inside pre have white text
71+
element.querySelectorAll('code').forEach((codeElement) => {
72+
(codeElement as HTMLElement).style.color = '#FFFFFF';
73+
});
74+
});
75+
76+
// Inline code (not in pre) gets green text
77+
el.querySelectorAll('code:not(pre code)').forEach((element) => {
78+
(element as HTMLElement).style.color = '#4CAF50'; // Green color
79+
});
80+
6781
// Set target="_blank" for links
6882
el.querySelectorAll('a').forEach((link) => {
6983
link.target = '_blank';
@@ -267,10 +281,25 @@ export const BotBubble = (props: Props) => {
267281
const setArtifactRef = (el: HTMLSpanElement) => {
268282
if (el) {
269283
const textColor = props.textColor ?? defaultTextColor;
270-
el.querySelectorAll('a, h1, h2, h3, h4, h5, h6, strong, em, blockquote, li, code, pre').forEach((element) => {
284+
// Apply textColor to all elements except code blocks
285+
el.querySelectorAll('a, h1, h2, h3, h4, h5, h6, strong, em, blockquote, li').forEach((element) => {
271286
(element as HTMLElement).style.color = textColor;
272287
});
273288

289+
// Code blocks (with pre) get white text
290+
el.querySelectorAll('pre').forEach((element) => {
291+
(element as HTMLElement).style.color = '#FFFFFF';
292+
// Also ensure any code elements inside pre have white text
293+
element.querySelectorAll('code').forEach((codeElement) => {
294+
(codeElement as HTMLElement).style.color = '#FFFFFF';
295+
});
296+
});
297+
298+
// Inline code (not in pre) gets green text
299+
el.querySelectorAll('code:not(pre code)').forEach((element) => {
300+
(element as HTMLElement).style.color = '#4CAF50'; // Green color
301+
});
302+
274303
el.querySelectorAll('a').forEach((link) => {
275304
link.target = '_blank';
276305
});

src/components/bubbles/GuestBubble.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,24 @@ export const GuestBubble = (props: Props) => {
3131

3232
// Apply textColor to all links, headings, and other markdown elements
3333
const textColor = props.textColor ?? defaultTextColor;
34-
el.querySelectorAll('a, h1, h2, h3, h4, h5, h6, strong, em, blockquote, li, code, pre').forEach((element) => {
34+
el.querySelectorAll('a, h1, h2, h3, h4, h5, h6, strong, em, blockquote, li').forEach((element) => {
3535
(element as HTMLElement).style.color = textColor;
3636
});
3737

38+
// Code blocks (with pre) get white text
39+
el.querySelectorAll('pre').forEach((element) => {
40+
(element as HTMLElement).style.color = '#FFFFFF';
41+
// Also ensure any code elements inside pre have white text
42+
element.querySelectorAll('code').forEach((codeElement) => {
43+
(codeElement as HTMLElement).style.color = '#FFFFFF';
44+
});
45+
});
46+
47+
// Inline code (not in pre) gets green text
48+
el.querySelectorAll('code:not(pre code)').forEach((element) => {
49+
(element as HTMLElement).style.color = '#4CAF50'; // Green color
50+
});
51+
3852
// Set target="_blank" for links
3953
el.querySelectorAll('a').forEach((link) => {
4054
link.target = '_blank';

0 commit comments

Comments
 (0)