Skip to content

feat: Support markdown formatting in docs +write helper #380

@dd-rK

Description

@dd-rK

Summary

The gws docs +write helper currently inserts plain text only. When writing markdown content to a Google Doc, all formatting (headings, bold, italic, code blocks, lists, tables) is lost — the raw markdown syntax appears as literal text.

Use Case

AI agents and CLI users frequently generate markdown content (RFCs, design docs, meeting notes) and need to push it to Google Docs with proper formatting. Currently, the only workaround is to create an empty doc via the API and manually paste markdown through the browser (right-click → paste from markdown). This breaks automation workflows.

Proposed Solution

Add a --content-format flag to +write (and potentially a new +write-md helper):

# Current (plain text only)
gws docs +write --document DOC_ID --text '# Heading\n\n**Bold text**'

# Proposed (markdown rendered)
gws docs +write --document DOC_ID --text '# Heading\n\n**Bold text**' --content-format markdown

Implementation approach

  1. Add pulldown-cmark crate for markdown parsing
  2. Parse markdown input into an AST
  3. Convert AST nodes into Google Docs API batchUpdate requests:
    • #updateParagraphStyle with namedStyleType: "HEADING_1"
    • **text**updateTextStyle with bold: true
    • *text*updateTextStyle with italic: true
    • `code`updateTextStyle with font family monospace
    • - itemcreateParagraphBullets
    • Code blocks → monospace font + background color
  4. Track 1-based character indices for all formatting ranges
  5. Emit all requests in a single batchUpdate call

MVP scope (v1)

  • Headings (H1-H6)
  • Bold, italic, inline code
  • Unordered and ordered lists
  • Code blocks (monospace)
  • Links

Future scope

  • Tables
  • Images (inline via insertInlineImage)
  • Nested lists
  • Horizontal rules

Relevant Code

The current +write implementation is in src/helpers/docs.rs, specifically the build_write_request() function which constructs a single insertText request. The change would extend this function (or add a parallel path) to generate formatting requests alongside text insertion.

Alternatives Considered

  • Google Docs native markdown paste: Works in the browser UI but not via API
  • Drive API import with conversion: Uploads files but doesn't reliably convert markdown formatting
  • Apps Script: Works but requires additional setup and is not CLI-native

Context

This was discovered while building HIPAA-compliant architecture docs that needed to be shared via Google Docs. The inability to programmatically create formatted Google Docs from markdown is a gap in the CLI that affects both human users and AI agent workflows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions