Skip to content

Commit 3132aa2

Browse files
authored
support pasting of team mention links (#91)
1 parent 6657ec6 commit 3132aa2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Diff for: src/paste-markdown-html.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function linkify(element: HTMLAnchorElement, label: string): string {
123123
let markdown = ''
124124

125125
// Don't linkify user mentions like "@octocat"
126-
if (isUserMention(element)) {
126+
if (isUserMention(element) || isTeamMention(element)) {
127127
markdown = label
128128
// Don't linkify things like "#123" or commit comparisons
129129
} else if (isSpecialLink(element) || areEqualLinks(url, label)) {
@@ -156,3 +156,8 @@ function areEqualLinks(link1: string, link2: string) {
156156
function isUserMention(link: HTMLAnchorElement): boolean {
157157
return link.textContent?.slice(0, 1) === '@' && link.getAttribute('data-hovercard-type') === 'user'
158158
}
159+
160+
// Team mentions have a "@" and a hovercard attribute of type "team"
161+
function isTeamMention(link: HTMLAnchorElement): boolean {
162+
return link.textContent?.slice(0, 1) === '@' && link.getAttribute('data-hovercard-type') === 'team'
163+
}

Diff for: test/test.js

+9
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,15 @@ describe('paste-markdown', function () {
320320
assert.equal(textarea.value, '')
321321
})
322322

323+
it("doesn't render any markdown for GitHub team handles", function () {
324+
// eslint-disable-next-line github/unescaped-html-literal
325+
const link = `<meta charset='utf-8'><a href="https://github.com/orgs/github/teams/octocats" data-hovercard-type="team">@github/octocats</a>`
326+
const plaintextLink = '@github/octocats'
327+
328+
paste(textarea, {'text/html': link, 'text/plain': plaintextLink})
329+
assert.equal(textarea.value, '')
330+
})
331+
323332
it('retains urls of special GitHub links', function () {
324333
const href = 'https://github.com/octocat/repo/issues/1'
325334
// eslint-disable-next-line github/unescaped-html-literal

0 commit comments

Comments
 (0)