en API Reference - ZeroHawkeye/wordZero GitHub Wiki

API Reference

This document provides a complete reference for all public APIs in the WordZero library.

📋 Package Overview

WordZero consists of three main packages:

  • github.com/ZeroHawkeye/wordZero/pkg/document - Core document manipulation
  • github.com/ZeroHawkeye/wordZero/pkg/style - Style definitions and management
  • github.com/ZeroHawkeye/wordZero/pkg/markdown - Markdown conversion utilities

📄 Document Package

Document Creation

New() *Document

Creates a new empty Word document.

doc := document.New()

Document Operations

Save(filename string) error

Saves the document to the specified file path.

err := doc.Save("document.docx")
if err != nil {
    log.Printf("Save failed: %v", err)
}

AddParagraph(text string) *Paragraph

Adds a new paragraph with the specified text to the document.

para := doc.AddParagraph("Hello, WordZero!")

AddTable(rows, cols int) *Table

Creates a new table with the specified number of rows and columns.

table := doc.AddTable(3, 4) // 3 rows, 4 columns

Advanced Features

AddTableOfContents() error

Adds a table of contents to the document based on heading styles.

err := doc.AddTableOfContents()
if err != nil {
    log.Printf("Failed to add TOC: %v", err)
}

📝 Paragraph Structure

Text Operations

SetStyle(style style.StyleType) error

Applies a predefined style to the paragraph.

err := para.SetStyle(style.StyleHeading1)

AddFormattedText(text string, format *TextFormat)

Adds formatted text to the paragraph.

para.AddFormattedText("Bold text", &document.TextFormat{
    Bold: true,
})

🎨 Text Formatting

TextFormat Structure

type TextFormat struct {
    FontName    string // Font family name
    FontSize    int    // Font size in points
    Bold        bool   // Bold formatting
    Italic      bool   // Italic formatting
    Underline   bool   // Underline formatting
    FontColor   string // Hex color code (without #)
}

📊 Table Operations

Basic Operations

SetCellText(row, col int, text string) error

Sets the text content of a specific cell.

err := table.SetCellText(0, 0, "Header 1")

GetCellText(row, col int) (string, error)

Gets the text content of a specific cell.

text, err := table.GetCellText(0, 0)

🎨 Style Package

Predefined Styles

const (
    StyleNormal        StyleType = "Normal"
    StyleTitle         StyleType = "Title"
    StyleSubtitle      StyleType = "Subtitle"
    StyleHeading1      StyleType = "Heading1"
    StyleHeading2      StyleType = "Heading2"
    StyleHeading3      StyleType = "Heading3"
    StyleQuote         StyleType = "Quote"
    StyleCodeBlock     StyleType = "CodeBlock"
)

This API reference provides comprehensive coverage of WordZero's functionality.