This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/document-authoring/editing-content/programmatic-editing.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Programmatic document editing in Document Authoring

Document Authoring provides a programmatic API for reading and updating document content with DocAuthDocument.transaction(). Transactions are atomic and isolated until committed. Each transaction gives you access to a draft document you can inspect or modify.

Before you start, make sure the Document Authoring library is installed and running in your app. If you haven’t set it up yet, refer to the getting started guide.

The examples omit error handling. Add it before you use this code in production.

Run a transaction

Use DocAuthDocument.transaction() to work with a draft document. Return true to commit the transaction:

// Assuming the `editor` instance exists.
const currentDoc = editor.currentDocument();
await currentDoc.transaction(async ({ draft }) => {
const paragraph = draft.body().content().addParagraph();
paragraph.asTextView().setText('Created in a transaction.');
return true;
});

Choose an editing operation

Run every programmatic edit inside a transaction. Use these guides for specific editing tasks:

Learn more