2024-04-03 01:48:27 +08:00
|
|
|
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package markup_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"html/template"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/git"
|
|
|
|
"code.gitea.io/gitea/modules/markup"
|
2024-11-14 13:02:11 +08:00
|
|
|
"code.gitea.io/gitea/modules/markup/markdown"
|
2024-04-03 01:48:27 +08:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRenderCodePreview(t *testing.T) {
|
|
|
|
markup.Init(&markup.ProcessorHelper{
|
|
|
|
RenderRepoFileCodePreview: func(ctx context.Context, opts markup.RenderCodePreviewOptions) (template.HTML, error) {
|
|
|
|
return "<div>code preview</div>", nil
|
|
|
|
},
|
|
|
|
})
|
|
|
|
test := func(input, expected string) {
|
|
|
|
buffer, err := markup.RenderString(&markup.RenderContext{
|
2024-11-14 13:02:11 +08:00
|
|
|
Ctx: git.DefaultContext,
|
|
|
|
MarkupType: markdown.MarkupName,
|
2024-04-03 01:48:27 +08:00
|
|
|
}, input)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
|
|
|
|
}
|
|
|
|
test("http://localhost:3000/owner/repo/src/commit/0123456789/foo/bar.md#L10-L20", "<p><div>code preview</div></p>")
|
2024-11-07 11:57:07 +08:00
|
|
|
test("http://other/owner/repo/src/commit/0123456789/foo/bar.md#L10-L20", `<p><a href="http://other/owner/repo/src/commit/0123456789/foo/bar.md#L10-L20" data-markdown-generated-content="" rel="nofollow">http://other/owner/repo/src/commit/0123456789/foo/bar.md#L10-L20</a></p>`)
|
2024-04-03 01:48:27 +08:00
|
|
|
}
|