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 /dokumente and other shared document lists, a primary click opens supported writing documents directly in Word Editor; the eye action still opens preview. /dokumente also exposes Neues 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 (slug word-canvas, entry index.html, renderer react, icon file-text). The React UI is src/components/modules/word-canvas-module.tsx, hosted by src/app/(app)/modules/[slug]/page.tsx; the bundled frontend assets remain in bundled-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

  • Dokumente back 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-pdf route, and stores the generated PDF as a sibling document.

Work with DOCX, DOC, TXT, and Markdown

  • DOCX import uses mammoth to 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 .docx output 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 .doc files are accepted as inputs. On first open, the backend converts the file locally with LibreOffice headless when available, creates an editable .docx beside the original file, updates the dokumente row to the .docx path/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 .txt files 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 Word entry (visible when word-canvas is installed) that opens a native document list backed by GET /docs. iPhone opens documents in a full-screen native editor; macOS uses a list/detail split pane. Creating a Word document from the native Dokumente screen also opens the native editor.
  • Editor: SwiftUI-wrapped UITextView/NSTextView with a hand-rolled HTML ↔ NSAttributedString codec (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/:id with html + text; the server builds the .docx from 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_documents
    • word_get_document (read the active document)
    • word_replace_document_content (replace full document content)
  • Agent rewrites that send plain text through word_replace_document_content reuse 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.updated so the active editor updates in place and flashes the changed document surface live instead of requiring a manual reload.
  • The shared documents_create agent tool can create a filled standard vollmacht Word draft from Mandant context by passing template_key="vollmacht" and mandant_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 dokumente and mandanten and resolves/enforces document path safety inside /app/workspace/mandanten.
  • Legacy .doc conversion depends on a local LibreOffice (soffice) binary; override discovery with LIBREOFFICE_BINARY / LIBREOFFICE_PATH if 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; direct docId opens do not depend on the current dropdown page)
  • POST /docs (create a new writing document in inbox; DOCX by default, Markdown/TXT via extension)
  • 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 core POST /api/documents/:id/export-pdf route, forwarding the caller's auth headers)
  • GET /health (module health)

Troubleshooting

  • A legacy .doc opens with plain, unstyled text: LibreOffice could not convert the file, so the OLE/CFB text importer extracted raw text as a fallback. Check that soffice/libreoffice is 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.