Word Editor
Bundled rich-text module for DOCX/DOC/TXT/MD editing with native Word-style formatting controls.
What it does
Word Editor (word-canvas) is a bundled module for editing writing documents (.docx, legacy .doc, .txt, .md) directly in Clapilot with Word-style formatting controls. It imports existing Word documents faithfully, saves DOCX back as real OOXML while keeping the source document's typography, and lets the agent read and rewrite the active document live.
How to open it
- Open the module from the Clapilot module menu; the route is
/modules/word-canvas. - In
/dokumenteand other shared document lists, a primary click opens supported writing documents directly in Word Editor; the eye action still opens preview./dokumentealso exposesNeues Dokument, which can create a Word or Markdown document and route directly into Word Editor. - Deep links from document lists are supported:
/modules/word-canvas?docId=<dokument-id>. - Uploads can go through the Clapilot inbox endpoint
POST /api/documents/inbox. - Manifest:
bundled-modules/word-canvas/module.json(slugword-canvas, entryindex.html, rendererreact, iconfile-text). The React UI issrc/components/modules/word-canvas-module.tsx, hosted bysrc/app/(app)/modules/[slug]/page.tsx; the bundled frontend assets remain inbundled-modules/word-canvas/but the app renders the module directly in the main React tree.
Key workflows
Format a document
The rich-text canvas supports:
- Font family and font size
- Bold, italic, underline, strikethrough
- Headings and block quote styles
- Alignment (left/center/right/justify)
- Ordered and unordered lists
- Indent / outdent
- Text color and highlight color
- Link create/remove
- Undo / redo
Toolbar actions
Dokumenteback action returns to the shared documents list.- A PDF icon action saves dirty changes first, exports the current document through the local
/api/documents/:id/export-pdfroute, and stores the generated PDF as a sibling document.
Work with DOCX, DOC, TXT, and Markdown
- DOCX import uses
mammothto convert existing Word documents to editable HTML. Import normalization keeps empty paragraphs as visible editable blank lines and applies richer block/list spacing in the React canvas so Word layouts survive faithfully. - DOCX export generates OOXML (
document.xml,styles.xml,numbering.xml) and packs the.docxoutput via ZIP. Saves infer the active document's dominant font defaults and heading sizes before rebuild, so agent-driven rewrites keep the source document's typography instead of falling back to generic Calibri-only output. - Legacy
.docfiles are accepted as inputs. On first open, the backend converts the file locally with LibreOffice headless when available, creates an editable.docxbeside the original file, updates thedokumenterow to the.docxpath/MIME type, and then loads it through the normal DOCX editor pipeline. If LibreOffice cannot convert a damaged or unusual file, Word Editor falls back to the local OLE/CFB text importer so the document can still open where possible. - Plain
.txtfiles load and save as escaped plain text in the same canvas. - Markdown documents (
.md,.markdown) render Markdown structure in the canvas, including headings, emphasis, links, block quotes, lists, code blocks, horizontal rules, images, and simple tables. Saving serializes the edited rich-text HTML back to Markdown so the file remains a Markdown file.
Native Apple client (iOS/macOS)
The Apple client ships a fully native Word module instead of a web view:
- Entry: the side menu shows a
Wordentry (visible whenword-canvasis installed) that opens a native document list backed byGET /docs. iPhone opens documents in a full-screen native editor; macOS uses a list/detail split pane. Creating a Word document from the nativeDokumentescreen also opens the native editor. - Editor: SwiftUI-wrapped
UITextView/NSTextViewwith a hand-rolled HTML ↔NSAttributedStringcodec (Sources/Clapilot/Support/WordHTML.swift,WordDocCoder.swift) covering the module's sanitized HTML dialect: bold/italic/underline/strikethrough, sub/superscript, font family/size (pt), text and highlight color, links, headings h1–h3, blockquote, ordered/unordered lists, alignment, indent, line spacing, inline data-URI images, and<hr class="page-break" />. - Tables are preserved losslessly: the table HTML block passes through the native edit cycle byte-for-byte and renders as a read-only inline preview with a
Tabelle (schreibgeschützt)affordance. - Saves go through
POST /docs/:idwithhtml+text; the server builds the.docxfrom the HTML, so native and web edits stay interchangeable.
How the agent can drive it (tools)
There is no in-module chat UI; use the global Clapilot chat for document-aware assistance. Word Editor stays focused on deterministic editing and formatting.
- The live agent has direct Word Editor tools exposed through
/api/chat/live/tools:word_list_documentsword_get_document(read the active document)word_replace_document_content(replace full document content)
- Agent rewrites that send plain text through
word_replace_document_contentreuse the active document's existing paragraph, heading, quote, and list styling instead of falling back to generic HTML blocks. - Word writes emit the structured UI action
word.document.updatedso the active editor updates in place and flashes the changed document surface live instead of requiring a manual reload. - The shared
documents_createagent tool can create a filled standardvollmachtWord draft from Mandant context by passingtemplate_key="vollmacht"andmandant_id; the generated draft is saved through Word Editor and remains linked to the source Mandant.
Configuration & limits
- Supported types:
.docx, legacy.doc(converted on first open),.txt,.md/.markdown. - The module reads document and client metadata from
dokumenteandmandantenand resolves/enforces document path safety inside/app/workspace/mandanten. - Legacy
.docconversion depends on a local LibreOffice (soffice) binary; override discovery withLIBREOFFICE_BINARY/LIBREOFFICE_PATHif needed.
API endpoints exposed by module
Base: /api/modules/word-canvas/api — implementation: bundled-modules/word-canvas/api/handler.mjs.
GET /docs(list supported writing documents; directdocIdopens do not depend on the current dropdown page)POST /docs(create a new writing document in inbox; DOCX by default, Markdown/TXT viaextension)GET /docs/:id(load document content into the rich-text canvas)POST /docs/:id(save document content)POST /documents/:id/export-pdf(proxies to the corePOST /api/documents/:id/export-pdfroute, forwarding the caller's auth headers)GET /health(module health)
Troubleshooting
- A legacy
.docopens with plain, unstyled text: LibreOffice could not convert the file, so the OLE/CFB text importer extracted raw text as a fallback. Check thatsoffice/libreofficeis available in the backend container for full-fidelity conversion. - Agent rewrite lost custom fonts: DOCX saves infer dominant fonts and heading sizes from the current document; if a document mixes many fonts, the rebuild keeps the dominant ones and may normalize complex per-run styling.
