sync: Display import error in markdown processing
This commit is contained in:
parent
ecc9ae6ef1
commit
93eed8d5e4
1 changed files with 7 additions and 4 deletions
|
@ -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
|
||||
}
|
||||
|
|
Reference in a new issue