Converse converse.js

Class: RichText

RichText(text, offset, options)

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 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.

Constructor

new RichText(text, offset, options)

Create a new RichText instance.

Parameters:
Name Type Default Description
text String

The text to be annotated

offset number 0

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).

options Object
Properties
Name Type Attributes Description
nick String

The current user's nickname (only relevant if the message is in a XEP-0045 MUC)

render_styling Boolean

Whether XEP-0393 message styling should be applied to the message

embed_audio Boolean <optional>

Whether audio URLs should be rendered as

embed_videos Boolean <optional>

Whether video URLs should be rendered as

mentions Array <optional>

An array of mention references

media_urls Array <optional>

An array of MediaURLMetadata objects, used to render media such as images, videos and audio. It might not be possible to have the media metadata available, so if this value is undefined then the passed-in text will be parsed for URLs. If you don't want this parsing to happen, pass in an empty array for this option.

show_images Boolean <optional>

Whether image URLs should be rendered as elements.

show_me_message Boolean

Whether /me messages should be rendered differently

onImgClick function

Callback for when an inline rendered image has been clicked

onImgLoad function

Callback for when an inline rendered image has been loaded

Source:

Classes

RichText

Methods

addAnnotations(func)

Look for plaintext (i.e. non-templated) sections of this RichText instance and add references via the passed in function.

Parameters:
Name Type Description
func function
Source:

addEmojis(text, offset)

Look for emojis (shortnames or unicode) and add templates for rendering them.

Parameters:
Name Type Description
text String
offset number

The index of the passed in text relative to the start of the message body text.

Source:

Look for http URIs and return templates that render them as URL links

Parameters:
Name Type Description
text String
local_offset number

The index of the passed in text relative to the start of this RichText instance (which is not necessarily the same as the offset from the start of the original message stanza's body text).

Source:

addMapURLs(text, offset)

Look for geo URIs and return templates that render them as URL links

Parameters:
Name Type Description
text String
offset number

The index of the passed in text relative to the start of the message body text.

Source:

addMentions(text, local_offset)

Look for mentions included as XEP-0372 references and add templates for rendering them.

Parameters:
Name Type Description
text String
local_offset number

The index of the passed in text relative to the start of this RichText instance (which is not necessarily the same as the offset from the start of the original message stanza's body text).

Source:

addStyling()

Look for XEP-0393 styling directives and add templates for rendering them.

Source:

(async) addTemplates()

Parse the text and add template references for rendering the "rich" parts.

Source:

marshall()

Take the annotations and return an array of text and TemplateResult instances to be rendered to the DOM.

Source:

(static) addTemplateResult(begin, end, template)

The "rich" markup parts of a chat message are represented by lit TemplateResult objects.

This method can be used to add new template results to this message's text.

Parameters:
Name Type Description
begin Number

The starting index of the plain message text which is being replaced with markup.

end Number

The ending index of the plain message text which is being replaced with markup.

template Object

The lit TemplateResult instance

Source: