aboutsummaryrefslogtreecommitdiffstats
path: root/modules/markup
diff options
context:
space:
mode:
Diffstat (limited to 'modules/markup')
-rw-r--r--modules/markup/html.go2
-rw-r--r--modules/markup/html_internal_test.go24
-rw-r--r--modules/markup/html_test.go36
3 files changed, 61 insertions, 1 deletions
diff --git a/modules/markup/html.go b/modules/markup/html.go
index da16bcd3cb..e53ccc6a79 100644
--- a/modules/markup/html.go
+++ b/modules/markup/html.go
@@ -852,7 +852,7 @@ func fullIssuePatternProcessor(ctx *RenderContext, node *html.Node) {
}
func issueIndexPatternProcessor(ctx *RenderContext, node *html.Node) {
- if ctx.Metas == nil {
+ if ctx.Metas == nil || ctx.Metas["mode"] == "document" {
return
}
var (
diff --git a/modules/markup/html_internal_test.go b/modules/markup/html_internal_test.go
index 00ffe45c28..7b7f6df701 100644
--- a/modules/markup/html_internal_test.go
+++ b/modules/markup/html_internal_test.go
@@ -262,6 +262,30 @@ func TestRender_IssueIndexPattern5(t *testing.T) {
})
}
+func TestRender_IssueIndexPattern_Document(t *testing.T) {
+ setting.AppURL = TestAppURL
+ metas := map[string]string{
+ "format": "https://someurl.com/{user}/{repo}/{index}",
+ "user": "someUser",
+ "repo": "someRepo",
+ "style": IssueNameStyleNumeric,
+ "mode": "document",
+ }
+
+ testRenderIssueIndexPattern(t, "#1", "#1", &RenderContext{
+ Ctx: git.DefaultContext,
+ Metas: metas,
+ })
+ testRenderIssueIndexPattern(t, "#1312", "#1312", &RenderContext{
+ Ctx: git.DefaultContext,
+ Metas: metas,
+ })
+ testRenderIssueIndexPattern(t, "!1", "!1", &RenderContext{
+ Ctx: git.DefaultContext,
+ Metas: metas,
+ })
+}
+
func testRenderIssueIndexPattern(t *testing.T, input, expected string, ctx *RenderContext) {
if ctx.URLPrefix == "" {
ctx.URLPrefix = TestAppURL
diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go
index a8d7ba7948..9156bc6331 100644
--- a/modules/markup/html_test.go
+++ b/modules/markup/html_test.go
@@ -529,6 +529,42 @@ func Test_ParseClusterFuzz(t *testing.T) {
assert.NotContains(t, res.String(), "<html")
}
+func TestPostProcess_RenderDocument(t *testing.T) {
+ setting.AppURL = TestAppURL
+
+ localMetas := map[string]string{
+ "user": "go-gitea",
+ "repo": "gitea",
+ "mode": "document",
+ }
+
+ test := func(input, expected string) {
+ var res strings.Builder
+ err := PostProcess(&RenderContext{
+ Ctx: git.DefaultContext,
+ URLPrefix: "https://example.com",
+ Metas: localMetas,
+ }, strings.NewReader(input), &res)
+ assert.NoError(t, err)
+ assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(res.String()))
+ }
+
+ // Issue index shouldn't be post processing in an document.
+ test(
+ "#1",
+ "#1")
+
+ // Test that other post processing still works.
+ test(
+ ":gitea:",
+ `<span class="emoji" aria-label="gitea"><img alt=":gitea:" src="`+setting.StaticURLPrefix+`/assets/img/emoji/gitea.png"/></span>`)
+ test(
+ "Some text with 😄 in the middle",
+ `Some text with <span class="emoji" aria-label="grinning face with smiling eyes">😄</span> in the middle`)
+ test("http://localhost:3000/person/repo/issues/4#issuecomment-1234",
+ `<a href="http://localhost:3000/person/repo/issues/4#issuecomment-1234" class="ref-issue">person/repo#4 (comment)</a>`)
+}
+
func TestIssue16020(t *testing.T) {
setting.AppURL = TestAppURL