---
title: "Helpers/html"
---
# Helpers/html

## Interfaces

- [WordListItem](../interfaces/helpers_html.WordListItem.html)

### safeOptions

**safeOptions** = `object`

Defined in: [src/core/helpers/html/safe-html.ts:16](https://github.com/xdan/jodit/blob/main/src/core/helpers/html/safe-html.ts#L16)

##### removeOnError

**removeOnError**: `boolean`

Defined in: [src/core/helpers/html/safe-html.ts:17](https://github.com/xdan/jodit/blob/main/src/core/helpers/html/safe-html.ts#L17)

##### safeJavaScriptLink

**safeJavaScriptLink**: `boolean`

Defined in: [src/core/helpers/html/safe-html.ts:18](https://github.com/xdan/jodit/blob/main/src/core/helpers/html/safe-html.ts#L18)

##### removeEventAttributes?

`optional` **removeEventAttributes?**: `boolean`

Defined in: [src/core/helpers/html/safe-html.ts:19](https://github.com/xdan/jodit/blob/main/src/core/helpers/html/safe-html.ts#L19)

##### safeLinksTarget?

`optional` **safeLinksTarget?**: `boolean`

Defined in: [src/core/helpers/html/safe-html.ts:20](https://github.com/xdan/jodit/blob/main/src/core/helpers/html/safe-html.ts#L20)

### applyStyles()

**applyStyles**(`html`): `string`

Defined in: [src/core/helpers/html/apply-styles.ts:65](https://github.com/xdan/jodit/blob/main/src/core/helpers/html/apply-styles.ts#L65)

If the HTML has CSS rules with selectors,
it applies them to the selectors in the HTML itself
and then removes the selector styles, leaving only the inline ones.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `html` | `string` |

#### Returns

`string`

***

### cleanFromWord()

**cleanFromWord**(`html`, `keepAttributes?`): `string`

Defined in: [src/core/helpers/html/clean-from-word.ts:134](https://github.com/xdan/jodit/blob/main/src/core/helpers/html/clean-from-word.ts#L134)

The method automatically cleans up content from Microsoft Word and other HTML sources to ensure clean, compliant
content that matches the look and feel of the site.

#### Parameters

| Parameter | Type | Default value | Description |
| ------ | ------ | ------ | ------ |
| `html` | `string` | `undefined` | - |
| `keepAttributes` | readonly `string`[] | `PASTE_KEEP_ATTRIBUTES` | The attributes to keep; every other attribute, and every style, is removed |

#### Returns

`string`

***

### htmlspecialchars()

**htmlspecialchars**(`html`): `string`

Defined in: [src/core/helpers/html/htmlspecialchars.ts:16](https://github.com/xdan/jodit/blob/main/src/core/helpers/html/htmlspecialchars.ts#L16)

Convert special characters to HTML entities

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `html` | `string` |

#### Returns

`string`

***

### nl2br()

**nl2br**(`html`): `string`

Defined in: [src/core/helpers/html/nl2br.ts:14](https://github.com/xdan/jodit/blob/main/src/core/helpers/html/nl2br.ts#L14)

Inserts HTML line breaks before all newlines in a string

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `html` | `string` |

#### Returns

`string`

***

### safeHTML()

**safeHTML**(`box`, `options`): `void`

Defined in: [src/core/helpers/html/safe-html.ts:73](https://github.com/xdan/jodit/blob/main/src/core/helpers/html/safe-html.ts#L73)

Removes dangerous constructs from HTML

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `box` | [`HTMLElement`](https://developer.mozilla.org/docs/Web/API/HTMLElement) \| [`DocumentFragment`](https://developer.mozilla.org/docs/Web/API/DocumentFragment) |
| `options` | [`safeOptions`](#safeoptions) |

#### Returns

`void`

***

### sanitizeHTMLElement()

**sanitizeHTMLElement**(`elm`, `__namedParameters?`): `boolean`

Defined in: [src/core/helpers/html/safe-html.ts:239](https://github.com/xdan/jodit/blob/main/src/core/helpers/html/safe-html.ts#L239)

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `elm` | [`Element`](https://developer.mozilla.org/docs/Web/API/Element) \| [`DocumentFragment`](https://developer.mozilla.org/docs/Web/API/DocumentFragment) |
| `__namedParameters` | [`safeOptions`](#safeoptions) |

#### Returns

`boolean`

***

### stripTags()

**stripTags**(`html`, `doc?`, `exclude?`, `blockBr?`): `string`

Defined in: [src/core/helpers/html/strip-tags.ts:39](https://github.com/xdan/jodit/blob/main/src/core/helpers/html/strip-tags.ts#L39)

Extract plain text from HTML text

#### Parameters

| Parameter | Type | Default value |
| ------ | ------ | ------ |
| `html` | `string` \| [`Node`](https://developer.mozilla.org/docs/Web/API/Node) | `undefined` |
| `doc` | [`Document`](https://developer.mozilla.org/docs/Web/API/Document) | `document` |
| `exclude` | [`Nullable`](./types.html#nullable)\<[`Set`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set)\<[`HTMLTagNames`](./types.html#htmltagnames)\>\> | `null` |
| `blockBr` | `boolean` | `false` |

#### Returns

`string`

***

### indexOfClosingTag()

**indexOfClosingTag**(`html`, `name`, `from`): `number`

Defined in: [src/core/helpers/html/tag-scan.ts:52](https://github.com/xdan/jodit/blob/main/src/core/helpers/html/tag-scan.ts#L52)

The first `</name>` at or after `from`, case-insensitive, or -1

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `html` | `string` |
| `name` | `string` |
| `from` | `number` |

#### Returns

`number`

***

### removeTagsByPrefix()

**removeTagsByPrefix**(`html`, `prefixes`): `string`

Defined in: [src/core/helpers/html/tag-scan.ts:75](https://github.com/xdan/jodit/blob/main/src/core/helpers/html/tag-scan.ts#L75)

Remove every tag that starts with one of the prefixes, up to its `>`:
`removeTagsByPrefix(html, ['<meta', '<!--'])`

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `html` | `string` |
| `prefixes` | `string`[] |

#### Returns

`string`

***

### removeWordWrappers()

**removeWordWrappers**(`html`): `string`

Defined in: [src/core/helpers/html/tag-scan.ts:103](https://github.com/xdan/jodit/blob/main/src/core/helpers/html/tag-scan.ts#L103)

Strip the Word wrapper tags and then the comments, as the clean-up always did

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `html` | `string` |

#### Returns

`string`

***

### indexOfOpenTag()

**indexOfOpenTag**(`html`, `name`): `number`

Defined in: [src/core/helpers/html/tag-scan.ts:158](https://github.com/xdan/jodit/blob/main/src/core/helpers/html/tag-scan.ts#L158)

The index of the first `<name>` or `<name …>` tag, or -1

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `html` | `string` |
| `name` | `string` |

#### Returns

`number`

***

### unwrapMarkedTags()

**unwrapMarkedTags**(`html`, `name`, `marker`, `keep?`): `string`

Defined in: [src/core/helpers/html/tag-scan.ts:201](https://github.com/xdan/jodit/blob/main/src/core/helpers/html/tag-scan.ts#L201)

Replace every `<name … marker …>inner</name>` with `inner`.
`name` null takes any tag; `keep` can refuse an element by its inner HTML.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `html` | `string` |
| `name` | `string` \| `null` |
| `marker` | `string` |
| `keep?` | (`inner`) => `boolean` |

#### Returns

`string`

***

### removeBetween()

**removeBetween**(`html`, `open`, `openEnd`, `close`, `marker?`): `string`

Defined in: [src/core/helpers/html/tag-scan.ts:274](https://github.com/xdan/jodit/blob/main/src/core/helpers/html/tag-scan.ts#L274)

Remove every `open … openEnd … close` block whose opener holds `marker` (any opener when it is ''):
`removeBetween(html, '<style', '>', '</style>', 'jodit-box')`

#### Parameters

| Parameter | Type | Default value |
| ------ | ------ | ------ |
| `html` | `string` | `undefined` |
| `open` | `string` | `undefined` |
| `openEnd` | `string` | `undefined` |
| `close` | `string` | `undefined` |
| `marker` | `string` | `''` |

#### Returns

`string`

***

### removeEmptyMarkedTags()

**removeEmptyMarkedTags**(`html`, `name`, `marker`): `string`

Defined in: [src/core/helpers/html/tag-scan.ts:324](https://github.com/xdan/jodit/blob/main/src/core/helpers/html/tag-scan.ts#L324)

Remove every empty `<name … marker …></name>` element

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `html` | `string` |
| `name` | `string` |
| `marker` | `string` |

#### Returns

`string`

***

### readWordListItems()

**readWordListItems**(`root`): [`WordListItem`](../interfaces/helpers_html.WordListItem.html)[]

Defined in: [src/core/helpers/html/word-lists.ts:117](https://github.com/xdan/jodit/blob/main/src/core/helpers/html/word-lists.ts#L117)

Finds Word's list paragraphs (`<p style="mso-list:l0 level1 lfo1">`), reads
their list, level and type from the `mso-list:Ignore` marker, and removes the
marker. Call it before anything strips the `mso-list` styles, then pass the
result to [wrapWordListItems](#wrapwordlistitems)

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `root` | [`HTMLElement`](https://developer.mozilla.org/docs/Web/API/HTMLElement) |

#### Returns

[`WordListItem`](../interfaces/helpers_html.WordListItem.html)[]

***

### wrapWordListItems()

**wrapWordListItems**(`items`): `void`

Defined in: [src/core/helpers/html/word-lists.ts:163](https://github.com/xdan/jodit/blob/main/src/core/helpers/html/word-lists.ts#L163)

Turns the paragraphs found by [readWordListItems](#readwordlistitems) into `<ul>`/`<ol>`
lists, nesting them by level. Each paragraph becomes an `<li>` without Word's
hanging indent

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `items` | [`WordListItem`](../interfaces/helpers_html.WordListItem.html)[] |

#### Returns

`void`
