added custom image renderer with image-container div
This commit is contained in:
parent
fb67ef046a
commit
0c1c842bcd
1 changed files with 19 additions and 0 deletions
|
@ -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, "<div class=\"image-container\">\n")
|
||||||
|
fmt.Fprintf(w, `<img src="%s" title="%s">`, node.Destination, node.Title)
|
||||||
|
} else {
|
||||||
|
// if it's the closing img tag
|
||||||
|
// we close the div tag *after*
|
||||||
|
fmt.Fprintf(w, `</div>`)
|
||||||
|
fmt.Println("Image node not entering??")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func renderLink(w io.Writer, l *ast.Link, entering bool) {
|
func renderLink(w io.Writer, l *ast.Link, entering bool) {
|
||||||
if entering {
|
if entering {
|
||||||
destPath := processLink(string(l.Destination))
|
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) {
|
func htmlRenderHook(w io.Writer, node ast.Node, entering bool) (ast.WalkStatus, bool) {
|
||||||
if link, ok := node.(*ast.Link); ok {
|
if link, ok := node.(*ast.Link); ok {
|
||||||
renderLink(w, link, entering)
|
renderLink(w, link, entering)
|
||||||
return ast.GoToNext, true
|
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 <small> tag?
|
||||||
|
renderImage(w, image, entering)
|
||||||
|
return ast.GoToNext, true
|
||||||
}
|
}
|
||||||
return ast.GoToNext, false
|
return ast.GoToNext, false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue