docx

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Annotation

type Annotation struct {
	// contains filtered or unexported fields
}

func (*Annotation) Key

func (a *Annotation) Key() string

func (*Annotation) Name

func (a *Annotation) Name() string

func (*Annotation) Text

func (a *Annotation) Text() string

func (*Annotation) Value

func (a *Annotation) Value() string

type Annotations

type Annotations map[string][]Annotation

type Directive

type Directive struct {
	// contains filtered or unexported fields
}

func (*Directive) Enabled

func (d *Directive) Enabled() bool

func (*Directive) Name

func (d *Directive) Name() string

func (*Directive) Parameter

func (d *Directive) Parameter() string

type Directives

type Directives map[string]Directive

type Meta

type Meta struct {
	// contains filtered or unexported fields
}

func Parse

func Parse(lines []string) *Meta
Example
m := docx.Parse([]string{
	" Typename",
	" Typename this line is title ",
	" this is line 1 for descriptions ",
	" this is line 2 for descriptions ",
	" +genx:directive=directive parameters ... ",
	" +genx:ignore=ignored1,ignored2,", // ignored directives
	" +genx:ignored1",                  // redeclared directives
	" + genx:... ",                     // invalid directive will be skipped
	" +genx: ... ",                     // invalid directive will be skipped
	" @attr k1=v1,attr parameters...",
	" TODO prefixed with keywords ",
	" todo keyword is case-sensitive",
	" this is line 3 for descriptions ",
	"", // empty line will be skipped
	" @def annotation content ",
	" @attr k2=v2,attr parameters...",
	" @def ",  // invalid annotation will be skipped
	" @ def ", // invalid annotation will be skipped
})

fmt.Println("Description Lines")
for _, line := range m.Lines() {
	fmt.Println(line)
}
fmt.Println()

fmt.Println("Description String")
fmt.Println(m.Description("Typename", "\n"))
fmt.Println()

fmt.Println("Description String No Prefix")
fmt.Println(m.Description("", "\n"))
fmt.Println()

fmt.Println("Annotations")
names := slices.Collect(maps.Keys(m.Annotations()))
slices.Sort(names)
for _, name := range names {
	fmt.Printf("%s:\n", name)
	annotations, _ := m.AnnotationsByName(name)
	for _, anno := range annotations {
		fmt.Printf("\tname:  %s\n", anno.Name())
		if k := anno.Key(); len(k) > 0 {
			fmt.Printf("\tkey:   %s\n", k)
		}
		if v := anno.Value(); len(v) > 0 {
			fmt.Printf("\tvalue: %s\n", v)
		}
		fmt.Printf("\ttext:  %s\n", anno.Text())
	}
}
fmt.Println()

fmt.Println("Directives")
names = slices.Collect(maps.Keys(m.Directives()))
slices.Sort(names)
for _, key := range names {
	d, _ := m.Directive(key)
	fmt.Printf("%s:\n", key)
	fmt.Printf("\tname:      %s\n", d.Name())
	if p := d.Parameter(); len(p) > 0 {
		fmt.Printf("\tparameter: %s\n", p)
	}
	fmt.Printf("\tenabled:   %t\n", d.Enabled())
}
fmt.Println()

fmt.Println("Empty documents")
fmt.Println("BEGIN")
fmt.Println(docx.Parse(nil).Description("", ""))
fmt.Println("END")
Output:
Description Lines
Typename
Typename this line is title
this is line 1 for descriptions
this is line 2 for descriptions
this is line 3 for descriptions

Description String
this line is title
this is line 1 for descriptions
this is line 2 for descriptions
this is line 3 for descriptions

Description String No Prefix
Typename
Typename this line is title
this is line 1 for descriptions
this is line 2 for descriptions
this is line 3 for descriptions

Annotations
attr:
	name:  attr
	key:   k1
	value: v1,attr parameters...
	text:  k1=v1,attr parameters...
	name:  attr
	key:   k2
	value: v2,attr parameters...
	text:  k2=v2,attr parameters...
def:
	name:  def
	key:   annotation content
	text:  annotation content

Directives
directive:
	name:      directive
	parameter: directive parameters ...
	enabled:   true
ignored1:
	name:      ignored1
	enabled:   false
ignored2:
	name:      ignored2
	enabled:   false

Empty documents
BEGIN

END

func (*Meta) Annotations

func (m *Meta) Annotations() Annotations

func (*Meta) AnnotationsByName

func (m *Meta) AnnotationsByName(name string) ([]Annotation, bool)

func (*Meta) Description

func (m *Meta) Description(prefix string, sep string) string

func (*Meta) Descriptions

func (m *Meta) Descriptions(prefix string) []string

func (*Meta) Directive

func (m *Meta) Directive(name string) (Directive, bool)

func (*Meta) Directives

func (m *Meta) Directives() map[string]Directive

func (*Meta) Lines

func (m *Meta) Lines() []string

func (*Meta) Title

func (m *Meta) Title(prefix string) string

Jump to

Keyboard shortcuts

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