Bladeren bron

added markdown processing to html

bmallred 9 jaren geleden
bovenliggende
commit
42125d9add
2 gewijzigde bestanden met toevoegingen van 31 en 0 verwijderingen
  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
}