Implemented links
This commit is contained in:
@ -11,7 +11,7 @@ func TestEmpty(t *testing.T) {
|
||||
assert.Equal(t, markdown.Render(""), "")
|
||||
}
|
||||
|
||||
func TestParagraphs(t *testing.T) {
|
||||
func TestParagraph(t *testing.T) {
|
||||
assert.Equal(t, markdown.Render("Text"), "<p>Text</p>")
|
||||
assert.Equal(t, markdown.Render("Text\n"), "<p>Text</p>")
|
||||
assert.Equal(t, markdown.Render("Text\n\n"), "<p>Text</p>")
|
||||
@ -28,7 +28,24 @@ func TestHeader(t *testing.T) {
|
||||
assert.Equal(t, markdown.Render("###### Header"), "<h6>Header</h6>")
|
||||
}
|
||||
|
||||
func TestLink(t *testing.T) {
|
||||
assert.Equal(t, markdown.Render("[text](https://example.com/)"), "<p><a href=\"https://example.com/\">text</a></p>")
|
||||
assert.Equal(t, markdown.Render("[text](https://example.com/"), "<p>[text](https://example.com/</p>")
|
||||
assert.Equal(t, markdown.Render("[text]https://example.com/)"), "<p>[text]https://example.com/)</p>")
|
||||
assert.Equal(t, markdown.Render("[text(https://example.com/)"), "<p>[text(https://example.com/)</p>")
|
||||
assert.Equal(t, markdown.Render("text](https://example.com/)"), "<p>text](https://example.com/)</p>")
|
||||
assert.Equal(t, markdown.Render("Prefix [text](https://example.com/) suffix."), "<p>Prefix <a href=\"https://example.com/\">text</a> suffix.</p>")
|
||||
}
|
||||
|
||||
func TestCombined(t *testing.T) {
|
||||
assert.Equal(t, markdown.Render("# Header\nLine 1.\nLine 2.\nLine 3."), "<h1>Header</h1><p>Line 1. Line 2. Line 3.</p>")
|
||||
assert.Equal(t, markdown.Render("# Header 1\nLine 1.\n# Header 2\nLine 2."), "<h1>Header 1</h1><p>Line 1.</p><h1>Header 2</h1><p>Line 2.</p>")
|
||||
assert.Equal(t, markdown.Render("# [Header Link](https://example.com/)"), "<h1><a href=\"https://example.com/\">Header Link</a></h1>")
|
||||
}
|
||||
|
||||
func TestSecurity(t *testing.T) {
|
||||
assert.Equal(t, markdown.Render("[text](javascript:alert(\"xss\"))"), "<p><a href=\"\">text</a></p>")
|
||||
assert.Equal(t, markdown.Render("[text](javAscRipt:alert(\"xss\"))"), "<p><a href=\"\">text</a></p>")
|
||||
assert.Equal(t, markdown.Render("[text](\"><div>html</div>)"), "<p><a href=\""><div>html</div>\">text</a></p>")
|
||||
assert.Equal(t, markdown.Render("[<div>html</div>]()"), "<p><a href=\"\"><div>html</div></a></p>")
|
||||
}
|
||||
|
Reference in New Issue
Block a user