add img-responsive so the css will pick it up

This commit is contained in:
Ben Harris 2018-10-07 19:33:07 -04:00
parent c40c0c4745
commit c02423e084
Signed by untrusted user: ben
GPG Key ID: 4E0AF802FFF7960C
1 changed files with 3 additions and 17 deletions

View File

@ -4,28 +4,14 @@ import (
"bytes"
"html/template"
"io"
"strings"
"github.com/gomarkdown/markdown"
"github.com/gomarkdown/markdown/ast"
)
func renderHookImageResponsive(w io.Writer, node ast.Node, entering bool) (ast.WalkStatus, bool) {
if _, ok := node.(*ast.Image); !ok {
return ast.GoToNext, false
}
container := node.AsContainer()
container.Classes = append(container.Classes, []byte("img-reponsive"))
return ast.GoToNext, true
}
func renderMd(b io.Reader) template.HTML {
buf := new(bytes.Buffer)
buf.ReadFrom(b)
// opts := html.RendererOptions{
// Flags: html.CommonFlags,
// RenderNodeHook: renderHookImageResponsive,
// }
// renderer := html.NewRenderer(opts)
// TODO: get the img-responsive thing to work
return template.HTML(string(markdown.ToHTML(buf.Bytes(), nil, nil)))
md := string(markdown.ToHTML(buf.Bytes(), nil, nil))
return template.HTML(strings.Replace(md, "<img", "<img class=\"img-responsive\"", -1))
}