From 93eed8d5e4d7b8b666259b5289784ce28f65d8f6 Mon Sep 17 00:00:00 2001 From: Pierre-Olivier Mercier Date: Fri, 2 Dec 2022 16:18:58 +0100 Subject: [PATCH] sync: Display import error in markdown processing --- admin/sync/markdown.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/admin/sync/markdown.go b/admin/sync/markdown.go index 307bb195..78c5f7ac 100644 --- a/admin/sync/markdown.go +++ b/admin/sync/markdown.go @@ -24,6 +24,8 @@ func ProcessMarkdown(i Importer, input string, rootDir string) (output string, e // Define the path where save linked files hash := blake2b.Sum512([]byte(rootDir)) + imgImporter := NewImageImporterTransformer(i, rootDir, hash) + // Process md markdown := goldmark.New( goldmark.WithExtensions(extension.DefinitionList), @@ -33,7 +35,7 @@ func ProcessMarkdown(i Importer, input string, rootDir string) (output string, e goldmark.WithExtensions(extension.Typographer), goldmark.WithParserOptions( parser.WithASTTransformers( - util.Prioritized(NewImageImporterTransformer(i, rootDir, hash), 200), + util.Prioritized(imgImporter, 200), ), ), goldmark.WithRendererOptions( @@ -52,7 +54,7 @@ func ProcessMarkdown(i Importer, input string, rootDir string) (output string, e // Trim output output = strings.TrimSpace(output) - return + return output, imgImporter.(*imageImporterTransformer).err } type imageImporterTransformer struct { @@ -60,15 +62,16 @@ type imageImporterTransformer struct { rootDir string hash [blake2b.Size]byte absPath string + err error } func NewImageImporterTransformer(i Importer, rootDir string, hash [blake2b.Size]byte) parser.ASTTransformer { absPath := "$FILES$/" + strings.ToLower(base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(hash[:])) - return &imageImporterTransformer{i, rootDir, hash, absPath} + return &imageImporterTransformer{i, rootDir, hash, absPath, nil} } func (t *imageImporterTransformer) Transform(doc *ast.Document, reader text.Reader, pc parser.Context) { - ast.Walk(doc, func(node ast.Node, enter bool) (ast.WalkStatus, error) { + t.err = ast.Walk(doc, func(node ast.Node, enter bool) (ast.WalkStatus, error) { if !enter { return ast.WalkContinue, nil }