Skip to content

Commit 0079d34

Browse files
committed
feat(chat): add support for custom markdown renderer
1 parent adf894e commit 0079d34

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

src/components/chat/chat-message.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ export default class IgcChatMessageComponent extends LitElement {
4545
const sanitizedMessageText = this.sanitizeMessageText(
4646
this.message?.text.trim() || ''
4747
);
48+
const renderer =
49+
this._chatState?.options?.markdownRenderer || renderMarkdown;
4850

4951
return html`
5052
<div class=${containerClass}>
5153
<div class="bubble">
5254
${this._chatState?.options?.templates?.messageTemplate && this.message
5355
? this._chatState.options.templates.messageTemplate(this.message)
5456
: html` ${sanitizedMessageText
55-
? html`<div>${renderMarkdown(sanitizedMessageText)}</div>`
57+
? html`<div>${renderer(sanitizedMessageText)}</div>`
5658
: nothing}
5759
${this.message?.attachments &&
5860
this.message?.attachments.length > 0

src/components/chat/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type AttachmentTemplate = (
2323
attachments: IgcMessageAttachment[]
2424
) => TemplateResult;
2525
export type MessageTemplate = (message: IgcMessage) => TemplateResult;
26+
export type MarkdownRenderer = (text: string) => TemplateResult;
2627

2728
export type IgcChatOptions = {
2829
currentUserId?: string;
@@ -40,6 +41,7 @@ export type IgcChatOptions = {
4041
headerText?: string;
4142
suggestions?: string[];
4243
templates?: IgcChatTemplates;
44+
markdownRenderer?: MarkdownRenderer;
4345
};
4446

4547
export type IgcChatTemplates = {

stories/chat.stories.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ const messageActionsTemplate = (msg: any) => {
106106
};
107107

108108
const _composingIndicatorTemplate = html`<span>LOADING...</span>`;
109+
const _customRenderer = (text: string) =>
110+
html`<span>${text.toUpperCase()}</span>`;
109111

110112
const ai_chat_options = {
111113
headerText: 'Chat',
@@ -114,6 +116,7 @@ const ai_chat_options = {
114116
messageActionsTemplate: messageActionsTemplate,
115117
//composingIndicatorTemplate: _composingIndicatorTemplate,
116118
},
119+
// markdownRenderer: _customRenderer
117120
};
118121

119122
const chat_options = {

0 commit comments

Comments
 (0)