import tplAudio from 'templates/audio.js'; import tplGif from 'templates/gif.js'; import tplImage from 'templates/image.js'; import tplVideo from 'templates/video.js'; import { api } from '@converse/headless/core'; import { containsDirectives, getDirectiveAndLength, getDirectiveTemplate, isQuoteDirective } from './styling.js'; import { getEmojiMarkup } from './chat/utils.js'; import { getHyperlinkTemplate } from 'utils/html.js'; import { getMediaURLs } from '@converse/headless/shared/chat/utils.js'; import { getMediaURLsMetadata } from '@converse/headless/shared/parsers.js'; import { convertASCII2Emoji, getCodePointReferences, getShortnameReferences } from '@converse/headless/plugins/emoji/utils.js'; import { filterQueryParamsFromURL, isAudioURL, isGIFURL, isImageURL, isVideoURL, shouldRenderMediaFromURL, } from '@converse/headless/utils/url.js'; import { html } from 'lit'; const isString = s => typeof s === 'string'; // We don't render more than two line-breaks, replace extra line-breaks with // the zero-width whitespace character const collapseLineBreaks = text => text.replace(/\n\n+/g, m => `\n${'\u200B'.repeat(m.length - 2)}\n`); const tplMentionWithNick = o => html`${o.mention}`; const tplMention = o => html`${o.mention}`; /** * @class RichText * A String subclass that is used to render rich text (i.e. text that contains * hyperlinks, images, mentions, styling etc.). * * The "rich" parts of the text is represented by lit TemplateResult * objects which are added via the {@link RichText.addTemplateResult} * method and saved as metadata. * * By default Converse adds TemplateResults to support emojis, hyperlinks, * images, map URIs and mentions. * * 3rd party plugins can listen for the `beforeMessageBodyTransformed` * and/or `afterMessageBodyTransformed` events and then call * `addTemplateResult` on the RichText instance in order to add their own * rich features. */ export class RichText extends String { /** * Create a new {@link RichText} instance. * @param { String } text - The text to be annotated * @param { number } offset - The offset of this particular piece of text * from the start of the original message text. This is necessary because * RichText instances can be nested when templates call directives * which create new RichText instances (as happens with XEP-393 styling directives). * @param { Object } options * @param { String } options.nick - The current user's nickname (only relevant if the message is in a XEP-0045 MUC) * @param { Boolean } options.render_styling - Whether XEP-0393 message styling should be applied to the message * @param { Boolean } [options.embed_audio] - Whether audio URLs should be rendered as