Spaces:
Running
Running
File size: 713 Bytes
b39afbe |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
/**
* Copyright (c) 2023 MERCENARIES.AI PTE. LTD.
* All rights reserved.
*/
import { ChatRenderer } from 'omni-client-services';
import DOMPurify from 'dompurify';
import { escapeHtmlSpecialChars } from '../../utils';
// An extension to render sanitized plain text in a chat message
class PlainTextRenderer extends ChatRenderer {
constructor(id?: string, opts?: any) {
super({ id: id ?? 'text/plain' }, opts);
}
render(content: { type: string; value: any }): string {
const text = Array.isArray(content.value) ? content.value.join('\n') : content.value?.toString();
return DOMPurify.sanitize(escapeHtmlSpecialChars(text)).replace(/\n/g, '<br/>');
}
}
export default PlainTextRenderer;
|