2017-08-18 17:07:01 +02:00
|
|
|
package renderers
|
2017-08-11 23:16:49 +02:00
|
|
|
|
|
|
|
import (
|
2017-08-22 16:47:34 +02:00
|
|
|
"log"
|
2017-08-11 23:16:49 +02:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2017-08-22 16:47:34 +02:00
|
|
|
func TestRenderMarkdown(t *testing.T) {
|
|
|
|
require.Equal(t, "<p><em>b</em></p>\n", mustMarkdownString("*b*"))
|
|
|
|
require.Equal(t, "<div>*b*</div>\n", mustMarkdownString("<div>*b*</div>"))
|
|
|
|
require.Equal(t, "<div a=1><p><em>b</em></p>\n</div>\n", mustMarkdownString(`<div a=1 markdown="1">*b*</div>`))
|
|
|
|
require.Equal(t, "<div a=1><p><em>b</em></p>\n</div>\n", mustMarkdownString(`<div a=1 markdown='1'>*b*</div>`))
|
|
|
|
require.Equal(t, "<div a=1><p><em>b</em></p>\n</div>\n", mustMarkdownString(`<div a=1 markdown=1>*b*</div>`))
|
|
|
|
|
|
|
|
_, err := renderMarkdownString(`<div a=1 markdown=1><p></div>`)
|
|
|
|
require.NotNil(t, err)
|
2017-08-11 23:16:49 +02:00
|
|
|
}
|
|
|
|
|
2017-08-22 16:47:34 +02:00
|
|
|
func mustMarkdownString(md string) string {
|
|
|
|
s, err := renderMarkdown([]byte(md))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
return string(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func renderMarkdownString(md string) (string, error) {
|
|
|
|
s, err := renderMarkdown([]byte(md))
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return string(s), err
|
2017-08-11 23:16:49 +02:00
|
|
|
}
|