replaceRangeWithMarkdown
Replace one section of a Google Doc with parsed Markdown, including headings, lists, tables, and links, while leaving content outside the chosen range untouched.
Instructions
Best for rewriting ONE section of a document with real structure. Replaces a caller-chosen range with content parsed from markdown, building true headings, nested bullet/numbered lists, tables, links, and the rich markdown HTML extensions — everything replaceDocumentWithMarkdown builds, scoped to a range. Address the range three ways: explicit {startIndex,endIndex} from readDocument with format='index'; {afterHeading} (or {headingId}) to replace everything under a heading, up to the next heading of the same or shallower level; or {textToFind}. Set startIndex == endIndex to INSERT markdown at an index without deleting anything. Use this instead of modifyText whenever the replacement is multi-line or contains lists — modifyText is text-only and flattens list nesting. Use replaceDocumentWithMarkdown when you are rewriting the whole body, and appendMarkdown to add to the end. Content outside the range is left untouched, including images, horizontal rules, and other sections; only content inside the range is checked for markdown fidelity, and by default a range holding an image or footnote is refused rather than silently flattened (onFidelityLoss). Pass dryRun to see the resolved range and what would be lost without writing. The write is guarded by the revision the read saw. If the document changed since you read it, an afterHeading/headingId or textToFind target is re-resolved against the current document and proceeds when the change did not touch the section; an explicit startIndex/endIndex is refused unless the change landed strictly after the range, since explicit indices have no anchor to re-resolve. Refusals name what changed and where.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"documentId": "<documentId>",
"target": "<target>"
},
"name": "replaceRangeWithMarkdown"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tabId | No | The ID of the specific tab to edit. If not specified, edits the first tab. | |
| dryRun | No | Resolve and validate the range, report what would change, and make no writes. | |
| target | Yes | The range to replace: explicit {startIndex,endIndex} (from readDocument format='index'), {afterHeading|headingId} for a whole section, or {textToFind} for content located by text. | |
| filePath | No | Path to a local markdown file to use as the replacement content. Takes precedence over markdown. | |
| markdown | No | Inline markdown to put in the range. Prefer filePath for content longer than ~2000 characters. | |
| documentId | Yes | The document ID — the long string between /d/ and /edit in a Google Docs URL. | |
| readHandle | No | Capability returned by a previous readDocument call for this document (and tab). Required over HTTP on the 2026-07-28 runtime: it authorizes the write and pins it to the revision that read saw. Omit it on stdio to use that connection's most recent read. | |
| onFidelityLoss | No | What to do when the range contains content markdown cannot represent (images, footnotes, a generated table of contents). 'block' (default) refuses and names what would be lost; 'warn' proceeds and reports it. Content OUTSIDE the range is never inspected and never at risk. | block |
| preserveHeading | No | Heading targets only. True (default) replaces the content BELOW the heading and keeps the heading itself; false moves the range start to the heading paragraph so the heading is replaced too. | |
| expectedRevisionId | No | Optional compare-and-write assertion: the write is refused unless the read handle was issued for this revision. It is an assertion only, never authorization. |