From 4cc2c914e634eb8c79eb61aa1bc29faf6021ffcf Mon Sep 17 00:00:00 2001 From: Wim Date: Sun, 22 Nov 2020 15:55:57 +0100 Subject: Update vendor (#1297) --- vendor/github.com/mattn/godown/godown.go | 38 +++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'vendor/github.com/mattn') 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. -- cgit v1.2.3