weiro/providers/markdown/uiexts.go

22 lines
599 B
Go
Raw Normal View History

package markdown
import (
"context"
"github.com/PuerkitoBio/goquery"
)
func rewriteImgSrc(transform func(ctx context.Context, in string) string) htmlTransform {
return func(ctx context.Context, dom *goquery.Document) error {
dom.Find("img").Each(func(i int, s *goquery.Selection) {
s.SetAttr("src", transform(ctx, s.AttrOr("src", "")))
})
dom.Find("img").Each(func(i int, s *goquery.Selection) {
s.AddClass("img-fluid")
})
//SetAttr("style", "max-width: 200px;max-height: 200px;height: auto;")
//log.Printf("Rewritten image src: %s", s.AttrOr("style", ""))
return nil
}
}