---
title: "Read the document"
description: "Extract document content in JSON, HTML, or text formats with support for selections, ranges, and chunked reads for AI integration."
canonical_url: "https://tiptap.dev/docs/content-ai/capabilities/ai-toolkit/api-reference/read-the-document"
---

# Read the document

Extract document content in JSON, HTML, or text formats with support for selections, ranges, and chunked reads for AI integration.

Read content in multiple formats. Chunked reads help with large documents.

## `getTextRange`

Return text content from a specific range.

### Parameters

- `range` (`Range`): The range to get content from
  - `from` (`number`): Start position
  - `to` (`number`): End position
- `options?` (`GetTextRangeOptions`): Options for the `getTextRange` method
  - `doc?` (`Node`): Optional document node to use instead of the current editor document

### Returns

`string`: The text content as a plain string

### Example

```ts
// Read a text slice
const snippet = toolkit.getTextRange({ from: 0, to: 100 })
```

## `getHtmlRange`

Return HTML content from a specific range.

### Parameters

- `range` (`Range`): The range to get content from
  - `from` (`number`): Start position
  - `to` (`number`): End position
- `options?` (`GetHtmlRangeOptions`): Options for the `getHtmlRange` method
  - `doc?` (`Node`): Optional document node to use instead of the current editor document

### Returns

`string`: The HTML content as a string

### Example

```ts
// Read the HTML of the content from position 0 to 100
const snippet = toolkit.getHtmlRange({ from: 0, to: 100 })
```

## `getMarkdownRange`

Return Markdown content from a specific range.

