diff --git a/go.mod b/go.mod
index c21c1fb..3b8f637 100644
--- a/go.mod
+++ b/go.mod
@@ -54,6 +54,7 @@ require (
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
+ github.com/mangoumbrella/goldmark-figure v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
diff --git a/go.sum b/go.sum
index 1ba44b8..a727bef 100644
--- a/go.sum
+++ b/go.sum
@@ -107,6 +107,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
+github.com/mangoumbrella/goldmark-figure v1.2.0 h1:T8wf2VAi0e2G2qeJDSHpO4M6GgkLbzYNliwSuozMcko=
+github.com/mangoumbrella/goldmark-figure v1.2.0/go.mod h1:iIL+fhdmCQDpE0l/TKtGhokWzIbo5lo/Y2OIAcx6usI=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
diff --git a/services/docs_import.go b/services/docs_import.go
index 71748e3..4fa6fc1 100644
--- a/services/docs_import.go
+++ b/services/docs_import.go
@@ -13,6 +13,7 @@ import (
"github.com/PuerkitoBio/goquery"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/transport/http"
+ figure "github.com/mangoumbrella/goldmark-figure"
"github.com/yuin/goldmark"
"github.com/yuin/goldmark/parser"
"github.com/yuin/goldmark/renderer/html"
@@ -22,6 +23,9 @@ func processMarkdown(content, dir string, cfg *config.Config) (string, error) {
gm := goldmark.New(
goldmark.WithRendererOptions(html.WithUnsafe()),
goldmark.WithParserOptions(parser.WithAutoHeadingID()),
+ goldmark.WithExtensions(
+ figure.Figure,
+ ),
)
var output bytes.Buffer
@@ -50,15 +54,28 @@ func processMarkdown(content, dir string, cfg *config.Config) (string, error) {
absPath := filepath.Join(dir, decodedSrc)
file, err := os.Open(absPath)
+ if err != nil {
+ return
+ }
+ defer file.Close()
- if err == nil {
- mime := utils.GetContentType(absPath)
+ mime := utils.GetContentType(absPath)
- s3URL, err := UploadToStorage(file, filepath.Base(absPath), mime, cfg)
+ s3URL, err := UploadToStorage(file, filepath.Base(absPath), mime, cfg)
+ if err != nil {
+ return
+ }
- if err == nil {
- s.SetAttr("src", s3URL)
- }
+ if strings.HasPrefix(mime, "image/") {
+ s.SetAttr("src", s3URL)
+ } else if strings.HasPrefix(mime, "video/") {
+ s.BeforeHtml(fmt.Sprintf(``, s3URL))
+ s.Remove()
+ } else if strings.HasPrefix(mime, "audio/") {
+ s.BeforeHtml(fmt.Sprintf(``, s3URL))
+ s.Remove()
+ } else {
+ s.SetAttr("src", s3URL)
}
}
})