1
0
mirror of https://github.com/fumiama/go-docx.git synced 2026-06-23 03:50:36 +08:00

feat: add_pagabreaks (#21)

This commit is contained in:
mabiao0525
2024-03-17 18:58:15 +08:00
committed by GitHub
parent 047c5e5f03
commit e9a89648f8
5 changed files with 35 additions and 14 deletions

View File

@@ -37,31 +37,31 @@ func (p *Paragraph) AddTab() *Run {
return run
}
// AddText adds text to paragraph
// AddText adds text to paragraph with \n
func (p *Paragraph) AddText(text string) *Run {
if text == "\t" {
return p.AddTab()
}
c := make([]interface{}, 0, 64)
for i, s := range strings.Split(text, "\t") {
for i, s := range strings.Split(text, "\n") {
if i > 0 {
c = append(c, &Tab{})
c = append(c, &BarterRabbet{})
}
if s != "" {
c = append(c, &Text{
Text: s,
})
for tabIndex, k := range strings.Split(s, "\t") {
if tabIndex > 0 {
c = append(c, &Tab{})
}
if k != "" {
c = append(c, &Text{
Text: k,
})
}
}
}
run := &Run{
RunProperties: &RunProperties{},
Children: c,
}
p.Children = append(p.Children, run)
return run
}