weiro/providers/markdown/htmltransforms.go

28 lines
546 B
Go
Raw Permalink Normal View History

package markdown
import (
"context"
"strings"
"github.com/PuerkitoBio/goquery"
)
type htmlTransform func(ctx context.Context, dom *goquery.Document) error
func applyTransforms(ctx context.Context, inHTML string, transforms []htmlTransform) string {
dom, err := goquery.NewDocumentFromReader(strings.NewReader(inHTML))
if err != nil {
return inHTML
}
for _, transform := range transforms {
if err := transform(ctx, dom); err != nil {
return inHTML
}
}
res, err := dom.Html()
if err != nil {
return inHTML
}
return res
}