diff --git a/internal/builder/convert.go b/internal/builder/convert.go index ed72fbd..ea7e46f 100644 --- a/internal/builder/convert.go +++ b/internal/builder/convert.go @@ -53,6 +53,20 @@ func processLink(p string) string { } } +func renderImage(w io.Writer, node *ast.Image, entering bool) { + // we add image-container div tag + // here before the opening img tag + if entering { + fmt.Fprintf(w, "
\n") + fmt.Fprintf(w, ``, node.Destination, node.Title) + } else { + // if it's the closing img tag + // we close the div tag *after* + fmt.Fprintf(w, `
`) + fmt.Println("Image node not entering??") + } +} + func renderLink(w io.Writer, l *ast.Link, entering bool) { if entering { destPath := processLink(string(l.Destination)) @@ -66,10 +80,15 @@ func renderLink(w io.Writer, l *ast.Link, entering bool) { } } +// htmlRenderHook hooks the HTML renderer and overrides the rendering of certain nodes. func htmlRenderHook(w io.Writer, node ast.Node, entering bool) (ast.WalkStatus, bool) { if link, ok := node.(*ast.Link); ok { renderLink(w, link, entering) return ast.GoToNext, true + } else if image, ok := node.(*ast.Image); ok { + // TODO: should do something more interesting with the alt text -- like put it in a tag? + renderImage(w, image, entering) + return ast.GoToNext, true } return ast.GoToNext, false }