Skip to content

feat(drive): convert Markdown uploads and strip YAML frontmatter#487

Merged
steipete merged 2 commits intosteipete:mainfrom
johnbenjaminlewis:feat/drive-markdown-upload-frontmatter
Apr 20, 2026
Merged

feat(drive): convert Markdown uploads and strip YAML frontmatter#487
steipete merged 2 commits intosteipete:mainfrom
johnbenjaminlewis:feat/drive-markdown-upload-frontmatter

Conversation

@johnbenjaminlewis
Copy link
Copy Markdown
Contributor

@johnbenjaminlewis johnbenjaminlewis commented Apr 2, 2026

Summary

  • Markdown to Doc Conversion: Treat .md as convertible to native Google Docs when using gog drive upload --convert. (Uses application/vnd.google-apps.document metadata).
  • Frontmatter Handling: Strips leading YAML frontmatter (--- ... ---) by default to ensure clean Drive imports.
  • New Flag: Added --keep-frontmatter for users who want to preserve the header.
  • Implementation: Frontmatter removal is delimiter-based (no heavy YAML dependency). Centralized --- literal in internal/cmd/literals.go to satisfy goconst.
  • Documentation: Updated README and docs/spec.md to reflect new flags and existing Google Doc → Markdown export logic.

User-facing changes

  • gog drive upload file.md --convert: Creates a Google Doc; strips frontmatter.
  • gog drive upload file.md --convert --keep-frontmatter: Creates a Google Doc; keeps frontmatter.

Test plan

  • make ci
  • Unit tests: Validated stripYAMLFrontmatter, MIME conversion logic, and edge cases.
  • Manual: Verified against live Drive API (Doc creation and frontmatter stripping confirmed).

Relates to #272 (Provides a workaround via drive upload import).

Comment thread README.md
gog drive download <fileId> --out ./downloaded.bin
gog drive download <fileId> --format pdf --out ./exported.pdf # Google Workspace files only
gog drive download <fileId> --format docx --out ./doc.docx
gog drive download <fileId> --format md --out ./note.md # Google Doc → Markdown
Copy link
Copy Markdown
Contributor Author

@johnbenjaminlewis johnbenjaminlewis Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: The addition of gog drive download --format md ... to the README is for documentation completeness. I’ve included it here so that the Markdown import/export flows are documented together in the same section.

(The download as md feature was originally added in #282)

johnbenjaminlewis and others added 2 commits April 20, 2026 16:32
Map .md to Google Doc conversion with --convert, strip leading
---/--- frontmatter before upload (opt out with --keep-frontmatter),
and extend tests for convert MIME and frontmatter handling.
Co-authored-by: Ben Lewis <johnbenjaminlewis@gmail.com>
@steipete steipete force-pushed the feat/drive-markdown-upload-frontmatter branch from 213dc8a to d9bc8f5 Compare April 20, 2026 15:39
@steipete steipete merged commit 5d332f7 into steipete:main Apr 20, 2026
1 check passed
@steipete
Copy link
Copy Markdown
Owner

Landed in 5d332f7 after a polish pass.

Changes added while landing:

  • byte-based frontmatter stripping with BOM/CRLF coverage
  • upload-path tests that inspect the actual multipart media body
  • --keep-frontmatter live-smoke verification
  • CHANGELOG entry with contributor credit

Verified locally with focused upload/frontmatter tests, make lint, make test, make build, and make ci. Also live-tested against clawdbot@gmail.com by converting Markdown to a Google Doc, exporting Markdown to verify stripping, testing the opt-out path, and trashing both test files.

Thanks again @johnbenjaminlewis.

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