Add wasm demo to github pages
This commit is contained in:
parent
8a9bc2bead
commit
6887fb2e02
5 changed files with 121 additions and 8 deletions
|
@ -1,4 +1,5 @@
|
||||||
language: go
|
language: go
|
||||||
|
go: "1.x"
|
||||||
script:
|
script:
|
||||||
- make test
|
- make test
|
||||||
- make generate-gh-pages
|
- make generate-gh-pages
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
* go-org [[https://travis-ci.org/niklasfasching/go-org.svg?branch=master]]
|
* 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
|
* next
|
||||||
- checkboxes
|
- checkboxes
|
||||||
- definition lists
|
- definition lists
|
||||||
|
|
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
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
org_files=org/testdata/*.org
|
org_files=org/testdata/*.org
|
||||||
content="
|
examples="
|
||||||
<h1>Sections</h1>
|
<h1>Sections</h1>
|
||||||
<style>
|
<style>
|
||||||
.sections { margin-left: 2rem; }
|
.sections { margin-left: 2rem; }
|
||||||
|
@ -11,14 +11,14 @@ content="
|
||||||
<ul class='sections'>"
|
<ul class='sections'>"
|
||||||
for org_file in $org_files; do
|
for org_file in $org_files; do
|
||||||
name=$(basename $org_file)
|
name=$(basename $org_file)
|
||||||
content+="<li><a id='toc-${name}' href='#${name}'>${name}</a>"
|
examples+="<li><a id='toc-${name}' href='#${name}'>${name}</a>"
|
||||||
done
|
done
|
||||||
content+="</ul><hr>"
|
examples+="</ul><hr>"
|
||||||
|
|
||||||
for org_file in $org_files; do
|
for org_file in $org_files; do
|
||||||
echo generating content for $org_file
|
echo generating content for $org_file
|
||||||
name=$(basename $org_file)
|
name=$(basename $org_file)
|
||||||
content+="
|
examples+="
|
||||||
<h2><a id='${name}' href='#toc-${name}'>${name}</a></h2>
|
<h2><a id='${name}' href='#toc-${name}'>${name}</a></h2>
|
||||||
<div class='source'>
|
<div class='source'>
|
||||||
<pre class='org'>$(sed 's/&/\&/g; s/</\</g; s/>/\>/g;' $org_file)</pre>
|
<pre class='org'>$(sed 's/&/\&/g; s/</\</g; s/>/\>/g;' $org_file)</pre>
|
||||||
|
@ -26,7 +26,69 @@ for org_file in $org_files; do
|
||||||
</div>"
|
</div>"
|
||||||
done
|
done
|
||||||
|
|
||||||
html="<html>
|
convert="
|
||||||
|
<h1>Convert</h1>
|
||||||
|
<button id='run' disabled='true' onclick='run()'>
|
||||||
|
RUN (initializing...)
|
||||||
|
</button>
|
||||||
|
or ctrl + return
|
||||||
|
<textarea id='input'>* Hello World</textarea>
|
||||||
|
<div id='output'></div>
|
||||||
|
<style>
|
||||||
|
#run {
|
||||||
|
background-color: #50CCDD;
|
||||||
|
border: none;
|
||||||
|
border-radius: 0.33em;
|
||||||
|
color: #FFF;
|
||||||
|
cursor: pointer;
|
||||||
|
font-weight: bold;
|
||||||
|
letter-spacing: 0.1em;
|
||||||
|
padding: 0.5em 1.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
#run:hover {
|
||||||
|
background-color: #40AACC;
|
||||||
|
outline: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#run:disabled {
|
||||||
|
background-color: #AAA;
|
||||||
|
cursor: wait;
|
||||||
|
}
|
||||||
|
|
||||||
|
#input, #output {
|
||||||
|
display: block;
|
||||||
|
border: 1px dashed grey;
|
||||||
|
margin: 0.5em 0;
|
||||||
|
overflow: auto;
|
||||||
|
padding: 0.25em;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
#input { height: 30%; }
|
||||||
|
#output { max-height: 100%; }
|
||||||
|
</style>
|
||||||
|
<script src='wasm_exec.js'></script>
|
||||||
|
<script>
|
||||||
|
const go = new Go();
|
||||||
|
WebAssembly
|
||||||
|
.instantiateStreaming(fetch('main.wasm'), go.importObject)
|
||||||
|
.then((result) => go.run(result.instance));
|
||||||
|
|
||||||
|
function initialized() {
|
||||||
|
const button = document.getElementById('run');
|
||||||
|
button.textContent = 'RUN';
|
||||||
|
button.removeAttribute('disabled');
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('input').addEventListener('keydown', function(e) {
|
||||||
|
if (e.keyCode == 13 && e.ctrlKey) { // ctrl+enter
|
||||||
|
run();
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
}, false)
|
||||||
|
</script>"
|
||||||
|
|
||||||
|
index="<html>
|
||||||
<head>
|
<head>
|
||||||
<style>$(cat etc/style.css)</style>
|
<style>$(cat etc/style.css)</style>
|
||||||
<style>
|
<style>
|
||||||
|
@ -41,8 +103,26 @@ html="<html>
|
||||||
overflow-x: auto; }
|
overflow-x: auto; }
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>$content</body>
|
<body>
|
||||||
|
$convert
|
||||||
|
$examples
|
||||||
|
</body>
|
||||||
|
</html>"
|
||||||
|
|
||||||
|
|
||||||
|
convert="<html>
|
||||||
|
<head>
|
||||||
|
<style>$(cat etc/style.css)</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
$convert
|
||||||
|
</body>
|
||||||
</html>"
|
</html>"
|
||||||
|
|
||||||
mkdir -p gh-pages
|
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
|
||||||
|
|
1
org/testdata/misc.html
vendored
1
org/testdata/misc.html
vendored
|
@ -67,6 +67,7 @@ example block
|
||||||
</p>
|
</p>
|
||||||
<pre class="example">
|
<pre class="example">
|
||||||
language: go
|
language: go
|
||||||
|
go: "1.x"
|
||||||
script:
|
script:
|
||||||
- make test
|
- make test
|
||||||
- make generate-gh-pages
|
- make generate-gh-pages
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue