瀏覽代碼

added markdown processing to html

bmallred 9 年之前
父節點
當前提交
42125d9add
共有 2 個文件被更改,包括 31 次插入0 次删除
  1. 12 0
      markdown.go
  2. 19 0
      markdown_test.go

+ 12 - 0
markdown.go

@ -0,0 +1,12 @@
1
package main
2
3
import (
4
	"github.com/microcosm-cc/bluemonday"
5
	"github.com/russross/blackfriday"
6
)
7
8
func MarkdownToHtml(markdown []byte) []byte {
9
	unsafe := blackfriday.MarkdownCommon(markdown)
10
	html := bluemonday.UGCPolicy().SanitizeBytes(unsafe)
11
	return html
12
}

+ 19 - 0
markdown_test.go

@ -0,0 +1,19 @@
1
package main
2
3
import "testing"
4
5
func TestMarkdownToHtml(t *testing.T) {
6
	markdown := `title
7
====
8
9
and now a list
10
 - item 1
11
 - item 2
12
13
and a [hyperlink](https://google.com).`
14
15
	html := MarkdownToHtml([]byte(markdown))
16
	if string(html) == "" {
17
		t.Error("Failed to convert markdown to HTML")
18
	}
19
}