i create rules for v1 like below:
converter := htmltomarkdown.NewConverter("", true, nil)
// Add a custom rule for the <img> tag
converter.AddRules(
htmltomarkdown.Rule{
Filter: []string{"img"},
Replacement: func(content string, node *goquery.Selection, options *htmltomarkdown.Options) *string {
// Get attributes from the <img> tag
src, _ := node.Attr("src")
alt, _ := node.Attr("alt")
title, _ := node.Attr("title")
// Return a custom Markdown format
result := fmt.Sprintf("", alt, title, src)
return &result
},
},
)
how to apply rules for v2?
is that correct to apply rules like v1 using custom render in v2?
something like this:
conv := converter.NewConverter(
converter.WithPlugins(
base.NewBasePlugin(),
commonmark.NewCommonmarkPlugin(),
),
)
conv.Register.RendererFor("img", converter.TagTypeInline, func(ctx converter.Context, w converter.Writer, node *html.Node) converter.RenderStatus {
src := getAttribute(node, "src")
alt := getAttribute(node, "alt")
title := getAttribute(node, "title")
// Custom Markdown for <img> tags
w.WriteString(fmt.Sprintf("", alt, title, src))
return converter.RenderSuccess
}, converter.PriorityEarly)
thank you
i create
rulesforv1like below:how to apply
rulesforv2?is that correct to apply
ruleslikev1usingcustom renderinv2?something like this:
thank you