mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-25 22:23:42 +09:00
fix(feed): use meaningful lines as comment excerpt (#39276)
Comment excerpts in activity feeds previously used either the first 200 display characters of a comment or, for review comments, its first physical line. That excerpt is rendered as Markdown in the feed, so if the excerpt began with a leading blank lines or structural markdown syntax, the excerpt would render as empty or produce broken output. For example, a review comment beginning with a code fence stored only the opening fence, which rendered as an empty code block. This commit instead renders feed excerpts as prose only, dropping code, math, tables, images and HTML, which also fixes already stored excerpts. New excerpts start at the first prose line, and review comments get the same excerpt as issue comments. This produces meaningful excerpts in more cases while preserving their original Markdown. --- For a comment that contains the following: ```` ``` some code ``` hello ```` This previously rendered as: <img width="816" height="118" alt="Screenshot 2026-09-08 at 5 06 47 PM" src="https://github.com/user-attachments/assets/9d125363-72de-46bf-b47a-961245a79c5f" /> And now renders as: <img width="807" height="89" alt="Screenshot 2026-09-08 at 5 08 30 PM" src="https://github.com/user-attachments/assets/d2dcdc6d-d7a9-437f-8e9c-b845fe99fa5e" /> --------- Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: bircni <bircni@icloud.com>
This commit is contained in:
co-authored by
silverwind
bircni
parent
03058691c3
commit
722e52334a
@@ -242,6 +242,25 @@ com 88fc37a3c0a4dda553bdcfc80c178a58247f42fb mit
|
||||
space</p>
|
||||
`
|
||||
assert.Equal(t, expected, string(newTestRenderUtils(t).MarkdownToHtml(testInput())))
|
||||
|
||||
defer test.MockVariableValue(&setting.Markdown.MathCodeBlockOptions, setting.MarkdownMathCodeBlockOptions{ParseBlockDollar: true})()
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{name: "code", input: "```suggestion\nreplacement\n```\n\nexplanation", expected: "<p>explanation</p>\n"},
|
||||
{name: "unclosed code", input: "```suggestion"},
|
||||
{name: "table", input: "| a | b |\n|---|---|\n| 1 | 2 |"},
|
||||
{name: "math", input: "$$\nx\n$$\nafter", expected: "<p>after</p>\n"},
|
||||
{name: "image", input: "\n\ncaption", expected: "<p>caption</p>\n"},
|
||||
{name: "linked image", input: "[](https://example.com)"},
|
||||
{name: "html", input: "<details>\n<summary>x</summary>\n\nbody\n</details>", expected: "<p>body</p>\n"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
assert.Equal(t, tc.expected, string(newTestRenderUtils(t).FeedExcerptToHtml(tc.input)))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderPackageMarkdown(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user