Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

team mention pasting #91

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while here, are there other types that shouldn't become urls?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattcosta7 Not that I know of.

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
Loading