Skip to content

Commit

Permalink
Upgrade tdewolff/parse (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: wangbiao <[email protected]>
  • Loading branch information
lvwxx and wangbiao authored Feb 8, 2023
1 parent 1528c7f commit 3ffb0bb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ go 1.13
require (
github.com/longbridgeapp/assert v0.1.0
github.com/pkg/errors v0.8.1
github.com/tdewolff/parse/v2 v2.4.3
github.com/tdewolff/parse/v2 v2.6.5
)
8 changes: 5 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tdewolff/parse/v2 v2.4.3 h1:k24zHgTRGm7LkvbTEreuavyZTf0k8a/lIenggv62OiU=
github.com/tdewolff/parse/v2 v2.4.3/go.mod h1:WzaJpRSbwq++EIQHYIRTpbYKNA3gn9it1Ik++q4zyho=
github.com/tdewolff/test v1.0.6/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE=
github.com/tdewolff/parse/v2 v2.6.5 h1:lYvWBk55GkqKl0JJenGpmrgu/cPHQQ6/Mm1hBGswoGQ=
github.com/tdewolff/parse/v2 v2.6.5/go.mod h1:woz0cgbLwFdtbjJu8PIKxhW05KplTFQkOdX78o+Jgrs=
github.com/tdewolff/test v1.0.7 h1:8Vs0142DmPFW/bQeHRP3MV19m1gvndjUb1sn8yy74LM=
github.com/tdewolff/test v1.0.7/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
8 changes: 5 additions & 3 deletions html.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/pkg/errors"
"github.com/tdewolff/parse/v2"
"github.com/tdewolff/parse/v2/html"
// "golang.org/x/net/html"
)
Expand All @@ -31,8 +32,9 @@ func UnformatHTML(body string, options ...UnformatOption) (out string, err error

func processHTML(body string, fn func(plainText string) string) (out string, err error) {
w := &bytes.Buffer{}
lex := html.NewLexer(strings.NewReader(body))
defer lex.Restore()
i := parse.NewInput(strings.NewReader(body))
lex := html.NewLexer(i)

out = body

ignoreTag := false
Expand All @@ -46,7 +48,7 @@ func processHTML(body string, fn func(plainText string) string) (out string, err
return w.String(), nil
}

err = errors.Errorf("Error on line %d, %v", lex.Offset(), lex.Err())
err = errors.Errorf("Error on line %d, %v", i.Offset(), lex.Err())
return
case html.TextToken:
if ignoreTag {
Expand Down

0 comments on commit 3ffb0bb

Please sign in to comment.