> For the complete documentation index, see [llms.txt](https://docs.wem.io/platform/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.wem.io/platform/tutorials/building-widgets/wemscript/8-types/8-richtext.md).

# 8. Richtext

A `richtext` type variable is used to represent and manipulate a sequence of characters that holds rich content.

```
<?
	var @rt: richtext
	@rt := "<strong>This text is very"
	@rt := @rt + ToRichText(" strong</strong>")
?>
```

#### Implicit HTML Encoding

When you concatenate a text value to a richtext variable, implicit encoding is applied to the text value. This is not always desired; therefore, the `ToRichText()` function can be used. Let’s dissect the example above.

```
var @rt: richtext
```

This line declares the variable `@rt` as `richtext`.

```
@rt := "<strong>This text is very"
```

Since the left-hand side `@rt` is of type `richtext` and the expression on the right-hand side is a literal text, the text is treated as richtext. The value of the variable `@rt` is now `<strong>This text is very`.

```
@rt := @rt + ToRichText(" strong</strong>")
```

Once again, the left-hand side `@rt` is of type `richtext`, but the expression on the right-hand side is a concatenation of `richtext` + `richtext`, resulting in the value `<strong>This text is very strong</strong>`.

What happens if we don't use the `ToRichText()` function?

```
@rt := @rt + " strong</strong>"
```

In this case, the expression is of `richtext` + `text`. When evaluating the right `text` operand, it will be coerced into `richtext`. During this conversion, the text value will be HTML encoded, resulting in `<strong>This text is very strong&lt;/strong&gt;`. This is not what we wanted in this example, as it generates malformed HTML.

So, be cautious when concatenating with `richtext`.

#### Postback

Fortunately, performing a postback with richtext is quite straightforward. You don't have to deal with localization, and updating the property with a new value is simply a matter of sending it back as is.

```html
<? register input @RichTextProperty ?>
<textarea name="<?attr OutputId(@RichTextProperty) ?>"><?= @RichTextProperty ?></textarea>
```

#### Print Output Overview

Since we are dealing with `richtext`, the encoding is mostly ignored, except for JavaScript encoding. Let’s assume we have a variable `var @rt: richtext` that holds the value `<p>I am a paragraph.</p>`. The following encoding (or lack thereof) will produce the corresponding outputs:

| Encoding        | Output                       |
| --------------- | ---------------------------- |
| `<?= @rt ?>`    | \<p>I am a paragraph.\</p>   |
| `<?attr @rt ?>` | \<p>I am a paragraph.\</p>   |
| `<?js @rt ?>`   | "\<p>I am a paragraph.\</p>" |
| `<?raw @rt ?>`  | \<p>I am a paragraph.\</p>   |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wem.io/platform/tutorials/building-widgets/wemscript/8-types/8-richtext.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
