Implemented separators

This commit is contained in:
Eduard Urbach 2024-04-02 19:25:42 +02:00
parent 4a4b9e168b
commit a06f513d65
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
3 changed files with 12 additions and 0 deletions

View File

@ -10,6 +10,7 @@ A markdown renderer that supports only a subset of the CommonMark spec in order
- Headers - Headers
- Paragraphs - Paragraphs
- Quotes - Quotes
- Separators
- Tables - Tables
## Installation ## Installation
@ -35,6 +36,7 @@ PASS: TestList
PASS: TestTables PASS: TestTables
PASS: TestCode PASS: TestCode
PASS: TestQuote PASS: TestQuote
PASS: TestSeparator
PASS: TestCombined PASS: TestCombined
PASS: TestSecurity PASS: TestSecurity
coverage: 100.0% of statements coverage: 100.0% of statements

View File

@ -117,6 +117,11 @@ func (r *renderer) processLine(line string) {
return return
case '-', '*': case '-', '*':
if strings.HasPrefix(line, "---") {
r.WriteString("<hr>")
return
}
line = strings.TrimSpace(line[1:]) line = strings.TrimSpace(line[1:])
if r.listLevel == 0 { if r.listLevel == 0 {

View File

@ -64,6 +64,11 @@ func TestQuote(t *testing.T) {
assert.Equal(t, markdown.Render("Line 1\n> Line 2\n> Line 3\nLine 4"), "<p>Line 1</p><blockquote><p>Line 2 Line 3</p></blockquote><p>Line 4</p>") assert.Equal(t, markdown.Render("Line 1\n> Line 2\n> Line 3\nLine 4"), "<p>Line 1</p><blockquote><p>Line 2 Line 3</p></blockquote><p>Line 4</p>")
} }
func TestSeparator(t *testing.T) {
assert.Equal(t, markdown.Render("---"), "<hr>")
assert.Equal(t, markdown.Render("Line 1\n\n---\n\nLine 2"), "<p>Line 1</p><hr><p>Line 2</p>")
}
func TestCombined(t *testing.T) { func TestCombined(t *testing.T) {
assert.Equal(t, markdown.Render("# Header\n\nLine 1."), "<h1>Header</h1><p>Line 1.</p>") assert.Equal(t, markdown.Render("# Header\n\nLine 1."), "<h1>Header</h1><p>Line 1.</p>")
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\nLine 1.\nLine 2.\nLine 3."), "<h1>Header</h1><p>Line 1. Line 2. Line 3.</p>")