Skip to content

Commit

Permalink
adding wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
jchenry committed Jan 22, 2022
1 parent 11e98c7 commit 347bda3
Showing 1 changed file with 4 additions and 25 deletions.
29 changes: 4 additions & 25 deletions render.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package pikchr

import (
"bytes"
"fmt"

"github.com/gebv/pikchr"
"github.com/yuin/goldmark/ast"
"github.com/yuin/goldmark/renderer"
"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{}
Expand All @@ -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(`<div class="pikchr">`)
// lines := n.Lines()
// for i := 0; i < lines.Len(); i++ {
// line := lines.At(i)
// template.HTMLEscape(w, line.Value(src))
// }
// } else {
// w.WriteString("</div>")
// }

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(`<div class="pikchr-svg" style="max-width:%dx">`, res.Width))
_, _ = w.Write([]byte(res.Data))
_, _ = w.WriteString("</div>")
}

return ast.WalkContinue, nil
Expand Down

0 comments on commit 347bda3

Please sign in to comment.