mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-07-27 17:28:34 +00:00
add lazy loading attribute to images
This commit is contained in:
parent
6d4554b01c
commit
cfeda81e2a
2 changed files with 4 additions and 0 deletions
|
@ -44,6 +44,7 @@ func (g *ASTTransformer) transformImage(ctx *markup.RenderContext, v *ast.Image)
|
||||||
for _, attr := range v.Attributes() {
|
for _, attr := range v.Attributes() {
|
||||||
image.SetAttribute(attr.Name, attr.Value)
|
image.SetAttribute(attr.Name, attr.Value)
|
||||||
}
|
}
|
||||||
|
image.SetAttributeString("loading", []byte("lazy"))
|
||||||
for child := v.FirstChild(); child != nil; {
|
for child := v.FirstChild(); child != nil; {
|
||||||
next := child.NextSibling()
|
next := child.NextSibling()
|
||||||
image.AppendChild(image, child)
|
image.AppendChild(image, child)
|
||||||
|
|
|
@ -108,6 +108,9 @@ func createDefaultPolicy() *bluemonday.Policy {
|
||||||
// Allow classes for emojis
|
// Allow classes for emojis
|
||||||
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^emoji$`)).OnElements("img")
|
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^emoji$`)).OnElements("img")
|
||||||
|
|
||||||
|
// Allow attributes for images
|
||||||
|
policy.AllowAttrs("loading").Matching(regexp.MustCompile(`^lazy$`)).OnElements("img")
|
||||||
|
|
||||||
// Allow icons, emojis, chroma syntax and keyword markup on span
|
// Allow icons, emojis, chroma syntax and keyword markup on span
|
||||||
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^((icon(\s+[\p{L}\p{N}_-]+)+)|(emoji)|(language-math display)|(language-math inline))$|^([a-z][a-z0-9]{0,2})$|^` + keywordClass + `$`)).OnElements("span")
|
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^((icon(\s+[\p{L}\p{N}_-]+)+)|(emoji)|(language-math display)|(language-math inline))$|^([a-z][a-z0-9]{0,2})$|^` + keywordClass + `$`)).OnElements("span")
|
||||||
policy.AllowAttrs("data-alias").Matching(regexp.MustCompile(`^[a-zA-Z0-9-_+]+$`)).OnElements("span")
|
policy.AllowAttrs("data-alias").Matching(regexp.MustCompile(`^[a-zA-Z0-9-_+]+$`)).OnElements("span")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue