---
title: "tinymce.html.Writer"
description: "This class is used to write HTML tags out it can be used with the Serializer or the SaxParser."
canonical_url: "https://www.tiny.cloud/docs/tinymce/latest/apis/tinymce.html.writer/"
md_url: "https://www.tiny.cloud/docs/tinymce/5/apis/tinymce.html.writer/index.md"
version: "5"
last_updated: "2024-03-26T08:09:19Z"
tokens: 732
---
Important This page documents TinyMCE 5. For new projects, Tiny recommends using the latest, most up-to-date version. [See TinyMCE 8 documentation](../../../latest/apis/tinymce.html.writer/).
# tinymce.html.Writer

This class is used to write HTML tags out it can be used with the Serializer or the SaxParser.

## Examples

```javascript
var writer = new tinymce.html.Writer({indent: true});
var parser = new tinymce.html.SaxParser(writer).parse('<p><br></p>');
console.log(writer.getContent());
```

## Summary

### Methods

| Name | Summary | Defined by |
| --- | --- | --- |
| [cdata()](#cdata) | Writes a comment node such as <!-- Comment -->. | `Writer` |
| [doctype()](#doctype) | Writes a doctype node such as <!DOCTYPE data>. | `Writer` |
| [end()](#end) | Writes the a end element such as </p>. | `Writer` |
| [getContent()](#getContent) | Returns the contents that got serialized. | `Writer` |
| [pi()](#pi) | Writes a PI node such as <?xml attr="value" ?>. | `Writer` |
| [reset()](#reset) | Resets the internal buffer if one wants to reuse the writer. | `Writer` |
| [start()](#start) | Writes the a start element such as <p id="a">. | `Writer` |
| [text()](#text) | Writes a text node. | `Writer` |

## Methods

### cdata()

```javascript
cdata(text: String)
```
Writes a comment node such as <!-- Comment -->.

#### Parameters

- `text (String)` - String to write out inside the comment.

### doctype()

```javascript
doctype(text: String)
```
Writes a doctype node such as <!DOCTYPE data>.

#### Parameters

- `text (String)` - String to write out inside the doctype.

### end()

```javascript
end(name: String)
```
Writes the a end element such as </p>.

#### Parameters

- `name (String)` - Name of the element.

### getContent()

```javascript
getContent(): String
```
Returns the contents that got serialized.

#### Return value

- `String` - HTML contents that got written down.

### pi()

```javascript
pi(name: String, text: String)
```
Writes a PI node such as <?xml attr="value" ?>.

#### Parameters

- `name (String)` - Name of the pi.
- `text (String)` - String to write out inside the pi.

### reset()

```javascript
reset()
```
Resets the internal buffer if one wants to reuse the writer.

### start()

```javascript
start(name: String, attrs: Array, empty: Boolean)
```
Writes the a start element such as <p id="a">.

#### Parameters

- `name (String)` - Name of the element.
- `attrs (Array)` - Optional attribute array or undefined if it hasn’t any.
- `empty (Boolean)` - Optional empty state if the tag should end like

.

### text()

```javascript
text(text: String, raw: Boolean)
```
Writes a text node.

#### Parameters

- `text (String)` - String to write out.
- `raw (Boolean)` - Optional raw state if true the contents wont get encoded.
