repochecker: Markdown: unescape path to images

This commit is contained in:
nemunaire 2024-01-13 14:30:43 +01:00
parent 55f7d0826e
commit 636cc2b55b
1 changed files with 7 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes"
"encoding/base32"
"io"
"net/url"
"os"
"path"
"strings"
@ -79,6 +80,12 @@ func (t *imageImporterTransformer) Transform(doc *ast.Document, reader text.Read
switch child := node.(type) {
case *ast.Image:
iPath := string(child.Destination)
// Unescape string if needed (mostly %20 to space)
if ip, err := url.QueryUnescape(iPath); err == nil {
iPath = ip
}
dPath := path.Join(fic.FilesDir, strings.ToLower(base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(t.hash[:])), iPath)
child.Destination = []byte(path.Join(t.absPath, string(child.Destination)))