Skip to content

Commit

Permalink
Merge pull request #8 from raykov/NOREF-dont-fail-if-dont-have-an-image
Browse files Browse the repository at this point in the history
Skip empty images
  • Loading branch information
raykov authored Oct 22, 2021
2 parents 4f8e2a8 + 9632d52 commit f904d6f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion renderer/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"image"
"image/png"
"log"
"net/http"
"os"
"strings"
Expand All @@ -17,7 +18,14 @@ import (
"github.com/yuin/goldmark/util"
)

const inlineDataPrefix = "data:image/"
const (
inlineDataPrefix = "data:image/"
incorrectInlineImageFormat = `Incorrect inline image format:`
missingInlineImageData = `Missing inline image data:`
inlineImageError = `%s
expected: ![](data:image/png;base64,iVBORw0KG...SUVORK5CYII=)
got: ![](%s)`
)

func renderImage(w Writer, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) {
if !entering {
Expand All @@ -40,6 +48,12 @@ func renderImage(w Writer, source []byte, node ast.Node, entering bool) (ast.Wal
func inlineData(w Writer, node ast.Node, filePath string) (ast.WalkStatus, error) {
parts := strings.Split(filePath, ",")
if len(parts) != 2 {
log.Printf(inlineImageError, incorrectInlineImageFormat, filePath)
return ast.WalkSkipChildren, nil
}

if parts[1] == "" {
log.Printf(inlineImageError, missingInlineImageData, filePath)
return ast.WalkSkipChildren, nil
}

Expand Down

0 comments on commit f904d6f

Please sign in to comment.