From 6887fb2e0271a4b92eb728d58ea4676565a972ec Mon Sep 17 00:00:00 2001 From: Niklas Fasching Date: Sun, 16 Dec 2018 19:18:16 +0100 Subject: [PATCH] Add wasm demo to github pages --- .travis.yml | 1 + README.org | 4 +- etc/_wasm.go | 29 +++++++++++++ etc/generate-gh-pages | 94 ++++++++++++++++++++++++++++++++++++++---- org/testdata/misc.html | 1 + 5 files changed, 121 insertions(+), 8 deletions(-) create mode 100644 etc/_wasm.go diff --git a/.travis.yml b/.travis.yml index 804f24a..002f045 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: go +go: "1.x" script: - make test - make generate-gh-pages diff --git a/README.org b/README.org index 2f0a017..aff6da2 100644 --- a/README.org +++ b/README.org @@ -1,5 +1,7 @@ * go-org [[https://travis-ci.org/niklasfasching/go-org.svg?branch=master]] -A basic org-mode parser in go. Take a look at [[https://niklasfasching.github.io/go-org/][github pages]] for some output examples. +A basic org-mode parser in go. +Take a look at [[https://niklasfasching.github.io/go-org/][github pages]] for some examples and an online org->html demo. + * next - checkboxes - definition lists diff --git a/etc/_wasm.go b/etc/_wasm.go new file mode 100644 index 0000000..e668a9f --- /dev/null +++ b/etc/_wasm.go @@ -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("
%s
", err)) + } else { + out.Set("innerHTML", html) + } + })) + + <-make(chan struct{}) // stay alive +} diff --git a/etc/generate-gh-pages b/etc/generate-gh-pages index b0cadaf..ed613e5 100755 --- a/etc/generate-gh-pages +++ b/etc/generate-gh-pages @@ -1,7 +1,7 @@ #!/bin/bash org_files=org/testdata/*.org -content=" +examples="

Sections

+ + " + +index=" - $content + + $convert + $examples + +" + + +convert=" + + + + + $convert + " mkdir -p gh-pages -echo "$html" > gh-pages/index.html +echo "$index" > gh-pages/index.html +echo "$convert" > gh-pages/convert.html +cp etc/_wasm.go gh-pages/wasm.go +GOOS=js GOARCH=wasm go build -o gh-pages/main.wasm gh-pages/wasm.go +rm gh-pages/wasm.go +cp $(go env GOROOT)/misc/wasm/wasm_exec.js gh-pages/wasm_exec.js diff --git a/org/testdata/misc.html b/org/testdata/misc.html index 8ef9cf7..61971f2 100644 --- a/org/testdata/misc.html +++ b/org/testdata/misc.html @@ -67,6 +67,7 @@ example block

 language: go
+go: "1.x"
 script:
   - make test
   - make generate-gh-pages