4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-07-03 11:57:45 +00:00

Update vendor (#1297)

This commit is contained in:
Wim
2020-11-22 15:55:57 +01:00
committed by GitHub
parent cbb46293ab
commit 4cc2c914e6
166 changed files with 25790 additions and 14376 deletions

View File

@ -346,6 +346,22 @@ func walk(node *html.Node, w io.Writer, nest int, option *Option) {
fmt.Fprint(w, "\n\n")
}
default:
if option == nil || option.CustomRules == nil {
walk(c, w, nest, option)
break
}
foundCustom := false
for _, cr := range option.CustomRules {
if tag, customWalk := cr.Rule(walk); strings.ToLower(c.Data) == tag {
customWalk(c, w, nest, option)
foundCustom = true
}
}
if foundCustom {
break
}
walk(c, w, nest, option)
}
default:
@ -354,11 +370,27 @@ func walk(node *html.Node, w io.Writer, nest int, option *Option) {
}
}
// WalkFunc type is an signature for functions traversing HTML nodes
type WalkFunc func(node *html.Node, w io.Writer, nest int, option *Option)
// CustomRule is an interface to define custom conversion rules
//
// Rule method accepts `next WalkFunc` as an argument, which `customRule` should call
// to let walk function continue parsing the content inside the HTML tag.
// It returns a tagName to indicate what HTML element this `customRule` handles and the `customRule`
// function itself, where conversion logic should reside.
//
// See example TestRule implementation in godown_test.go
type CustomRule interface {
Rule(next WalkFunc) (tagName string, customRule WalkFunc)
}
// Option is optional information for Convert.
type Option struct {
GuessLang func(string) (string, error)
Script bool
Style bool
GuessLang func(string) (string, error)
Script bool
Style bool
CustomRules []CustomRule
}
// Convert convert HTML to Markdown. Read HTML from r and write to w.