/* global marked, Prism */ /** * @file * * View for the messages. */ import { EventDispatcher } from './EventDispatcher.mjs'; import { Message } from './Message.mjs'; import { messageTypes } from './Message.mjs'; import { getUniqueId } from './util.mjs'; const events = { QUICK_ACTION_TRIGGER: 'quickactiontrigger', CODE_BLOCK_QUICK_ACTION_TRIGGER: 'codeblockquickactiontrigger', AFTER_LOAD_RENDER: 'afterloadrender', // applies only to promises AFTER_QUICK_ACTIONS_RENDER: 'afterquickactionsrender' }; const { lang, util } = apex; const MSG_PROCESSING = lang.getMessage('APEX.PROCESSING'), MSG_USER_AVATAR = lang.getMessage('APEX.AI.USER_AVATAR'), MSG_ERROR = lang.getMessage('APEX.ERROR'); const loaderMarkup = `
${util.escapeHTML(text)}
\n`; } else { return `${util.escapeHTML(text)}`; } }; renderer.paragraph = function({tokens}){ // note that the contents of text are already properly escaped // role none needed for a11y return `${this.parser.parseInline(tokens)}
\n`; }; return renderer; })(); const markedInst = new marked.Marked({ gfm: true, breaks: true, tables: true, mangle: false, xhtml: false, headerIds: false, renderer: markedRenderer }); const md2html = (message, codeBlockQuickActions = []) => { // render logic for code blocks borrowed from markedjs, adapted for our needs markedRenderer.code = function({text, lang, escaped}){ lang = (lang || '').match(/^\S*/)?.[0]; if (!escaped) { text = util.escapeHTML(text); } const actionBtnsMarkup = codeBlockQuickActions.reduce((prev, curr) => { const { id, iconClasses, label, ariaLabel } = curr; return `${prev} `; }, ''); const escLang = util.escapeHTMLAttr(lang || ''); let langElDomId; let headerMarkup = ''; if (lang || actionBtnsMarkup) { langElDomId = getUniqueId(); headerMarkup = `${text}