> **Markdown extension required:**
>
> This method requires the [Tiptap Markdown
> extension](https://tiptap.dev/docs/editor/markdown/api/editor) to be installed and configured.

### Parameters

- `range` (`Range`): The range to get content from
  - `from` (`number`): Start position
  - `to` (`number`): End position
- `options?` (`GetMarkdownRangeOptions`): Options for the `getMarkdownRange` method
  - `doc?` (`Node`): Optional document node to use instead of the current editor document

### Returns

`string`: The Markdown content as a string, or an empty string if the Markdown extension is not available

### Example

```ts
// Read the Markdown of the content from position 0 to 100
const snippet = toolkit.getMarkdownRange({ from: 0, to: 100 })
```

## `getJsonRange`

Return Tiptap JSON content from a specific range.

### Parameters

- `range` (`Range`): The range to get content from
  - `from` (`number`): Start position
  - `to` (`number`): End position
- `options?` (`GetJsonRangeOptions`): Options for the `getJsonRange` method
  - `doc?` (`Node`): Optional document node to use instead of the current editor document

### Returns

`any`: The Tiptap JSON content

### Example

```ts
// Read a Tiptap JSON slice
const snippet = toolkit.getJsonRange({ from: 0, to: 100 })
```

## `getTextChunks`

Split the document into text chunks for large-content processing.

### Parameters

- `options?` (`GetTextChunksOptions`): Options for the `getTextChunks` method
  - `chunkSize?` (`number`): Max characters per chunk. Defaults to 32,000 characters (8000 tokens \* 4 characters per token)

### Returns

`TextChunk[]`: Array of text chunks, where each chunk contains:

- `content` (`string`): The text content of the chunk
- `range` (`Range`): The range in the document where the chunk starts and ends
  - `from` (`number`): Start position in the document
  - `to` (`number`): End position in the document
- `nodeRange` (`NodeRange`): The node range where the chunk starts and ends
  - `from` (`number`): Start node position in the document
  - `to` (`number`): End node position in the document

### Example

```ts
// Split the document into chunks of the default size
const chunks = toolkit.getTextChunks()
// Split the document into chunks of 1000 characters maximum
const smallerChunks = toolkit.getTextChunks({ chunkSize: 1000 })
```

## `getHtmlChunks`

Split the document into HTML chunks for large-content processing.

### Parameters

- `options?` (`GetHtmlChunksOptions`): Options for the `getHtmlChunks` method
  - `chunkSize?` (`number`): Max characters per chunk. Defaults to 32,000 characters (8000 tokens \* 4 characters per token)

### Returns

`HtmlChunk[]`: Array of HTML chunks, where each chunk contains:

- `content` (`string`): The HTML content of the chunk
- `range` (`Range`): The range in the document where the chunk starts and ends
  - `from` (`number`): Start position in the document
  - `to` (`number`): End position in the document
- `nodeRange` (`NodeRange`): The node range where the chunk starts and ends
  - `from` (`number`): Start node position in the document
  - `to` (`number`): End node position in the document

### Example

```ts
// Split the document into chunks of the default size
const chunks = toolkit.getHtmlChunks()
// Split the document into chunks of 1000 characters maximum
const smallerChunks = toolkit.getHtmlChunks({ chunkSize: 1000 })
```

## `getJsonChunks`

Split the document into Tiptap JSON chunks for large-content processing.

### Parameters

- `options?` (`GetJsonChunksOptions`): Options for the `getJsonChunks` method
  - `chunkSize?` (`number`): Max characters per chunk. Defaults to 32,000 characters (8000 tokens \* 4 characters per token)

### Returns

`JsonChunk[]`: Array of Tiptap JSON chunks, where each chunk contains:

- `content` (`any`): The Tiptap JSON content of the chunk. It is the JSON of a Fragment of the document.
- `range` (`Range`): The range in the document where the chunk starts and ends
  - `from` (`number`): Start position in the document
  - `to` (`number`): End position in the document
- `nodeRange` (`NodeRange`): The node range where the chunk starts and ends
  - `from` (`number`): Start node position in the document
  - `to` (`number`): End node position in the document

### Example

```ts
// Split the document into chunks of the default size
const chunks = toolkit.getJsonChunks()
// Split the document into chunks of 1000 characters maximum
const smallerChunks = toolkit.getJsonChunks({ chunkSize: 1000 })
```

## `tiptapRead`

Read the document in a format that allows the AI to make fast, efficient edits.

Used in the [Proofreader workflow](https://tiptap.dev/docs/content-ai/capabilities/ai-toolkit/workflows/proofreader.md) and other workflows.

### Parameters

- `range?` (`Range`): The range to read from. Defaults to the entire document.
  - `from` (`number`): Start position
  - `to` (`number`): End position
- `ignoreSuggestions?` (`boolean`): When `true`, preview suggestions are not applied and the document is read as-is. Defaults to `false`.
- `reviewOptions?` ([`ReviewOptions`](https://tiptap.dev/docs/content-ai/capabilities/ai-toolkit/api-reference/review-options.md)): Review mode options used to decide which document representation should be read.
  - When `mode` is `'trackedChanges'`, the method reads the document after tracked changes have been applied.

### Returns (`TiptapReadResult`)

- `content` (`string`): The content of the document in a format that allows the AI to make fast, efficient edits.

## `tiptapReadChunks`

Read the document in the Tiptap Read format, split into chunks for large-content processing.

### Parameters

- `options?` (`TiptapReadChunksOptions`): Options for the `tiptapReadChunks` method
  - `chunkSize?` (`number`): Max characters per chunk. Defaults to 32,000 characters (8000 tokens \* 4 characters per token)
  - `reviewOptions?` ([`ReviewOptions`](https://tiptap.dev/docs/content-ai/capabilities/ai-toolkit/api-reference/review-options.md)): Review mode options used to decide which document representation should be chunked.
    - When `mode` is `'trackedChanges'`, the method chunks the document after tracked changes have been applied.

### Returns

`TiptapReadChunk[]`: Array of chunks, where each chunk contains:

- `content` (`string`): HTML content in the Tiptap Read format
- `range` (`Range`): The range in the document where the chunk starts and ends
  - `from` (`number`): Start position in the document
  - `to` (`number`): End position in the document
- `nodeRange` (`NodeRange`): The node range where the chunk starts and ends
  - `from` (`number`): Start node position in the document
  - `to` (`number`): End node position in the document

### Example

```ts
// Split the document into chunks
const chunks = toolkit.tiptapReadChunks()
// Split the document into smaller chunks
const smallerChunks = toolkit.tiptapReadChunks({ chunkSize: 16000 })
```
