diff --git a/__visual_tests__/const.ts b/__visual_tests__/const.ts
index b8cbde4f5..58266c50f 100644
--- a/__visual_tests__/const.ts
+++ b/__visual_tests__/const.ts
@@ -15,4 +15,5 @@ export const WidgetComponentIds = {
INPUT: '.sendbird-input__input',
CHIPS_CONTAINER: '.sendbird-form-chip__container',
FORM: '#aichatbot-widget-form',
+ MARKDOWN: 'widget-markdown',
};
diff --git a/__visual_tests__/workflow-tests.spec.ts b/__visual_tests__/workflow-tests.spec.ts
index 49778c090..d7c913c36 100644
--- a/__visual_tests__/workflow-tests.spec.ts
+++ b/__visual_tests__/workflow-tests.spec.ts
@@ -137,3 +137,21 @@ test('103', async ({ page, browserName }) => {
await page.waitForTimeout(2000);
await assertScreenshot(page, '103-6', browserName);
});
+
+/**
+ * 104
+ * Workflow - Markdown response
+ * Steps:
+ * 1. Send the trigger message: "give me a markdown message"
+ */
+test('104', async ({ page, browserName }) => {
+ await loadWidget(page);
+ // 1
+ await sendTextMessage(page, 'give me a markdown message', 5000);
+
+ // Wait for the lazy-loaded component to appear
+ const markdown = page.locator(WidgetComponentIds.MARKDOWN);
+ await expect(markdown).toBeVisible();
+
+ await assertScreenshot(page, '104', browserName);
+});
diff --git a/src/components/TokensBody.tsx b/src/components/TokensBody.tsx
index 059d68e37..fe5c63aa8 100644
--- a/src/components/TokensBody.tsx
+++ b/src/components/TokensBody.tsx
@@ -1,5 +1,5 @@
import DOMPurify from 'dompurify';
-import Markdown from 'markdown-to-jsx';
+import { lazy, Suspense } from 'react';
import styled from 'styled-components';
import BotMessageBottom from './BotMessageBottom';
@@ -10,6 +10,8 @@ import { Token, TokenType } from '../utils';
import './markdown.scss';
+const Markdown = lazy(() => import('markdown-to-jsx'));
+
type TokensBodyProps = {
tokens: Token[];
sources?: Source[];
@@ -44,66 +46,74 @@ export default function TokensBody({ tokens, sources }: TokensBodyProps) {
const { enableSourceMessage } = useConstantState();
return (
-
- {children}
-
- ),
+
- {children}
-
- ),
+ overrides: {
+ // Note that this is to remove text-align: right by the library.
+ td: {
+ component: ({ children, ...props }) => (
+
+ {children}
+
+ ),
+ },
+ // Note that this is to remove text-align: right by the library.
+ th: {
+ component: ({ children, ...props }) => (
+
+ {children}
+
+ ),
+ },
+ a: {
+ component: ({ children, ...props }) => (
+
+ {children}
+
+ ),
+ },
},
- a: {
- component: ({ children, ...props }) => (
-
- {children}
-
- ),
- },
- },
- }}
- >
- {token.value}
-