go-org-orgwiki/etc/_wasm.go
Niklas Fasching 3655a58b63 Update github pages demo for go 1.12+
- go 1.12 optimizes memory allocation for wasm - see
  https://github.com/golang/go/issues/27462. This was causing the demo to OOM
  on memory restricted devices (e.g. phones).
- js namespace changed so we need to adapt to that
2019-06-03 17:01:38 +02:00

27 lines
629 B
Go

package main
import (
"fmt"
"strings"
"syscall/js"
"github.com/niklasfasching/go-org/org"
)
func main() {
js.Global().Call("initialized")
doc := js.Global().Get("document")
in, out := doc.Call("getElementById", "input"), doc.Call("getElementById", "output")
js.Global().Set("run", js.FuncOf(func(js.Value, []js.Value) interface{} {
in := strings.NewReader(in.Get("value").String())
html, err := org.New().Parse(in, "").Write(org.NewHTMLWriter())
if err != nil {
out.Set("innerHTML", fmt.Sprintf("<pre>%s</pre>", err))
} else {
out.Set("innerHTML", html)
}
return nil
}))
select {} // stay alive
}