insert_document
Insert a full document into another at a chosen position, merging chapters into one manuscript. Reconciles styles, tables, footnotes, tracked changes; blocks unsupported content.
Instructions
Insert the ENTIRE body of source_path into target_path at one position, with full resource reconciliation: the document-assembly tool for merging chapter files into one manuscript. com_merge_documents only concatenates whole files into a new one; copy_table transplants a single table.
Position (exactly one): after_index is a body ITEM index, counting paragraphs AND tables together in document order (unlike the paragraph-only indices elsewhere); insertion lands after that item. after_anchor matches a paragraph whose FULL plain text equals the anchor; several matches refuse and list every location, so recurring heading text cannot land content at the wrong spot (prefer after_index for structural work). at_end appends after the last body item.
Carried: tables, images, charts, hyperlinks, lists (fresh numbering), footnotes/endnotes (new ids), bookmarks (remapped, collisions renamed and reported), tracked changes, equations. Styles reconcile BY NAME (the target's formatting wins on a match; unmatched styles are cloned in with dependency chains). The source's section setup is never carried; mid-content section breaks and comment references are stripped and reported. OLE objects, ActiveX, subdocuments, and altChunks refuse the whole insertion, naming the blocker; nothing is half-applied.
formatting mirrors Word's paste modes on the carried copies: 'source' (default) keeps direct formatting; 'merge' keeps bold/italic/emphasis but strips direct font/size/color/spacing/indent overrides; 'destination' strips all direct formatting except structural properties. Returns per-resource counts, style remaps, bookmark renames, and the occupied body-item range. The source file is never modified. Auto-backup: prev/anchor slots in .ks4w-backups (backup=False skips rotation only); atomic validated save. Refuses documents open in Word.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| at_end | No | ||
| backup | No | ||
| formatting | No | source | |
| after_index | No | ||
| source_path | Yes | ||
| target_path | Yes | ||
| after_anchor | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||