--- name: libreoffice-writer description: Use when creating, editing, formatting, exporting, or extracting LibreOffice Writer (.odt) documents via UNO, including session-based edits, structured text targets, tables, images, lists, patch workflows, and snapshots. --- # LibreOffice Writer Use the bundled `writer` modules for UNO-backed Writer document work. All paths must be **absolute**. Bundled modules live under `scripts/` in this skill directory, so set `PYTHONPATH=/scripts`. If setup or runtime issues appear, check `references/troubleshooting.md`. ## API Surface ```python # Non-session utilities create_document(path) export_document(path, output_path, format) # formats: "pdf", "docx" snapshot_page(doc_path, output_path, page=1, dpi=150) # Session (primary editing API) open_writer_session(path) -> WriterSession WriterSession methods: read_text(target: WriterTarget | None = None) -> str insert_text(text, target: WriterTarget | None = None) replace_text(target: WriterTarget, new_text) delete_text(target: WriterTarget) format_text(target: WriterTarget, formatting: TextFormatting) insert_table(rows, cols, data=None, name=None, target: WriterTarget | None = None) update_table(target: WriterTarget, data) delete_table(target: WriterTarget) insert_image(image_path, width=None, height=None, name=None, target: WriterTarget | None = None) update_image(target: WriterTarget, image_path=None, width=None, height=None) delete_image(target: WriterTarget) insert_list(items: list[ListItem], ordered: bool, target: WriterTarget | None = None) replace_list(target: WriterTarget, items: list[ListItem], ordered: bool | None = None) delete_list(target: WriterTarget) patch(patch_text, mode="atomic") -> PatchApplyResult export(output_path, format) reset() close(save=True) # Standalone patch utility patch(path, patch_text, mode="atomic") -> PatchApplyResult ``` ## Structured Targets: `WriterTarget` ```python from writer import WriterTarget WriterTarget( kind="text" | "insertion" | "table" | "image" | "list", text=None, after=None, before=None, occurrence=None, name=None, index=None, ) ``` ### Target kinds | Kind | Supported fields | Use | |---|---|---| | `text` | `text`, `after`, `before`, `occurrence` | Read, replace, delete, or format matched text | | `insertion` | `text`, `after`, `before`, `occurrence` | Insert at a resolved boundary or after a matched span | | `table` | `name` or `index` | Update/delete a table | | `image` | `name` or `index` | Update/delete an image | | `list` | `text`, `after`, `before`, `occurrence` | Replace/delete one logical list block | ### Resolution rules - Omit `target` to read the full document or append inserted content at the end. - Use `after` and `before` to constrain a search window. - Use `occurrence` when repeated text is expected; otherwise matching must be unique. - Prefer full sentences or distinctive paragraph-sized phrases for `text`, `after`, and `before` anchors; single-word anchors are often too brittle for realistic prose edits. - For table/image targets, prefer `name`; use `index` only when order is stable. - For insertion after inline text, Writer inserts at the boundary after the matched span; paragraph breaks must come from the inserted text or the session helper. ## Formatting Payload ```python from writer import TextFormatting TextFormatting( bold=None, italic=None, underline=None, font_name=None, font_size=None, color=None, # named color or integer align=None, # "left" | "center" | "right" | "justify" line_spacing=None, spacing_before=None, spacing_after=None, ) ``` Notes: - Character and paragraph formatting can be combined in one call. - Paragraph properties such as `align` apply to the full paragraph containing the match, not just the exact matched span. - At least one formatting field must be set. ## List Items ```python from writer import ListItem ListItem(text="Confirm scope", level=0) ``` - `level` is zero-based nesting. - Nesting cannot skip levels. - `ordered=True` uses a numbering style; `ordered=False` uses bullets. ## Patch DSL Use `patch()` or `session.patch()` to apply ordered operations. ```ini [operation] type = format_text target.kind = text target.text = Quarterly revenue grew 18%. target.after = Financial Summary target.before = Action Items format.bold = true format.align = center [operation] type = insert_list target.kind = insertion target.after = Action Items list.ordered = false items <