Read the document

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

getText

Return the entire document as plain text.

Returns

string: The entire document as plain text

Example

// Read the whole document as text
const text = toolkit.getText()

getHtml

Return the entire document as HTML.

Returns

string: The entire document as HTML

Example

// Read the whole document as HTML
const html = toolkit.getHtml()

getJson

Return the entire document as Tiptap JSON.

Returns

any: The entire document as Tiptap JSON

Example

// Read the whole document as Tiptap JSON
const json = toolkit.getJson()

getTextSelection

Return the current selection as text.

Returns

string: The selected text content as a plain string

Example

// Read the selected text
const selection = toolkit.getTextSelection()

getHtmlSelection

Return the current selection as HTML.

Returns

string: The selected HTML content

Example

// Read the selected HTML content
const selection = toolkit.getHtmlSelection()

getJsonSelection

Return the current selection as Tiptap JSON.

Returns

any: The selected Tiptap JSON content

Example

// Read the selected Tiptap JSON content
const selection = toolkit.getJsonSelection()

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

// 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

// Read an HTML slice
const snippet = toolkit.getHtmlRange({ 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

// 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

// 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

// 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

// 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 })