Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit 50becb1

Browse files
Update parse.go
1 parent 8b5107f commit 50becb1

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

claat/parser/gdoc/parse.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,12 +697,32 @@ func image(ds *docState) nodes.Node {
697697
errorAlt = "The domain of the requested iframe (" + u.Hostname() + ") has not been whitelisted."
698698
fmt.Fprint(os.Stderr, errorAlt+"\n")
699699
}
700+
701+
var imageBytes []byte
702+
var imageSrc string
700703
s := nodeAttr(ds.cur, "src")
701704
if s == "" {
702705
return nil
706+
} else if strings.HasPrefix(s, "data:") {
707+
_, data, ok := strings.Cut(s, ",")
708+
if !ok {
709+
fmt.Fprint(os.Stderr, "Failed to decode data URL: "+s+" \n")
710+
return nil
711+
}
712+
b, err := base64.StdEncoding.DecodeString(data)
713+
if err != nil {
714+
fmt.Fprint(os.Stderr, "Failed to decode data URL: "+s+"\n"+err.Error()+"\n")
715+
return nil
716+
}
717+
imageSrc = ""
718+
imageBytes = b
719+
} else {
720+
imageSrc = s
721+
imageBytes = []byte{}
703722
}
704723
n := nodes.NewImageNode(nodes.NewImageNodeOptions{
705-
Src: s,
724+
Src: imageSrc,
725+
Bytes: imageBytes,
706726
Width: styleFloatValue(ds.cur, "width"),
707727
})
708728
n.MutateBlock(findBlockParent(ds.cur))

0 commit comments

Comments
 (0)