> For the complete documentation index, see [llms.txt](https://help.sdocs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.sdocs.com/sdocs/template-architecture/inserting-merge-fields/additional-resources/concerns-with-using-rich-text-field-formatting.md).

# Rich Text Field Formatting Considerations

Rich text fields often create extra spacing in generated documents.

{% hint style="info" %}
This behavior is most common when the rich text value is saved in Lightning Experience.
{% endhint %}

### Problem

Salesforce rich text values usually contain HTML such as `<p>` and `<br>`.

That can cause a few common issues:

* Extra blank lines between paragraphs
* Missing bold or italic styles when Unicode fonts are fully enabled
* Font substitution in PDF output, such as Times New Roman

### Solution 1: Clean up a merge field

Use this pattern when you output a single rich text field directly in the template.

{% code title="merge-field-example.html" %}

```html
<div style="font-family: sans-serif;">{{{!Object.fieldname replaceall="#LT#/p#GT##LT#
p#GT##LT#br#GT#,#LT#br#GT#,#LT#/p#GT##LT#p#GT#,#LT#br#GT#,#LT#p#GT#, ,#LT#/p#GT#, "}}}</div>
```

{% endcode %}

This replaces paragraph tags with single break tags and removes extra spacing.

#### Example

**Field value stored in Salesforce**

```html
<p>First line</p><p><br></p><p>Second line</p>
```

**Rendered output**

```
First line
Second line
```

{% hint style="warning" %}
Set **Unicode enforcement level** to `DATA`.
{% endhint %}

### Solution 2: Remove all paragraph tags in a related list

Use this option when a related list column should render as plain text with line breaks only.

{% code title="related-list-column-remove-all.xml" %}

```xml
<column replaceall="</p><p><br>,<br>,</p><p>,<br>,<p>, ,</p>, ">Description__c</column>
```

{% endcode %}

#### Example

{% code title="related-list-example-remove-all.xml" %}

```xml
<lineitemsSOQL>
  <soql>
    SELECT Description__c
    FROM Custom_Object__c
    WHERE Parent__c = '{{!Parent__c.Id}}'
  </soql>
  <column replaceall="</p><p><br>,<br>,</p><p>,<br>,<p>, ,</p>, ">Description__c</column>
</lineitemsSOQL>
```

{% endcode %}

**Field value stored in Salesforce**

```html
<p>Item one</p><p><br></p><p>Item two</p>
```

**Rendered output**

```
Item one
Item two
```

### Solution 3: Keep the first and last paragraph tags in a related list

Use this option when you want to preserve the outer paragraph wrapper and still remove the extra blank line in the middle.

{% code title="related-list-column-keep-outer.xml" %}

```xml
<column replaceall="</p><p><br>,<br>,</p><p>,<br>">Description__c</column>
```

{% endcode %}

#### Example

{% code title="related-list-example-keep-outer.xml" %}

```xml
<lineitemsSOQL>
  <soql>
    SELECT Description__c
    FROM Custom_Object__c
    WHERE Parent__c = '{{!Parent__c.Id}}'
  </soql>
  <column replaceall="</p><p><br>,<br>,</p><p>,<br>">Description__c</column>
</lineitemsSOQL>
```

{% endcode %}

**Field value stored in Salesforce**

```html
<p>Item one</p><p><br></p><p>Item two</p>
```

**Rendered output**

```html
<p>Item one<br>Item two</p>
```

### Tag reference

Use encoded tokens inside merge fields.

Use literal HTML tags inside related list column attributes.

| Token        | Represents |
| ------------ | ---------- |
| `#LT#p#GT#`  | `<p>`      |
| `#LT#/p#GT#` | `</p>`     |
| `#LT#br#GT#` | `<br>`     |
| `#QUOT#`     | `"`        |
| `#AMP#`      | `&`        |


---

# 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, and the optional `goal` query parameter:

```
GET https://help.sdocs.com/sdocs/template-architecture/inserting-merge-fields/additional-resources/concerns-with-using-rich-text-field-formatting.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
