Expand Markdown support for Google Docs#40
Merged
a-bonus merged 3 commits intoa-bonus:mainfrom Feb 4, 2026
Merged
Conversation
Enable users to edit Google Docs using familiar markdown syntax, allowing for: - Offline editing in preferred text editors (VS Code, Vim, etc.) - Version control of document content with Git - Batch processing and automation via scripts - Faster editing with markdown's concise syntax This addresses a key workflow limitation: the existing text editing tools (appendToGoogleDoc, insertText) only accept plain text, requiring separate formatting operations. Users requested the ability to work with markdown as an interchange format, enabling a "retrieve as markdown → edit → apply back" workflow. Added two new MCP tools (bringing total from 42 to 44): - replaceDocumentWithMarkdown: Replace entire document with markdown content - appendMarkdownToGoogleDoc: Append markdown content to document end 1. **markdown-it Parser** (src/markdownParser.ts) - Lightweight, fast markdown parser (~20KB vs 500KB alternatives) - Parses markdown into token stream for sequential processing - Helper functions for extracting heading levels and link URLs 2. **Conversion Engine** (src/markdownToGoogleDocs.ts) - Two-pass algorithm: insert text → apply formatting - Tracks formatting state through nested markdown (bold + italic + links) - Generates Google Docs API batch update requests - Supports: headings (H1-H6), bold, italic, strikethrough, links, lists 3. **Batch Splitting** (src/googleDocsApiHelpers.ts) - executeBatchUpdateWithSplitting handles Google's 50-request limit - Separates insert and format operations for correct execution order - Logs progress for large documents (100+ operations) - Headings: # H1 through ###### H6 → HEADING_1 through HEADING_6 - Bold: **text** or __text__ - Italic: *text* or _text_ - Strikethrough: ~~text~~ - Links: [text](url) - Lists: Bullet (-, *) and numbered (1., 2.) - Nested formatting: ***bold italic***, **bold [link](url)** Created comprehensive test suite (tests/markdown.test.js) with 17 tests covering: - Basic formatting (bold, italic, strikethrough) - Links and nested formatting - Headings (H1-H6) - Lists (bullet and numbered) - Mixed content documents - Index tracking and tab support - Edge cases (empty input, plain text, whitespace) All tests pass ✓ - CLAUDE.md: Added Markdown category, workflow guide, tool reference - README.md: Added Markdown Support feature section - SAMPLE_TASKS.md: Added Task a-bonus#16 demonstrating markdown workflow
…tWithMarkdown Root cause: Google Docs API applies all requests in a batchUpdate against the INITIAL document state, not sequentially. When delete and insert operations were in the same batch, inserts used indices calculated for empty document but were applied to the original document, causing corruption. Solution: Execute delete operation in a completely separate batchUpdate call before generating and executing markdown conversion requests. Changes: - Split replaceDocumentWithMarkdown into 3 API calls: 1. Delete existing content 2. Convert markdown (indices now correct for empty doc) 3. Insert and format new content - Add debug logging to track operation flow - Update executeBatchUpdateWithSplitting with detailed logging
Owner
|
sick, thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I wanted to use Claude code to revise documents in Google Docs. Markdown was a reasonable interchange format to work with.
This pull request adds comprehensive markdown support to the Google Docs MCP server, enabling users to read, edit, and write documents using markdown syntax. It introduces two new tools for converting markdown to Google Docs format, updates documentation to reflect these capabilities, and enhances batch update handling for large document changes. The changes also include improvements to formatting functions and add required dependencies for markdown parsing.
Major Features:
Markdown Support & Tools:
replaceDocumentWithMarkdownandappendMarkdownToGoogleDoc, allowing users to replace or append document content using markdown syntax with full formatting (headings, bold, italic, strikethrough, links, lists, etc.).src/markdownParser.tsfor analyzing and parsing markdown content.Batch Update Improvements:
executeBatchUpdateWithSplittinginsrc/googleDocsApiHelpers.tsto efficiently handle large sets of requests by splitting them into delete, insert, and format operations, improving reliability for bulk document updates.Formatting & Styling Enhancements:
tabIdparameter, enabling precise formatting in multi-tab documents. [1] [2] [3] [4]