Skip to content

Commit

Permalink
support pasting of team mention links (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcosta7 authored Nov 9, 2023
1 parent 6657ec6 commit 3132aa2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/paste-markdown-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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'
}
9 changes: 9 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<meta charset='utf-8'><a href="https://github.com/orgs/github/teams/octocats" data-hovercard-type="team">@github/octocats</a>`
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
Expand Down

0 comments on commit 3132aa2

Please sign in to comment.