Versions in this module Expand all Collapse all v0 v0.5.1 Jul 1, 2024 v0.5.0 Jul 1, 2024 v0.4.9 Jul 1, 2024 Changes in this version + const DocumentXml + const RunElementName + const TextElementName + var CloseDelimiter rune = '}' + var CloseDelimiterRegex = regexp.MustCompile(string(CloseDelimiter)) + var ErrPlaceholderNotFound = errors.New("placeholder not found in document") + var ErrTagsInvalid = errors.New("one or more tags are invalid and will cause the XML to be corrupt") + var FooterPathRegex = regexp.MustCompile(`word/footer[0-9]*.xml`) + var HeaderPathRegex = regexp.MustCompile(`word/header[0-9]*.xml`) + var OpenDelimiter rune = '{' + var OpenDelimiterRegex = regexp.MustCompile(string(OpenDelimiter)) + var RunCloseTagRegex = regexp.MustCompile(`(</w:r>)`) + var RunOpenTagRegex = regexp.MustCompile(`(<w:r).*>`) + var RunSingletonTagRegex = regexp.MustCompile(`(<w:r/>)`) + var TextCloseTagRegex = regexp.MustCompile(`(</w:t>)`) + var TextOpenTagRegex = regexp.MustCompile(`(<w:t).*>`) + func AddPlaceholderDelimiter(s string) string + func ChangeOpenCloseDelimiter(openDelimiter, closeDelimiter rune) + func IsDelimitedPlaceholder(s string) bool + func NewFragmentID() int + func NewRunID() int + func RemovePlaceholderDelimiter(s string) string + func ResetFragmentIdCounter() + func ResetRunIdCounter() + func ValidatePositions(document []byte, runs []*Run) error + type Document struct + func Open(path string) (*Document, error) + func OpenBytes(b []byte) (*Document, error) + func (d *Document) Close() + func (d *Document) GetFile(fileName string) []byte + func (d *Document) GetPlaceHoldersList() ([]string, error) + func (d *Document) Placeholders() (placeholders []*Placeholder) + func (d *Document) Replace(key, value string) error + func (d *Document) ReplaceAll(placeholderMap PlaceholderMap) error + func (d *Document) Runs() (runs []*Run) + func (d *Document) SetFile(fileName string, fileBytes []byte) error + func (d *Document) Write(writer io.Writer) error + func (d *Document) WriteToFile(file string) error + type DocumentRuns []*Run + func (dr *DocumentRuns) Pop() *Run + func (dr *DocumentRuns) Push(run *Run) + func (dr DocumentRuns) WithText() DocumentRuns + type FileMap map[string][]byte + func (fm FileMap) Write(writer io.Writer, filename string) error + type Placeholder struct + Fragments []*PlaceholderFragment + func ParsePlaceholders(runs DocumentRuns, docBytes []byte) (placeholders []*Placeholder, err error) + func (p Placeholder) EndPos() int64 + func (p Placeholder) StartPos() int64 + func (p Placeholder) Text(docBytes []byte) string + func (p Placeholder) Valid() bool + type PlaceholderFragment struct + ID int + Number int + Position Position + Run *Run + func NewPlaceholderFragment(number int, pos Position, run *Run) *PlaceholderFragment + func (p *PlaceholderFragment) ShiftAll(deltaLength int64) + func (p *PlaceholderFragment) ShiftCut(cutLength int64) + func (p *PlaceholderFragment) ShiftReplace(deltaLength int64) + func (p PlaceholderFragment) EndPos() int64 + func (p PlaceholderFragment) StartPos() int64 + func (p PlaceholderFragment) String(docBytes []byte) string + func (p PlaceholderFragment) Text(docBytes []byte) string + func (p PlaceholderFragment) TextLength(docBytes []byte) int64 + func (p PlaceholderFragment) Valid() bool + type PlaceholderMap map[string]interface + type Position struct + End int64 + Start int64 + func (p Position) Match(regexp *regexp.Regexp, data []byte) bool + func (p Position) Valid() bool + type Reader struct + func NewReader(s string) *Reader + func (r *Reader) Len() int + func (r *Reader) Pos() int64 + func (r *Reader) Read(b []byte) (int, error) + func (r *Reader) ReadByte() (byte, error) + func (r *Reader) Size() int64 + func (r *Reader) String() string + type Replacer struct + BytesChanged int64 + ReplaceCount int + func NewReplacer(docBytes []byte, placeholder []*Placeholder) *Replacer + func (r *Replacer) Bytes() []byte + func (r *Replacer) Replace(placeholderKey string, value string) error + type Run struct + HasText bool + ID int + Text TagPair + func NewEmptyRun() *Run + func (r *Run) GetText(documentBytes []byte) string + func (r *Run) String(bytes []byte) string + type RunParser struct + func NewRunParser(doc []byte) *RunParser + func (parser *RunParser) Execute() error + func (parser *RunParser) Runs() DocumentRuns + type TagPair struct + CloseTag Position + OpenTag Position