diff --git a/templates/repo/issue/view_content/context_menu.tmpl b/templates/repo/issue/view_content/context_menu.tmpl index 6f43f768b3..8cd4a056f0 100644 --- a/templates/repo/issue/view_content/context_menu.tmpl +++ b/templates/repo/issue/view_content/context_menu.tmpl @@ -11,7 +11,7 @@ {{end}}
{{ctx.Locale.Tr "repo.issues.context.copy_link"}}
{{if and .ctxData.IsSigned (not .ctxData.Repository.IsArchived)}} -
{{ctx.Locale.Tr "repo.issues.context.quote_reply"}}
+
{{ctx.Locale.Tr "repo.issues.context.quote_reply"}}
{{if not .ctxData.UnitIssuesGlobalDisabled}}
{{ctx.Locale.Tr "repo.issues.context.reference_issue"}}
{{end}} diff --git a/tests/e2e/fixtures/comment.yml b/tests/e2e/fixtures/comment.yml index f3f8a2d8e8..ae7c850036 100644 --- a/tests/e2e/fixtures/comment.yml +++ b/tests/e2e/fixtures/comment.yml @@ -3,7 +3,7 @@ type: 0 # comment poster_id: 2 issue_id: 1 # in repo_id 1 - content: "## Lorem Ipsum\nI would like to say that **I am not appealed** that it took _so long_ for this `feature` to be [created](https://example.com) $e^{\\pi i} + 1 = 0$\n$$e^{\\pi i} + 1 = 0$$\n#1\n```js\nconsole.log('evil')\nalert('evil')\n```\n:+1: :100:" + content: "## Lorem Ipsum\nI would like to say that **I am not appealed** that it took _so long_ for this `feature` to be [created](https://example.com) $e^{\\pi i} + 1 = 0$\n$$e^{\\pi i} + 1 = 0$$\n#1\n```js\nconsole.log('evil')\nalert('evil')\n```\n:+1: :100:\n![hi there](/attachments/3f4f4016-877b-46b3-b79f-ad24519a9cf2)\n\nsomething something" created_unix: 946684811 updated_unix: 946684811 content_version: 1 @@ -13,7 +13,7 @@ type: 21 # code comment poster_id: 2 issue_id: 19 - content: "## Lorem Ipsum\nI would like to say that **I am not appealed** that it took _so long_ for this `feature` to be [created](https://example.com) $e^{\\pi i} + 1 = 0$\n$$e^{\\pi i} + 1 = 0$$\n#1\n```js\nconsole.log('evil')\nalert('evil')\n```\n:+1: :100:" + content: "## Lorem Ipsum\nI would like to say that **I am not appealed** that it took _so long_ for this `feature` to be [created](https://example.com) $e^{\\pi i} + 1 = 0$\n$$e^{\\pi i} + 1 = 0$$\n#1\n```js\nconsole.log('evil')\nalert('evil')\n```\n:+1: :100:\n![hi there](/attachments/3f4f4016-877b-46b3-b79f-ad24519a9cf2)\n\nsomething something" review_id: 1001 line: 1 tree_path: "test1.txt" diff --git a/tests/e2e/issue-comment.test.e2e.ts b/tests/e2e/issue-comment.test.e2e.ts index d2dbafafd0..2017e4563e 100644 --- a/tests/e2e/issue-comment.test.e2e.ts +++ b/tests/e2e/issue-comment.test.e2e.ts @@ -123,7 +123,8 @@ test('Quote reply', async ({page}, workerInfo) => { "> alert('evil')\n" + '> ```\n' + '> \n' + - '> :+1: :100:\n\n'); + '> :+1: :100: [![hi there](/attachments/3f4f4016-877b-46b3-b79f-ad24519a9cf2)](/user2/repo1/attachments/3f4f4016-877b-46b3-b79f-ad24519a9cf2)\n' + + '> something something\n\n'); await editorTextarea.fill(''); @@ -197,7 +198,8 @@ test('Pull quote reply', async ({page}, workerInfo) => { "> alert('evil')\n" + '> ```\n' + '> \n' + - '> :+1: :100:\n\n'); + '> :+1: :100: [![hi there](/attachments/3f4f4016-877b-46b3-b79f-ad24519a9cf2)](/user2/commitsonpr/attachments/3f4f4016-877b-46b3-b79f-ad24519a9cf2)\n' + + '> something something\n\n'); await editorTextarea.fill(''); }); diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index e6af4cbf04..66ee945d02 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -531,6 +531,13 @@ const filters = { } return el; }, + IMG(el, context) { + const src = el.getAttribute('src'); + if (src?.startsWith(context)) { + el.src = src.slice(context.length); + } + return el; + }, }; function hasContent(node) { @@ -538,32 +545,34 @@ function hasContent(node) { } // This code matches that of what is done by @github/quote-selection -function preprocessFragment(fragment) { - const nodeIterator = document.createNodeIterator(fragment, NodeFilter.SHOW_ELEMENT, { - acceptNode(node) { - if (node.nodeName in filters && hasContent(node)) { - return NodeFilter.FILTER_ACCEPT; +function preprocessFragment(context) { + return function(fragment) { + const nodeIterator = document.createNodeIterator(fragment, NodeFilter.SHOW_ELEMENT, { + acceptNode(node) { + if (node.nodeName in filters && hasContent(node)) { + return NodeFilter.FILTER_ACCEPT; + } + + return NodeFilter.FILTER_SKIP; + }, + }); + const results = []; + let node = nodeIterator.nextNode(); + + while (node) { + if (node instanceof HTMLElement) { + results.push(node); } - - return NodeFilter.FILTER_SKIP; - }, - }); - const results = []; - let node = nodeIterator.nextNode(); - - while (node) { - if (node instanceof HTMLElement) { - results.push(node); + node = nodeIterator.nextNode(); } - node = nodeIterator.nextNode(); - } // process deepest matches first - results.reverse(); + results.reverse(); - for (const el of results) { - el.replaceWith(filters[el.nodeName](el)); - } + for (const el of results) { + el.replaceWith(filters[el.nodeName](el, context)); + } + }; } function initRepoIssueCommentEdit() { @@ -573,7 +582,7 @@ function initRepoIssueCommentEdit() { // Quote reply $(document).on('click', '.quote-reply', async (event) => { event.preventDefault(); - const quote = new MarkdownQuote('', preprocessFragment); + const quote = new MarkdownQuote('', preprocessFragment(event.target.getAttribute('data-context'))); let editorTextArea; if (event.target.classList.contains('quote-reply-diff')) {