Fix relative links in postprocessed images (#16334) (#16340)

* Fix relative links in postprocessed images (#16334)

If a pre-post-processed file contains relative img tags these need to be updated
and joined correctly with the prefix. Finally, the node attributes need to be updated.

Fix #16308

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
zeripath 2021-07-04 15:28:29 +01:00 committed by GitHub
parent 50084daa4c
commit c65e49d72f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View file

@ -401,7 +401,7 @@ func (ctx *postProcessCtx) visitNode(node *html.Node, visitText bool) {
}
case html.ElementNode:
if node.Data == "img" {
for _, attr := range node.Attr {
for i, attr := range node.Attr {
if attr.Key != "src" {
continue
}
@ -414,6 +414,7 @@ func (ctx *postProcessCtx) visitNode(node *html.Node, visitText bool) {
attr.Val = util.URLJoin(prefix, attr.Val)
}
node.Attr[i] = attr
}
} else if node.Data == "a" {
visitText = false