package markdown_test import ( "testing" "git.akyoto.dev/go/assert" "git.akyoto.dev/go/markdown" ) func TestEmpty(t *testing.T) { assert.Equal(t, markdown.Render(""), "") } func TestParagraph(t *testing.T) { assert.Equal(t, markdown.Render("Text"), "

Text

") assert.Equal(t, markdown.Render("Text\n"), "

Text

") assert.Equal(t, markdown.Render("Text\n\n"), "

Text

") assert.Equal(t, markdown.Render("Text\n\n\n"), "

Text

") assert.Equal(t, markdown.Render("Line 1\nLine 2"), "

Line 1 Line 2

") assert.Equal(t, markdown.Render("Line 1\n\nLine 2"), "

Line 1

Line 2

") } func TestHeader(t *testing.T) { assert.Equal(t, markdown.Render("# Header"), "

Header

") assert.Equal(t, markdown.Render("## Header"), "

Header

") assert.Equal(t, markdown.Render("### Header"), "

Header

") assert.Equal(t, markdown.Render("#### Header"), "

Header

") assert.Equal(t, markdown.Render("##### Header"), "
Header
") assert.Equal(t, markdown.Render("###### Header"), "
Header
") } func TestLink(t *testing.T) { assert.Equal(t, markdown.Render("[text](https://example.com/)"), "

text

") assert.Equal(t, markdown.Render("[text](https://example.com/"), "

[text](https://example.com/

") assert.Equal(t, markdown.Render("[text]https://example.com/)"), "

[text]https://example.com/)

") assert.Equal(t, markdown.Render("[text(https://example.com/)"), "

[text(https://example.com/)

") assert.Equal(t, markdown.Render("text](https://example.com/)"), "

text](https://example.com/)

") assert.Equal(t, markdown.Render("Prefix [text](https://example.com/) suffix."), "

Prefix text suffix.

") } func TestList(t *testing.T) { assert.Equal(t, markdown.Render("- Entry"), "") assert.Equal(t, markdown.Render("- Entry 1\n- Entry 2"), "") assert.Equal(t, markdown.Render("- Entry 1\n- Entry 2\n- Entry 3"), "") } func TestTables(t *testing.T) { assert.Equal(t, markdown.Render("| Head |\n| --- |\n| Body |"), "
Head
Body
") assert.Equal(t, markdown.Render("| 1 | 2 |\n| --- | --- |\n| 1 | 2 |"), "
12
12
") } func TestCode(t *testing.T) { assert.Equal(t, markdown.Render("```\nText\n```"), "
Text
") assert.Equal(t, markdown.Render("```go\ntype A struct {\n\t\n}\n```"), "
type A struct {\n\t\n}
") } func TestQuote(t *testing.T) { assert.Equal(t, markdown.Render("> Line"), "

Line

") assert.Equal(t, markdown.Render("> Line 1\n> Line 2"), "

Line 1 Line 2

") assert.Equal(t, markdown.Render("> Line 1\n\nLine 2"), "

Line 1

Line 2

") assert.Equal(t, markdown.Render("> Line 1\n>>Line 2"), "

Line 1

Line 2

") assert.Equal(t, markdown.Render("Line 1\n> Line 2\n> Line 3\nLine 4"), "

Line 1

Line 2 Line 3

Line 4

") } func TestCombined(t *testing.T) { assert.Equal(t, markdown.Render("# Header\n\nLine 1."), "

Header

Line 1.

") assert.Equal(t, markdown.Render("# Header\nLine 1.\nLine 2.\nLine 3."), "

Header

Line 1. Line 2. Line 3.

") assert.Equal(t, markdown.Render("# Header 1\nLine 1.\n# Header 2\nLine 2."), "

Header 1

Line 1.

Header 2

Line 2.

") assert.Equal(t, markdown.Render("# [Header Link](https://example.com/)"), "

Header Link

") assert.Equal(t, markdown.Render("# Title\n\n- Entry 1\n- Entry 2\n\nText."), "

Title

Text.

") assert.Equal(t, markdown.Render("- Entry\n# Header"), "

Header

") assert.Equal(t, markdown.Render("> - Entry\n> # Header"), "

Header

") } func TestSecurity(t *testing.T) { assert.Equal(t, markdown.Render("[text](javascript:alert(\"xss\"))"), "

text

") assert.Equal(t, markdown.Render("[text](javAscRipt:alert(\"xss\"))"), "

text

") assert.Equal(t, markdown.Render("[text]( javascript:alert(\"xss\"))"), "

text

") assert.Equal(t, markdown.Render("[text]('javAscRipt:alert(\"xss\")')"), "

text

") assert.Equal(t, markdown.Render("[text](\">)"), "

text

") assert.Equal(t, markdown.Render("[]()"), "

<script>alert(123)</script>

") }