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 thegetTextSelection
methodchunkOptions?
(GetTextChunksOptions
): Used to computechunkIndex
in selection resultchunkSize?
(number
): Maximum size of each chunk in number of characters. Defaults to 32,000 characterschunkingFunction?
((doc: string) => string[]
): Custom chunking function
Returns
selection
(string
): The selected text content as a plain stringchunkIndex
(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 thegetHtmlSelection
methodchunkOptions?
(GetTextChunksOptions
): Used to computechunkIndex
in selection resultchunkSize?
(number
): Maximum size of each chunk in number of characters. Defaults to 32,000 characterschunkingFunction?
((doc: string) => string[]
): Custom chunking function
Returns
selection
(string
): The selected HTML contentchunkIndex
(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 computechunkIndex
in selection resultchunkSize?
(number
): Maximum size of each chunk in number of characters. Defaults to 32,000 characterschunkingFunction?
((doc: string) => string[]
): Custom chunking function
Returns
selection
(any
): The selected Tiptap JSON contentchunkIndex
(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 fromfrom
(number
): Start positionto
(number
): End position
options?
(GetTextRangeOptions
): Options for thegetTextRange
methodchunkOptions?
(GetTextChunksOptions
): Used to computechunkIndex
chunkSize?
(number
): Maximum size of each chunk in number of characters. Defaults to 32,000 characterschunkingFunction?
((doc: string) => string[]
): Custom chunking function
Returns (GetJsonSelectionResult
)
content
(string
): The text content as a plain stringchunkIndex
(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 fromfrom
(number
): Start positionto
(number
): End position
options?
(GetTextRangeOptions
): Options for thegetHtmlRange
methodchunkOptions?
(GetTextChunksOptions
): Used to computechunkIndex
chunkSize?
(number
): Maximum size of each chunk in number of characters. Defaults to 32,000 characterschunkingFunction?
((doc: string) => string[]
): Custom chunking function
Returns
content
(string
): The HTML content as a stringchunkIndex
(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 fromfrom
(number
): Start positionto
(number
): End position
options?
(GetTextRangeOptions
): Options for thegetJsonRange
methodchunkOptions?
(GetTextChunksOptions
): Used to computechunkIndex
chunkSize?
(number
): Maximum size of each chunk in number of characters. Defaults to 32,000 characterschunkingFunction?
((doc: string) => string[]
): Custom chunking function
Returns
content
(any
): The Tiptap JSON contentchunkIndex
(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 thegetTextChunks
methodchunkSize?
(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 thegetHtmlChunks
methodchunkSize?
(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 thegetJsonChunks
methodchunkSize?
(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()