diff --git a/src/paste-markdown-html.ts b/src/paste-markdown-html.ts index ed9cb1d..5217c57 100644 --- a/src/paste-markdown-html.ts +++ b/src/paste-markdown-html.ts @@ -123,7 +123,7 @@ function linkify(element: HTMLAnchorElement, label: string): string { let markdown = '' // Don't linkify user mentions like "@octocat" - if (isUserMention(element)) { + if (isUserMention(element) || isTeamMention(element)) { markdown = label // Don't linkify things like "#123" or commit comparisons } else if (isSpecialLink(element) || areEqualLinks(url, label)) { @@ -156,3 +156,8 @@ function areEqualLinks(link1: string, link2: string) { function isUserMention(link: HTMLAnchorElement): boolean { return link.textContent?.slice(0, 1) === '@' && link.getAttribute('data-hovercard-type') === 'user' } + +// Team mentions have a "@" and a hovercard attribute of type "team" +function isTeamMention(link: HTMLAnchorElement): boolean { + return link.textContent?.slice(0, 1) === '@' && link.getAttribute('data-hovercard-type') === 'team' +} diff --git a/test/test.js b/test/test.js index 951d261..b4a2c39 100644 --- a/test/test.js +++ b/test/test.js @@ -320,6 +320,15 @@ describe('paste-markdown', function () { assert.equal(textarea.value, '') }) + it("doesn't render any markdown for GitHub team handles", function () { + // eslint-disable-next-line github/unescaped-html-literal + const link = `@github/octocats` + const plaintextLink = '@github/octocats' + + paste(textarea, {'text/html': link, 'text/plain': plaintextLink}) + assert.equal(textarea.value, '') + }) + it('retains urls of special GitHub links', function () { const href = 'https://github.com/octocat/repo/issues/1' // eslint-disable-next-line github/unescaped-html-literal