summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mattn
diff options
context:
space:
mode:
authorWim <wim@42.be>2020-11-22 15:55:57 +0100
committerGitHub <noreply@github.com>2020-11-22 15:55:57 +0100
commit4cc2c914e634eb8c79eb61aa1bc29faf6021ffcf (patch)
tree92d3b8d27cd35455eae7423e4d47aad67cc6a43b /vendor/github.com/mattn
parentcbb46293ab670c1989bfcd9aae5d853223074038 (diff)
downloadmatterbridge-msglm-4cc2c914e634eb8c79eb61aa1bc29faf6021ffcf.tar.gz
matterbridge-msglm-4cc2c914e634eb8c79eb61aa1bc29faf6021ffcf.tar.bz2
matterbridge-msglm-4cc2c914e634eb8c79eb61aa1bc29faf6021ffcf.zip
Update vendor (#1297)
Diffstat (limited to 'vendor/github.com/mattn')
-rw-r--r--vendor/github.com/mattn/godown/godown.go38
1 files changed, 35 insertions, 3 deletions
diff --git a/vendor/github.com/mattn/godown/godown.go b/vendor/github.com/mattn/godown/godown.go
index 5f73743f..5aae9690 100644
--- a/vendor/github.com/mattn/godown/godown.go
+++ b/vendor/github.com/mattn/godown/godown.go
@@ -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.