Debian Codegraph @

format/markdown_test.go

raw
1 // Copyright (c) 2022 Tulir Asokan
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7 package format_test
8
9 import (
10 "strings"
11 "testing"
12
13 "github.com/stretchr/testify/assert"
14
15 "maunium.net/go/mautrix/format"
16 )
17
18 var spoilerTests = map[string]string{
19 "test ||bar||": "test <span data-mx-spoiler>bar</span>",
20 "test ||reason|**bar**||": `test <span data-mx-spoiler="reason"><strong>bar</strong></span>`,
21
22 "test ||reason|[bar](https://example.com)||": `test <span data-mx-spoiler="reason"><a href="https://example.com">bar</a></span>`,
23 "test [||reason|foo||](https://example.com)": `test <a href="https://example.com"><span data-mx-spoiler="reason">foo</span></a>`,
24 "test [||foo||](https://example.com)": `test <a href="https://example.com"><span data-mx-spoiler>foo</span></a>`,
25 "test [||*foo*||](https://example.com)": `test <a href="https://example.com"><span data-mx-spoiler><em>foo</em></span></a>`,
26 // FIXME wrapping spoilers in italic/bold/strikethrough doesn't work for some reason
27 //"test **[||foo||](https://example.com)**": `test <strong><a href="https://example.com"><span data-mx-spoiler>foo</span></a></strong>`,
28 //"test **||foo||**": `test <strong><span data-mx-spoiler><em>foo</span></strong>`,
29
30 "* ||foo||": `<ul><li><span data-mx-spoiler>foo</span></li></ul>`,
31 "> ||foo||": "<blockquote><p><span data-mx-spoiler>foo</span></p></blockquote>",
32 }
33
34 func TestRenderMarkdown_Spoiler(t *testing.T) {
35 for markdown, html := range spoilerTests {
36 rendered := format.RenderMarkdown(markdown, true, false)
37 // FIXME the HTML parser doesn't do spoilers yet
38 //assert.Equal(t, plaintext, rendered.Body)
39 assert.Equal(t, html, strings.ReplaceAll(rendered.FormattedBody, "\n", ""))
40 }
41 }