Add wasm demo to github pages
This commit is contained in:
parent
8a9bc2bead
commit
6887fb2e02
5 changed files with 121 additions and 8 deletions
29
etc/_wasm.go
Normal file
29
etc/_wasm.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"syscall/js"
|
||||
|
||||
"github.com/niklasfasching/go-org/org"
|
||||
)
|
||||
|
||||
func main() {
|
||||
js.Global().Call("initialized")
|
||||
|
||||
document := js.Global().Get("document")
|
||||
in := document.Call("getElementById", "input")
|
||||
out := document.Call("getElementById", "output")
|
||||
|
||||
js.Global().Set("run", js.NewCallback(func([]js.Value) {
|
||||
in := strings.NewReader(in.Get("value").String())
|
||||
html, err := org.NewDocument().Parse(in).Write(org.NewHTMLWriter())
|
||||
if err != nil {
|
||||
out.Set("innerHTML", fmt.Sprintf("<pre>%s</pre>", err))
|
||||
} else {
|
||||
out.Set("innerHTML", html)
|
||||
}
|
||||
}))
|
||||
|
||||
<-make(chan struct{}) // stay alive
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue