Skip to content

feat(docs): add rich formatting support (font, color, alignment)#479

Closed
mmaghsoodnia wants to merge 2 commits intoopenclaw:mainfrom
mmaghsoodnia:feat/docs-formatting
Closed

feat(docs): add rich formatting support (font, color, alignment)#479
mmaghsoodnia wants to merge 2 commits intoopenclaw:mainfrom
mmaghsoodnia:feat/docs-formatting

Conversation

@mmaghsoodnia
Copy link
Copy Markdown

Summary

  • Adds a new docs format subcommand for applying rich text formatting to existing text in Google Docs
  • Adds formatting flags (--font-family, --font-size, --text-color, --bg-color, --bold, --italic, --underline, --strikethrough, --alignment, --line-spacing) to docs write
  • Uses Google Docs API batchUpdate with UpdateTextStyle and UpdateParagraphStyle requests

docs format command

Target text by content match or apply to entire document:

# Format specific text
gog docs format <docId> --match "Hello World" --bold --text-color "#FF0000"

# Format all occurrences
gog docs format <docId> --match "important" --match-all --underline --bg-color "#FFFF00"

# Format entire document
gog docs format <docId> --font-family "Georgia" --font-size 14

docs write formatting

Apply formatting after writing content:

gog docs write <docId> --text "Hello" --font-family "Arial" --font-size 16 --text-color "#003399"

Implementation

  • FormattingOpts struct + buildFormattingRequests() in docs_formatter.go — builds typed API requests with proper field masks
  • DocsFormatCmd in docs_edit.go — reuses existing findTextInDoc/findTextMatches for text search
  • Reuses existing parseHexColor from docs_sed_helpers.go via hexToOptionalColor wrapper
  • Supports ForceSendFields for explicitly setting boolean values to false (e.g., removing bold)

Test plan

  • gog docs format <id> --match "text" --bold --text-color "#FF0000" — verify bold red text in browser
  • gog docs format <id> --match "text" --match-all --underline — verify all occurrences underlined
  • gog docs format <id> --alignment center — verify whole doc centered
  • gog docs write <id> --text "Hello" --font-family Georgia --font-size 16 — verify font applied
  • gog docs format <id> --match "nonexistent" — verify error message

🤖 Generated with Claude Code

mehdi maghsoodnia and others added 2 commits March 26, 2026 12:07
Add `docs format` subcommand and formatting flags to `docs write` for
applying rich text formatting via the Google Docs API batchUpdate.

New `docs format` command:
- Target text by content match: --match "text" (first occurrence)
- Format all occurrences: --match-all
- Apply to entire document when no --match given
- Reuses findTextInDoc/findTextMatches for text search

Formatting flags (shared by `docs write` and `docs format`):
- --font-family: font family (e.g. Arial, Georgia)
- --font-size: font size in points
- --text-color: text color as hex (#RRGGBB)
- --bg-color: background highlight color as hex
- --bold, --italic, --underline, --strikethrough
- --alignment: left|center|right|justified
- --line-spacing: line spacing percentage (e.g. 150 = 1.5x)

Implementation:
- FormattingOpts struct and buildFormattingRequests() in docs_formatter.go
- Builds UpdateTextStyle and UpdateParagraphStyle requests with proper
  field masks, including ForceSendFields for false boolean values
- Reuses existing parseHexColor from docs_sed_helpers.go via wrapper

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add --show-anchors flag to `docs comments list` to expose kix anchor
  data from UI-created comments, enabling the only known workaround for
  inline comment anchoring.
- Improve --quoted and --anchor help text to clearly document the Google
  API limitation: programmatic comment anchoring does not work.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@steipete
Copy link
Copy Markdown
Collaborator

steipete commented May 4, 2026

Landed the formatting part on main as b4d6f55.

I rewrote the patch a bit before landing so formatting uses explicit Docs API ranges instead of formatting the whole document after docs write. The shipped behavior now adds:

  • docs format for whole-doc or --match / --match-all formatting
  • plain-text docs write formatting flags that apply only to the inserted range
  • validation for colors/alignment/conflicting set/clear flags
  • generated command docs, README examples, and changelog credit

Verified with:

  • go test ./internal/cmd -run 'TestDocsFormat|TestDocsWriteFormatsInsertedRangeOnly' -count=1
  • make lint
  • make test
  • make docs-site
  • make build
  • make ci
  • live Google Docs smoke against clawdbot@gmail.com: create doc, formatted write, docs format --match-all, raw style readback, trash doc
  • live clear/paragraph smoke: --no-bold, --italic, --alignment center, --line-spacing 150, raw readback, trash doc

I did not include the unrelated --show-anchors comment-help change from the branch here so this stays scoped to rich formatting. Thanks @mmaghsoodnia.

@steipete
Copy link
Copy Markdown
Collaborator

steipete commented May 4, 2026

Closing as landed on main in b4d6f55. Thanks again @mmaghsoodnia.

@steipete steipete closed this May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants