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.

Parameters

  • options? (GetTextSelectionOptions): Options for the getTextSelection method
    • chunkOptions? (GetTextChunksOptions): Used to compute chunkIndex in selection result
      • chunkSize? (number): Maximum size of each chunk in number of characters. Defaults to 32,000 characters
      • chunkingFunction? ((doc: string) => string[]): Custom chunking function

Returns

  • selection (string): The selected text content as a plain string
  • chunkIndex (number): The index of the chunk where the selection starts

Example

// Read the selected text and its chunk index
const sel = toolkit.getTextSelection()

getHtmlSelection

Return the current selection as HTML.

Parameters

  • options? (GetTextSelectionOptions): Options for the getHtmlSelection method
    • chunkOptions? (GetTextChunksOptions): Used to compute chunkIndex in selection result
      • chunkSize? (number): Maximum size of each chunk in number of characters. Defaults to 32,000 characters
      • chunkingFunction? ((doc: string) => string[]): Custom chunking function

Returns

  • selection (string): The selected HTML content
  • chunkIndex (number): The index of the chunk where the selection starts

Example

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

getJsonSelection

Return the current selection as Tiptap JSON.

Parameters (GetTextSelectionOptions)

  • chunkOptions? (GetTextChunksOptions): Used to compute chunkIndex in selection result
    • chunkSize? (number): Maximum size of each chunk in number of characters. Defaults to 32,000 characters
    • chunkingFunction? ((doc: string) => string[]): Custom chunking function

Returns

  • selection (any): The selected Tiptap JSON content
  • chunkIndex (number): The index of the chunk where the selection starts

Example

// Read the selected Tiptap JSON content
const jsonSel = 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
    • chunkOptions? (GetTextChunksOptions): Used to compute chunkIndex
      • chunkSize? (number): Maximum size of each chunk in number of characters. Defaults to 32,000 characters
      • chunkingFunction? ((doc: string) => string[]): Custom chunking function

Returns (GetJsonSelectionResult)

  • content (string): The text content as a plain string
  • chunkIndex (number): The index of the chunk where the range starts

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? (GetTextRangeOptions): Options for the getHtmlRange method
    • chunkOptions? (GetTextChunksOptions): Used to compute chunkIndex
      • chunkSize? (number): Maximum size of each chunk in number of characters. Defaults to 32,000 characters
      • chunkingFunction? ((doc: string) => string[]): Custom chunking function

Returns

  • content (string): The HTML content as a string
  • chunkIndex (number): The index of the chunk where the range starts

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? (GetTextRangeOptions): Options for the getJsonRange method
    • chunkOptions? (GetTextChunksOptions): Used to compute chunkIndex
      • chunkSize? (number): Maximum size of each chunk in number of characters. Defaults to 32,000 characters
      • chunkingFunction? ((doc: string) => string[]): Custom chunking function

Returns

  • content (any): The Tiptap JSON content
  • chunkIndex (number): The index of the chunk where the range starts

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)
    • chunkingFunction? ((doc: string) => string[]): Custom chunking function

Returns

  • string[]: Array of text chunks

Example

// Chunk text by 1000 characters
const chunks = toolkit.getTextChunks()

getHtmlChunks

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

Parameters

  • options? (GetTextChunksOptions): Options for the getHtmlChunks method
    • chunkSize? (number): Max characters per chunk. Defaults to 32,000 characters (8000 tokens * 4 characters per token)
    • chunkingFunction? ((doc: string) => string[]): Custom chunking function

Returns

  • string[]: Array of HTML chunks

Example

// Chunk HTML by 1000 characters
const chunks = toolkit.getHtmlChunks()

getJsonChunks

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

Parameters

  • options? (GetTextChunksOptions): Options for the getJsonChunks method
    • chunkSize? (number): Max characters per chunk. Defaults to 32,000 characters (8000 tokens * 4 characters per token)
    • chunkingFunction? ((doc: string) => string[]): Custom chunking function

Returns

  • any[]: Array of Tiptap JSON chunks

Example

// Chunk Tiptap JSON by 1000 characters
const chunks = toolkit.getJsonChunks()