1
0
mirror of https://github.com/fumiama/go-docx.git synced 2026-06-08 09:10:24 +08:00

add KeepElements & DropDrawingOf

This commit is contained in:
源文雨
2023-03-09 20:50:39 +08:00
parent 54e7323f63
commit b68d555c67
7 changed files with 275 additions and 13 deletions

View File

@@ -23,6 +23,7 @@ package docx
import (
"encoding/xml"
"io"
"reflect"
"strconv"
"strings"
)
@@ -175,6 +176,24 @@ func (r *Run) parse(d *xml.Decoder, tt xml.StartElement) (child interface{}, err
return
}
// KeepElements keep named elems amd removes others
//
// names: *docx.Text *docx.Drawing *docx.Tab *docx.BarterRabbet
func (r *Run) KeepElements(name ...string) {
items := make([]interface{}, 0, len(r.Children))
namemap := make(map[string]struct{}, len(name)*2)
for _, n := range name {
namemap[n] = struct{}{}
}
for _, item := range r.Children {
_, ok := namemap[reflect.ValueOf(item).Type().String()]
if ok {
items = append(items, item)
}
}
r.Children = items
}
// RunProperties encapsulates visual properties of a run
type RunProperties struct {
XMLName xml.Name `xml:"w:rPr,omitempty"`