mirror of
https://github.com/fumiama/go-docx.git
synced 2026-06-18 16:30:27 +08:00
add AddInlineDrawingFrom
This commit is contained in:
@@ -3,6 +3,7 @@ package docxlib
|
||||
import (
|
||||
"encoding/xml"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ParagraphChild struct {
|
||||
@@ -18,6 +19,33 @@ type Paragraph struct {
|
||||
file *Docx
|
||||
}
|
||||
|
||||
func (p *Paragraph) String() string {
|
||||
sb := strings.Builder{}
|
||||
for _, c := range p.Children {
|
||||
switch {
|
||||
case c.Link != nil:
|
||||
id := c.Link.ID
|
||||
text := c.Link.Run.InstrText
|
||||
link, err := p.file.ReferHref(id)
|
||||
sb.WriteString(text)
|
||||
sb.WriteByte('(')
|
||||
if err != nil {
|
||||
sb.WriteString(id)
|
||||
} else {
|
||||
sb.WriteString(link)
|
||||
}
|
||||
sb.WriteByte(')')
|
||||
case c.Run != nil:
|
||||
sb.WriteString("run") //TODO: implement
|
||||
case c.Properties != nil:
|
||||
sb.WriteString("prop") //TODO: implement
|
||||
default:
|
||||
continue
|
||||
}
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
func (p *Paragraph) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
||||
err := e.EncodeToken(start)
|
||||
if err != nil {
|
||||
@@ -48,6 +76,9 @@ func (p *Paragraph) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch tt := t.(type) {
|
||||
case xml.StartElement:
|
||||
var elem ParagraphChild
|
||||
|
||||
Reference in New Issue
Block a user