mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-25 19:40:56 +00:00
fix: paste copied code as text, not as a markdown table (#40053)
Copying lines from a diff, file view, blame, code search or code preview and pasting them into a comment on Gitea or GitHub produced a markdown table with escaped pipes and stripped indentation. Both use `@github/paste-markdown`, which converts copied HTML tables unless they carry `data-paste-markdown-skip`, as GitHub's own code tables do. Gitea's code tables now set it too. The test is a bit more complicated because of a upstream bug which causes `paste-markdown` to insert pasted content twice, once https://github.com/github/paste-markdown/pull/128 is merged and released, the negative assertion could be removed. --------- Signed-off-by: silverwind <me@silverwind.io>
This commit is contained in:
1 parent
edebfaa125
commit
cd92c6a008
12 files changed
+39
-11
No files matched your search
@@ -31,8 +31,9 @@ func (st *Sanitizer) createDefaultPolicy() *bluemonday.Policy {
|
||||
// Chroma always uses 1-2 letters for style names, we could tolerate it at the moment
|
||||
policy.AllowAttrs("class").Matching(regexp.MustCompile(`^\w{0,2}$`)).OnElements("span")
|
||||
|
||||
// Line numbers on codepreview
|
||||
// Line numbers and paste behavior on codepreview
|
||||
policy.AllowAttrs("data-line-number").OnElements("span")
|
||||
policy.AllowAttrs("data-paste-markdown-skip").OnElements("table")
|
||||
|
||||
// emoji aliases for dark theme inversion
|
||||
policy.AllowAttrs("data-alias").OnElements("span")
|
||||
|
||||
@@ -49,6 +49,8 @@ func TestSanitizer(t *testing.T) {
|
||||
`<p style="bad-color: red">Hello World</p>`, `<p>Hello World</p>`,
|
||||
`<code style="bad-color: red">Hello World</code>`, `<code>Hello World</code>`,
|
||||
|
||||
`<table data-paste-markdown-skip><tr><td>1</td></tr></table>`, `<table data-paste-markdown-skip=""><tr><td>1</td></tr></table>`,
|
||||
|
||||
// Org mode status of list items.
|
||||
`<li class="checked"></li>`, `<li class="checked"></li>`,
|
||||
`<li class="unchecked"></li>`, `<li class="unchecked"></li>`,
|
||||
|
||||
Reference in new issue
Block a user