mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-10-17 00:34:01 -04:00
30 lines
851 B
Go
30 lines
851 B
Go
package highlight
|
|
|
|
import (
|
|
"bytes"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/AvengeMedia/DankMaterialShell/core/internal/highlight/styles"
|
|
"github.com/alecthomas/chroma/v2/formatters/html"
|
|
"github.com/yuin/goldmark"
|
|
)
|
|
|
|
func TestMarkdown(t *testing.T) {
|
|
md := goldmark.New(goldmark.WithExtensions(Markdown{Style: styles.Get("monokai"), Formatter: html.New(html.WithClasses(false))}))
|
|
cases := []struct{ in, want string }{
|
|
{"```go\nfunc main() {}\n```\n", `style="color:`},
|
|
{"```nope\na < b\n```\n", `<pre><code class="language-nope">a < b`},
|
|
{"```\nplain\n```\n", `<pre><code>plain`},
|
|
}
|
|
for _, tc := range cases {
|
|
var out bytes.Buffer
|
|
if err := md.Convert([]byte(tc.in), &out); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !strings.Contains(out.String(), tc.want) {
|
|
t.Errorf("%q rendered %q, want %q", tc.in, out.String(), tc.want)
|
|
}
|
|
}
|
|
}
|