Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
plandem committed Jul 9, 2019
1 parent 11ae135 commit aeb2ea0
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func main() {
styles.Font.Bold,
styles.Font.Color("#ff0000"),
),
"red bold text",
" red bold text ",
"another plain text",
)

Expand All @@ -116,7 +116,7 @@ func main() {
styles.Font.Bold,
styles.Font.Color("#ff0000"),
),
"red bold text",
" red bold text ",
"another plain text",
),
))
Expand Down
1 change: 1 addition & 0 deletions comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (c *comments) Add(bounds types.Bounds, info interface{}) error {
cml.AuthorID = id
} else {
nextID := len(c.ml.Authors)
c.ml.Authors = append(c.ml.Authors, types.Text(object.Author))
c.authorIndex[authorKey] = nextID
cml.AuthorID = nextID
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/plandem/xlsx
go 1.12

require (
github.com/plandem/ooxml v0.0.0-20190707190948-c8a4fbdda617
github.com/plandem/ooxml v0.0.0-20190709153553-bb6edf43a4b2
github.com/stretchr/testify v1.3.0
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/go-test/deep v1.0.1/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/plandem/ooxml v0.0.0-20190707190948-c8a4fbdda617 h1:Te32w/enwEEVSG9jwYU9ER+ID8621U+MKLOoWpJkZBs=
github.com/plandem/ooxml v0.0.0-20190707190948-c8a4fbdda617/go.mod h1:IPgZT3JusQax//tCModfRm0HVTJXMB04liCaOeaDf5o=
github.com/plandem/ooxml v0.0.0-20190709153553-bb6edf43a4b2 h1:ZrFWOoS0PJGAbnCIlk3Of1HJk/WMqOUFXnRTsj9A/J4=
github.com/plandem/ooxml v0.0.0-20190709153553-bb6edf43a4b2/go.mod h1:IPgZT3JusQax//tCModfRm0HVTJXMB04liCaOeaDf5o=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
16 changes: 14 additions & 2 deletions internal/hash/hash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ func TestDiffStyle(t *testing.T) {
}

func TestVmlShape(t *testing.T) {

shape := &vml.Shape{}
shape.ID = fmt.Sprintf("_x0000_s%d", 1025)
shape.Type = "#_x0000_t202"
Expand All @@ -343,5 +342,18 @@ func TestVmlShape(t *testing.T) {
Row: 2,
}

require.Equal(t, hash.Key("#_x0000_t202:1:2"), hash.Vml(shape))
require.Equal(t, hash.Key("#_x0000_t202:0:1:2"), hash.Vml(shape))

shape = &vml.Shape{}
shape.ID = fmt.Sprintf("_x0000_s%d", 1025)
shape.FillColor = "#ffeeee"
shape.InsetMode = vml.InsetModeAuto
shape.Spt = 202

shape.ClientData = &vml.ClientData{
Column: 1,
Row: 2,
}

require.Equal(t, hash.Key(":202:1:2"), hash.Vml(shape))
}
1 change: 1 addition & 0 deletions internal/hash/vml_shape.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func Vml(shape *vml.Shape) Key {

return Key(strings.Join([]string{
shape.Type,
strconv.FormatInt(int64(shape.Spt), 10),
strconv.FormatInt(int64(shape.ClientData.Column), 10),
strconv.FormatInt(int64(shape.ClientData.Row), 10),
}, ":"))
Expand Down
6 changes: 4 additions & 2 deletions internal/ml/primitives/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ package primitives
import (
"encoding/xml"
"github.com/plandem/ooxml/ml"
"strings"
"unicode"
)

//Text is textual type that can have leading/trailing spaces that must be preserved
//Text is textual type that can have leading/trailing whitespace or newlines that must be preserved
type Text string

//MarshalXML marshal Text
func (t *Text) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
value := string(*t)

//need to preserve space?
if len(value) > 0 && (value[0] == 32 || value[len(value)-1] == 32) {
if len(value) > 0 && (unicode.IsSpace(rune(value[0])) || unicode.IsSpace(rune(value[len(value)-1])) || strings.IndexByte(value, '\n') != -1) {
start.Attr = append(start.Attr, ml.AttrPreserveSpace)
}

Expand Down

0 comments on commit aeb2ea0

Please sign in to comment.