docsutil

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package docsutil provides utilities for working with the Google Docs API.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidURL is returned when a URL cannot be parsed.
	ErrInvalidURL = errors.New("invalid Google Docs URL")

	// ErrEmptyInput is returned when input is empty.
	ErrEmptyInput = errors.New("input cannot be empty")
)

Functions

func BuildDocumentURL

func BuildDocumentURL(documentID string) string

BuildDocumentURL constructs a Google Docs URL from a document ID.

func EnrichImagesWithURIs

func EnrichImagesWithURIs(content *DocumentContent, doc *docs.Document)

EnrichImagesWithURIs populates image URIs from the document's inline objects.

func ExtractPlainText

func ExtractPlainText(doc *docs.Document) string

ExtractPlainText extracts all text from a document as a single string.

func ExtractTextByParagraph

func ExtractTextByParagraph(doc *docs.Document) []string

ExtractTextByParagraph extracts text organized by paragraphs.

func IsDocumentURL

func IsDocumentURL(s string) bool

IsDocumentURL checks if the given string is a Google Docs document URL.

func NormalizeDocumentInput

func NormalizeDocumentInput(urlOrID string) (string, error)

NormalizeDocumentInput accepts either a document ID or URL and returns the document ID. This is useful for APIs that accept either format.

func ParseDocumentURL

func ParseDocumentURL(urlOrID string) (string, error)

ParseDocumentURL extracts the document ID from a Google Docs URL. Returns the document ID or an error if the URL is invalid.

func Scopes

func Scopes() []string

Scopes returns the OAuth2 scopes for Google Docs API access.

func ScopesReadWrite

func ScopesReadWrite() []string

ScopesReadWrite returns the OAuth2 scopes for read-write Google Docs API access.

Types

type DocumentContent

type DocumentContent struct {
	Title      string            `json:"title"`
	DocumentID string            `json:"document_id"`
	Sections   []SectionContent  `json:"sections"`
	Images     []ImageContent    `json:"images,omitempty"`
	Tables     []TableContent    `json:"tables,omitempty"`
	Lists      []ListContent     `json:"lists,omitempty"`
	Headers    map[string]string `json:"headers,omitempty"`
	Footers    map[string]string `json:"footers,omitempty"`
}

DocumentContent represents extracted content from a Google Doc.

func ExtractDocumentContent

func ExtractDocumentContent(doc *docs.Document) *DocumentContent

ExtractDocumentContent extracts all text and structural content from a document.

type ImageContent

type ImageContent struct {
	ObjectID    string `json:"object_id"`
	ContentURI  string `json:"content_uri"`
	SourceURI   string `json:"source_uri,omitempty"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
}

ImageContent represents an embedded image.

type ListContent

type ListContent struct {
	ListID string   `json:"list_id"`
	Items  []string `json:"items"`
}

ListContent represents a list in the document.

type SectionContent

type SectionContent struct {
	Type    string `json:"type"` // "heading", "paragraph", "list_item"
	Level   int    `json:"level,omitempty"`
	Text    string `json:"text"`
	StyleID string `json:"style_id,omitempty"`
}

SectionContent represents a section of text content.

type Service

type Service struct {
	DocsService      *docs.Service
	DocumentsService *docs.DocumentsService
	// contains filtered or unexported fields
}

Service wraps the Google Docs API service.

func NewService

func NewService(ctx context.Context, httpClient *http.Client) (*Service, error)

NewService creates a new Docs service from an authenticated HTTP client.

func (*Service) GetDocument

func (s *Service) GetDocument(ctx context.Context, documentID string) (*docs.Document, error)

GetDocument retrieves a document by ID.

func (*Service) GetDocumentWithSuggestions

func (s *Service) GetDocumentWithSuggestions(ctx context.Context, documentID, suggestionsViewMode string) (*docs.Document, error)

GetDocumentWithSuggestions retrieves a document with the specified suggestions view mode. Mode can be: DEFAULT_FOR_CURRENT_ACCESS, SUGGESTIONS_INLINE, PREVIEW_SUGGESTIONS_ACCEPTED, PREVIEW_WITHOUT_SUGGESTIONS

type TableContent

type TableContent struct {
	Rows    int        `json:"rows"`
	Columns int        `json:"columns"`
	Cells   [][]string `json:"cells"`
}

TableContent represents a table in the document.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL