aboutsummaryrefslogtreecommitdiffstats
path: root/modules/markup
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-11-07 11:57:07 +0800
committerGitHub <noreply@github.com>2024-11-07 03:57:07 +0000
commit145e26698791221b007c7dd460fb506cb0237235 (patch)
treeceeff90fbc2a1e97d906daa9a8023b399c04dcf8 /modules/markup
parent276500c314db1c0ef360088753861ffc010a99da (diff)
downloadgitea-145e26698791221b007c7dd460fb506cb0237235.tar.gz
gitea-145e26698791221b007c7dd460fb506cb0237235.zip
Support quote selected comments to reply (#32431)
Many existing tests were quite hacky, these could be improved later. <details> ![image](https://github.com/user-attachments/assets/93aebb4f-9de5-4cb8-910b-50c64cbcd25a) </details>
Diffstat (limited to 'modules/markup')
-rw-r--r--modules/markup/html.go5
-rw-r--r--modules/markup/html_codepreview_test.go2
-rw-r--r--modules/markup/html_internal_test.go12
-rw-r--r--modules/markup/html_test.go16
-rw-r--r--modules/markup/markdown/markdown_test.go12
-rw-r--r--modules/markup/sanitizer_default.go1
6 files changed, 32 insertions, 16 deletions
diff --git a/modules/markup/html.go b/modules/markup/html.go
index a9c3dc9ba2..e2eefefc4b 100644
--- a/modules/markup/html.go
+++ b/modules/markup/html.go
@@ -442,7 +442,10 @@ func createLink(href, content, class string) *html.Node {
a := &html.Node{
Type: html.ElementNode,
Data: atom.A.String(),
- Attr: []html.Attribute{{Key: "href", Val: href}},
+ Attr: []html.Attribute{
+ {Key: "href", Val: href},
+ {Key: "data-markdown-generated-content"},
+ },
}
if class != "" {
diff --git a/modules/markup/html_codepreview_test.go b/modules/markup/html_codepreview_test.go
index d33630d040..a90de278f5 100644
--- a/modules/markup/html_codepreview_test.go
+++ b/modules/markup/html_codepreview_test.go
@@ -30,5 +30,5 @@ func TestRenderCodePreview(t *testing.T) {
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>")
- 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" rel="nofollow">http://other/owner/repo/src/commit/0123456789/foo/bar.md#L10-L20</a></p>`)
+ 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>`)
}
diff --git a/modules/markup/html_internal_test.go b/modules/markup/html_internal_test.go
index 74089cffdd..8f516751b0 100644
--- a/modules/markup/html_internal_test.go
+++ b/modules/markup/html_internal_test.go
@@ -33,11 +33,9 @@ func numericIssueLink(baseURL, class string, index int, marker string) string {
// link an HTML link
func link(href, class, contents string) string {
- if class != "" {
- class = " class=\"" + class + "\""
- }
-
- return fmt.Sprintf("<a href=\"%s\"%s>%s</a>", href, class, contents)
+ extra := ` data-markdown-generated-content=""`
+ extra += util.Iif(class != "", ` class="`+class+`"`, "")
+ return fmt.Sprintf(`<a href="%s"%s>%s</a>`, href, extra, contents)
}
var numericMetas = map[string]string{
@@ -353,7 +351,9 @@ func TestRender_FullIssueURLs(t *testing.T) {
Metas: localMetas,
}, []processor{fullIssuePatternProcessor}, strings.NewReader(input), &result)
assert.NoError(t, err)
- assert.Equal(t, expected, result.String())
+ actual := result.String()
+ actual = strings.ReplaceAll(actual, ` data-markdown-generated-content=""`, "")
+ assert.Equal(t, expected, actual)
}
test("Here is a link https://git.osgeo.org/gogs/postgis/postgis/pulls/6",
"Here is a link https://git.osgeo.org/gogs/postgis/postgis/pulls/6")
diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go
index 32858dbd6b..82aded4407 100644
--- a/modules/markup/html_test.go
+++ b/modules/markup/html_test.go
@@ -116,7 +116,9 @@ func TestRender_CrossReferences(t *testing.T) {
Metas: localMetas,
}, input)
assert.NoError(t, err)
- assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
+ actual := strings.TrimSpace(buffer)
+ actual = strings.ReplaceAll(actual, ` data-markdown-generated-content=""`, "")
+ assert.Equal(t, strings.TrimSpace(expected), actual)
}
test(
@@ -156,7 +158,9 @@ func TestRender_links(t *testing.T) {
},
}, input)
assert.NoError(t, err)
- assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
+ actual := strings.TrimSpace(buffer)
+ actual = strings.ReplaceAll(actual, ` data-markdown-generated-content=""`, "")
+ assert.Equal(t, strings.TrimSpace(expected), actual)
}
oldCustomURLSchemes := setting.Markdown.CustomURLSchemes
@@ -267,7 +271,9 @@ func TestRender_email(t *testing.T) {
},
}, input)
assert.NoError(t, err)
- assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(res))
+ actual := strings.TrimSpace(res)
+ actual = strings.ReplaceAll(actual, ` data-markdown-generated-content=""`, "")
+ assert.Equal(t, strings.TrimSpace(expected), actual)
}
// Text that should be turned into email link
@@ -616,7 +622,9 @@ func TestPostProcess_RenderDocument(t *testing.T) {
Metas: localMetas,
}, strings.NewReader(input), &res)
assert.NoError(t, err)
- assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(res.String()))
+ actual := strings.TrimSpace(res.String())
+ actual = strings.ReplaceAll(actual, ` data-markdown-generated-content=""`, "")
+ assert.Equal(t, strings.TrimSpace(expected), actual)
}
// Issue index shouldn't be post processing in a document.
diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go
index cfb821ab19..ad38e7a088 100644
--- a/modules/markup/markdown/markdown_test.go
+++ b/modules/markup/markdown/markdown_test.go
@@ -311,7 +311,8 @@ func TestTotal_RenderWiki(t *testing.T) {
IsWiki: true,
}, sameCases[i])
assert.NoError(t, err)
- assert.Equal(t, template.HTML(answers[i]), line)
+ actual := strings.ReplaceAll(string(line), ` data-markdown-generated-content=""`, "")
+ assert.Equal(t, answers[i], actual)
}
testCases := []string{
@@ -336,7 +337,8 @@ func TestTotal_RenderWiki(t *testing.T) {
IsWiki: true,
}, testCases[i])
assert.NoError(t, err)
- assert.Equal(t, template.HTML(testCases[i+1]), line)
+ actual := strings.ReplaceAll(string(line), ` data-markdown-generated-content=""`, "")
+ assert.EqualValues(t, testCases[i+1], actual)
}
}
@@ -356,7 +358,8 @@ func TestTotal_RenderString(t *testing.T) {
Metas: localMetas,
}, sameCases[i])
assert.NoError(t, err)
- assert.Equal(t, template.HTML(answers[i]), line)
+ actual := strings.ReplaceAll(string(line), ` data-markdown-generated-content=""`, "")
+ assert.Equal(t, answers[i], actual)
}
testCases := []string{}
@@ -996,7 +999,8 @@ space</p>
for i, c := range cases {
result, err := markdown.RenderString(&markup.RenderContext{Ctx: context.Background(), Links: c.Links, IsWiki: c.IsWiki}, input)
assert.NoError(t, err, "Unexpected error in testcase: %v", i)
- assert.Equal(t, c.Expected, string(result), "Unexpected result in testcase %v", i)
+ actual := strings.ReplaceAll(string(result), ` data-markdown-generated-content=""`, "")
+ assert.Equal(t, c.Expected, actual, "Unexpected result in testcase %v", i)
}
}
diff --git a/modules/markup/sanitizer_default.go b/modules/markup/sanitizer_default.go
index 669dc24eae..476ae5e26f 100644
--- a/modules/markup/sanitizer_default.go
+++ b/modules/markup/sanitizer_default.go
@@ -107,6 +107,7 @@ func (st *Sanitizer) createDefaultPolicy() *bluemonday.Policy {
"start", "summary", "tabindex", "target",
"title", "type", "usemap", "valign", "value",
"vspace", "width", "itemprop",
+ "data-markdown-generated-content",
}
generalSafeElements := []string{