We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i create rules for v1 like below:
rules
v1
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("![Custom Format | Alt: %s | Title: %s](%s)", 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:
v2
custom render
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("![Custom Format | Alt: %s | Title: %s](%s)", alt, title, src)) return converter.RenderSuccess }, converter.PriorityEarly)
thank you
The text was updated successfully, but these errors were encountered:
There is an example for Register in examples/register/main.go
Register
examples/register/main.go
You can use the function dom.GetAttributeOr(node, "alt", "") from the "github.com/JohannesKaufmann/dom" package.
dom.GetAttributeOr(node, "alt", "")
The Rule in V1 was quite limited. With V2 there is a lot more customisation possible. For most case the RendererFor is what you need.
Rule
RendererFor
If you want to package logic, you can optionally package it into a plugin. But registering it like you do right now is perfectly okay.
@hbinduni The logic above seems to be good 👍
Sorry, something went wrong.
Thank you for your help
No problem, happy to help!
Let me know if you have any other questions...
No branches or pull requests
i create
rules
forv1
like below:how to apply
rules
forv2
?is that correct to apply
rules
likev1
usingcustom render
inv2
?something like this:
thank you
The text was updated successfully, but these errors were encountered: