Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Work on testing markdownfmt nested branch.
- Loading branch information
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |