Document lifecycle
open
Open a document from a file, URL, or buffer.
source
string | File | Blob | Buffer
Document source. Omit for a blank document.
'docx', 'text', or 'html'
HTML content (for text/html mode)
ProseMirror JSON to use instead of DOCX parsing
await editor . open ( docxFile );
await editor . open ( null , { mode: 'html' , html: '<p>Hello</p>' });
This is the instance method. For one-liner creation, use the static Editor.open() factory — see Configuration .
close
Close the current document. The editor instance stays alive for reuse.
editor . close ();
await editor . open ( anotherFile );
save
Save back to the original source path (Node.js only).
Replace fields with values
fieldsHighlightColor
string
default: "'#FFFF00'"
Field highlight color
await editor . save ();
await editor . save ({ isFinalDoc: true });
Throws if the editor was opened from a Blob/Buffer instead of a file path. Use saveTo() or exportDocument() instead.
saveTo
Save to a specific path (Node.js only).
await editor . saveTo ( '/path/to/output.docx' );
exportDocument
Export as a Blob (browser) or Buffer (Node.js).
const blob = await editor . exportDocument ();
const blob = await editor . exportDocument ({ isFinalDoc: true });
exportDocx
Lower-level export with additional control.
Returns: Promise<Blob> in the browser, Promise<Buffer> in headless/Node.js mode.
Replace fields with values
'external', 'clean', or custom
fieldsHighlightColor
string
default: "'#FFFF00'"
Field highlight color
const blob = await editor . exportDocx ({
isFinalDoc: true ,
commentsType: 'clean'
});
replaceFile
Replace the current DOCX with a new file.
await editor . replaceFile ( newDocxFile );
Content
getHTML
const html = editor . getHTML ();
const html = editor . getHTML ({ unflattenLists: true });
getJSON
const json = editor . getJSON ();
getMarkdown
const md = await editor . getMarkdown ();
replaceContent
Replace the entire document content.
editor . replaceContent ( proseMirrorJson );
replaceNodeWithHTML
Replace a specific node with HTML.
const table = editor . getNodesOfType ( 'table' )[ 0 ];
editor . replaceNodeWithHTML ( table , '<table>...</table>' );
Editor control
mount / unmount
editor . mount ( document . querySelector ( '#editor' ));
editor . unmount (); // Keeps instance alive
destroy
Permanently destroy the editor.
Irreversible. The instance cannot be used after this.
focus / blur
editor . focus ();
editor . blur ();
setEditable
editor . setEditable ( false ); // Read-only
editor . setEditable ( true ); // Editable
setDocumentMode
editor . setDocumentMode ( 'editing' ); // Full editing
editor . setDocumentMode ( 'suggesting' ); // Track changes
editor . setDocumentMode ( 'viewing' ); // Read-only
Commands
Deprecated. Editor commands (editor.commands) will be removed in a future version. Use the Document API (editor.doc) for programmatic document operations. See available operations for the full list.
All commands are accessed via editor.commands:
// Formatting
editor . commands . toggleBold ();
editor . commands . toggleItalic ();
editor . commands . toggleUnderline ();
// Tables
editor . commands . insertTable ({ rows: 3 , cols: 3 });
// Selection
editor . commands . setTextSelection ({ from: 10 , to: 20 });
editor . commands . selectAll ();
insertContent
Insert content with automatic format detection.
'html', 'markdown', 'text', or 'schema'
Insert position (defaults to cursor)
Callback for HTML elements dropped during parsing. Receives { tagName, outerHTML, count }[]. Falls back to the editor-level option if not set.
Log dropped elements via console.warn. Falls back to the editor-level option if not set.
editor . commands . insertContent ( htmlContent , { contentType: 'html' });
editor . commands . insertContent ( markdownText , { contentType: 'markdown' });
editor . commands . insertContent ( 'Plain text' , { contentType: 'text' });
HTML and Markdown inline styles are stripped on import to ensure Word compatibility.
const { documentGuid , isModified , version } = editor . getMetadata ();
getDocumentIdentifier
Get a stable identifier (GUID or content hash).
const id = await editor . getDocumentIdentifier ();
isDocumentModified
if ( editor . isDocumentModified ()) {
// Prompt user to save
}
Schema
getSchemaSummaryJSON
Generate a summary of the document schema. Useful for AI agents that need to understand the document structure.
const summary = await editor . getSchemaSummaryJSON ();
Position & coordinates
getElementAtPos
Get the DOM element at a document position.
const element = editor . getElementAtPos ( 42 );
getNodesOfType
Get all nodes of a specific type.
const tables = editor . getNodesOfType ( 'table' );
const paragraphs = editor . getNodesOfType ( 'paragraph' );
isActive
Check if a node or mark is active.
editor . isActive ( 'bold' );
editor . isActive ( 'heading' , { level: 2 });
getAttributes
Get attributes of the active node or mark.
const attrs = editor . getAttributes ( 'link' );
console . log ( attrs . href );
Page & layout
getPageStyles
const styles = editor . getPageStyles ();
updatePageStyle
editor . updatePageStyle ({
pageMargins: { top: '1in' , bottom: '1in' , left: '1in' , right: '1in' }
});
Search
const results = editor . commands . search ( 'hello' );
const results = editor . commands . search ( / \d {3} - \d {4} / gi );
editor . commands . goToSearchResult ( results [ 0 ]);
Properties
Property Type Description lifecycleStatestring'initialized', 'documentLoading', 'ready', 'saving', 'closed', 'destroyed'isEditablebooleanWhether editor accepts input isDestroyedbooleanWhether editor has been destroyed isFocusedbooleanWhether editor has focus docChangedbooleanWhether any edits have been made currentTotalPagesnumber | undefinedPage count after the first layout completes. undefined until then. Use the pagination-update event to know when it’s available. sourcePathstring | nullSource file path (null if opened from Blob)