feat(docs): add docs.appendMarkdown for formatted writes without index math#401
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request introduces the docs.appendMarkdown tool, allowing users to append markdown-formatted content directly to a Google Doc as natively formatted text. It includes a custom markdown parser utility and corresponding unit tests. The review feedback highlights a bug where appending to a non-empty document merges the first markdown block with the existing text, suggesting prepending a newline when insertAt > 1 and updating the affected tests. Additionally, it is recommended to support __ for bold text formatting to better align with standard markdown conventions.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
…x math Implements gemini-cli-extensions#400. Converts a markdown string into natively formatted Docs content in one call: headings (#-######), bold, italic, strikethrough, inline code, links, bullet and numbered lists. A pure parser module (utils/markdown.ts) produces blocks with inline-format ranges over stripped plain text; the service issues one insertText followed by one batchUpdate whose updateParagraphStyle / updateTextStyle / createParagraphBullets requests are computed from parse offsets, so character-index arithmetic never reaches the model. Optional tabId follows the docs.writeText convention. Horizontal rules are skipped with a count in the response (no Docs API request exists for them); tables degrade to plain paragraphs. No new OAuth scopes.
…_bold__ support Addresses gemini-code-assist review: when appending to a non-empty body, insertAt sits just before the last paragraph's final newline, so the first markdown block merged into that paragraph and its block style leaked onto existing text; a prepended newline (with offsets shifted accordingly) keeps appends isolated. Also adds __double-underscore__ bold per standard markdown, with parser coverage.
Refinement mirrored from downstream review of the same logic: keying the prefix off insertAt > 1 also prepended a newline when the body already ended in an empty paragraph, leaving a stray blank line between existing content and the appended markdown. Now keyed off the last element's startIndex (separator only when inserting inside a non-empty last paragraph), with a test pinning the empty-trailing-paragraph case and realistic startIndex in the existing mocks.
33fb763 to
f8ed5c9
Compare
|
appendMarkdown as a dedicated individual tool seems odd. I would try to propose something more akin to formatting that is generic and markdown as a param to the tool is just one option for the model to format the input |
Summary
Fixes #400. Adds
docs.appendMarkdown(documentId, markdown, tabId?): converts markdown into natively formatted Docs content in a single call.Today the only way to produce formatted content is the two-step
docs.writeText+docs.formatTextflow, where the model hand-computes 1-based character indices (thegoogle-docsskill spends most of its length teaching that arithmetic). For agents, markdown is the native output format — this removes the index math entirely.Design
utils/markdown.ts): blocks (headings 1-6, bullets, numbered, paragraphs, horizontal rules) with inline formats (**bold**,*italic*/_italic_,~~strikethrough~~,`code`,[links](url)) recorded as character ranges over the stripped text. Single-pass, non-nesting semantics, documented in the module.insertTextwith the full stripped text, then one batch ofupdateParagraphStyle/updateTextStyle/createParagraphBulletsrequests computed from parse offsets. Consecutive list items of the same kind merge into single bullet ranges.tabIdoptional with the same convention/discovery asdocs.writeText(flattened tab walk incl. child tabs; clearTab with ID x not founderror).documentsalready covers it). Registered in thedocs.writefeature group.docs.formatTextremains the right tool for fine-grained edits to existing text; this covers the much more common "write new formatted content" path.What's included
utils/markdown.tsparser +DocsService.appendMarkdownfollowing the existing service conventions (logging,isErrorshape,TABS_FIELD_MASKreuse)docs/index.mdentryVerification
All passing: 30 suites, 635 tests (619 existing + 16 new), eslint/prettier/tsc clean.
Made with Cursor