Skip to content

Commit

Permalink
Work on testing markdownfmt nested branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitshur committed Sep 29, 2014
1 parent 1c35f48 commit 5bdbf89
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
23 changes: 23 additions & 0 deletions 60/live-markdownfmt.html
@@ -0,0 +1,23 @@
<html>
<head>
<style type="text/css">
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
}
* {
tab-size: 4;
}

textarea, pre {
font-family: "Menlo", monospace;
font-size: 12px;
}
</style>
</head>
<body>
<h1>Live markdownfmt</h1>
<textarea id="input" cols=60 rows=30 autofocus>Loading...</textarea>
<pre id="output" style="display: inline-block; margin: 0px; vertical-align: top;"></pre>
<script type="text/go" src="markdownfmt.go"></script>
</body>
</html>
72 changes: 72 additions & 0 deletions 60/markdownfmt.go
@@ -0,0 +1,72 @@
// +build js

package main

import (
"github.com/shurcooL/go/u/u9"
"github.com/shurcooL/markdownfmt/markdown"

"honnef.co/go/js/dom"
)

var document = dom.GetWindow().Document()

var input = document.GetElementByID("input").(*dom.HTMLTextAreaElement)
var output = document.GetElementByID("output").(dom.HTMLElement)

var initial = `Title
==
Hello there.
1. Item one.
1. Item TWO.
| Branch | Behind | Ahead |
|---------|-------:|:------|
| improve-nested-list-support | 1 | 1 |
| **master** | 0 | 0 |
3. Item 1
Another paragraph inside this list item is ` + `
indented just like the previous paragraph.
4. Item 2
- Item 2a
Things go here.
> This a quote within a list.
And they stay here.
- Item 2b
- Item 333!
Yep.
- Item 4444!
Why not?
- Item 3
`

func run(event dom.Event) {
output.SetTextContent(ProcessMarkdown(input.Value))
}

func ProcessMarkdown(text string) string {
output, err := markdown.Process("", []byte(text), nil)
if err != nil {
println("ProcessMarkdown:", err.Error())
return text
}
return string(output)
}

func main() {
input.AddEventListener("input", false, run)
input.Value = initial
input.SelectionStart, input.SelectionEnd = len(initial), len(initial)
run(nil)

u9.AddTabSupport(input)
}

0 comments on commit 5bdbf89

Please sign in to comment.