Documentation
¶
Overview ¶
Package docsutil provides utilities for working with the Google Docs API.
Index ¶
- Variables
- func BuildDocumentURL(documentID string) string
- func EnrichImagesWithURIs(content *DocumentContent, doc *docs.Document)
- func ExtractPlainText(doc *docs.Document) string
- func ExtractTextByParagraph(doc *docs.Document) []string
- func IsDocumentURL(s string) bool
- func NormalizeDocumentInput(urlOrID string) (string, error)
- func ParseDocumentURL(urlOrID string) (string, error)
- func Scopes() []string
- func ScopesReadWrite() []string
- type DocumentContent
- type ImageContent
- type ListContent
- type SectionContent
- type Service
- type TableContent
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
ExtractPlainText extracts all text from a document as a single string.
func ExtractTextByParagraph ¶
ExtractTextByParagraph extracts text organized by paragraphs.
func IsDocumentURL ¶
IsDocumentURL checks if the given string is a Google Docs document URL.
func NormalizeDocumentInput ¶
NormalizeDocumentInput accepts either a document ID or URL and returns the document ID. This is useful for APIs that accept either format.
func ParseDocumentURL ¶
ParseDocumentURL extracts the document ID from a Google Docs URL. Returns the document ID or an error if the URL is invalid.
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"`
}
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 ¶
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 ¶
NewService creates a new Docs service from an authenticated HTTP client.
func (*Service) GetDocument ¶
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.