replaceDocumentWithMarkdown
Replaces a Google Docs document body with Markdown content, including headings, lists, tables, and supported formatting. Use it to rewrite entire documents from edited Markdown.
Instructions
Best for rewriting entire sections or full documents. Replaces the entire document body with content parsed from markdown. Supports headings, bold, italic, strikethrough, links, tables, bullet/numbered lists, and rich markdown HTML extensions for underline, color, highlight, font, alignment, and blockquotes. Does not support markdown images or raw HTML outside those listed extensions; unsupported content is omitted and reported as warnings in the result. Use insertImage for images. Use readDocument with format='markdown' first to get the current content, edit it, then call this tool to apply changes. PREFERRED WORKFLOW for large edits: readDocument saves the content to a local working-copy file and returns its path — edit that file, then pass it here as filePath instead of inline markdown, to avoid truncation and get a reviewable diff before pushing. DESTRUCTIVE METADATA WARNING: this rebuilds the whole body, which Google Docs treats as new content, so unresolved comments anchored in the replaced text lose their anchors and every headingId is regenerated, breaking in-document links that pointed at headings. Both are enumerated before the delete and reported (onCollateral='block' refuses instead of warning), and the response carries the post-write heading map so links can be repointed. Pass dryRun to see the proposed-vs-current unified diff and the full collateral list without writing anything. For several small scattered edits, use batchModifyText — it edits in place in one atomic batch and costs no comment anchors or heading ids. To rewrite ONE section instead of the whole body — keeping images, rules, and every other section untouched — use replaceRangeWithMarkdown, which builds the same structure inside a caller-chosen range. For small single-location edits (one line or paragraph), use modifyText instead. To add content without rewriting, use appendMarkdown. Inserted text carries the document's default text color explicitly, when the document defines one.
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>"
},
"name": "replaceDocumentWithMarkdown"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tabId | No | The ID of the specific tab to replace content in. If not specified, replaces content in the first tab. | |
| dryRun | No | Preview only: returns the proposed-vs-current unified diff, the deletion summary, and the full comment/heading-link collateral list, and performs NO delete, no cleanup, no insert, and no workspace write. | |
| filePath | No | Path to a local markdown file to use as content. Takes precedence over the markdown parameter. Use this for large documents to avoid truncation. | |
| markdown | No | Inline markdown content. Prefer filePath instead for content longer than ~2000 characters — use the working-copy path returned by readDocument, edit that file, then pass it here. | |
| 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. | |
| onCollateral | No | What to do when the replace would orphan unresolved comment anchors or break in-document heading links. 'warn' (default) proceeds and reports them; 'block' refuses and lists them. Under 'block', a collateral check that could not run (for example comments could not be listed) is also a refusal, since a check that did not run cannot clear anything. | warn |
| preserveTitle | No | If true, preserves the first heading/title and replaces content after it. | |
| 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. | |
| firstHeadingAsTitle | No | If true (default), the first H1 heading (# ...) in the markdown is styled as a Google Docs TITLE instead of Heading 1. Useful when the markdown represents a full document whose first line is the document title. Set to false if the first H1 should remain a Heading 1. |