From 347bda3c4fda941a43a9afd799073a4d02a6c445 Mon Sep 17 00:00:00 2001 From: Colin Henry Date: Fri, 21 Jan 2022 20:45:28 -0800 Subject: [PATCH] adding wrapper --- render.go | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/render.go b/render.go index 685d8c0..7939138 100644 --- a/render.go +++ b/render.go @@ -2,6 +2,7 @@ package pikchr import ( "bytes" + "fmt" "github.com/gebv/pikchr" "github.com/yuin/goldmark/ast" @@ -9,8 +10,6 @@ import ( "github.com/yuin/goldmark/util" ) -// const _defaultpikchrJS = "https://cdn.jsdelivr.net/npm/pikchr/dist/pikchr.min.js" - // Renderer renders pikchr diagrams as HTML, to be rendered into images // client side. type Renderer struct{} @@ -24,37 +23,17 @@ func (r *Renderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer) { // Render renders pikchr.Block nodes. func (r *Renderer) Render(w util.BufWriter, src []byte, node ast.Node, entering bool) (ast.WalkStatus, error) { n := node.(*Block) - // if entering { - // w.WriteString(`
`) - // lines := n.Lines() - // for i := 0; i < lines.Len(); i++ { - // line := lines.At(i) - // template.HTMLEscape(w, line.Value(src)) - // } - // } else { - // w.WriteString("
") - // } if !entering { raw := r.getLines(src, n) - // h := sha1.New() - // h.Write(raw) - // hash := string(h.Sum([]byte{})) - // if result, exist := u.buf[hash]; exist { - // _, _ = w.Write(result) - // } else { res, _ := pikchr.Render( string(raw), pikchr.HTMLError(), ) - svg := []byte(res.Data) - // if len(u.buf) >= u.MaxLength { - // u.buf = make(map[string][]byte) - // } - // u.buf[hash] = svg - _, _ = w.Write(svg) - // } + _, _ = w.WriteString(fmt.Sprintf(`
`, res.Width)) + _, _ = w.Write([]byte(res.Data)) + _, _ = w.WriteString("
") } return ast.WalkContinue, nil