Skip to content

Commit

Permalink
embed-gist-inline improve gist detection
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Jun 4, 2021
1 parent 0af6c3f commit 1a9c4f9
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions source/features/embed-gist-inline.tsx
Expand Up @@ -6,23 +6,20 @@ import * as pageDetect from 'github-url-detection';
import features from '.';
import {getCleanPathname} from '../github-helpers';

function parseGistLink(link: HTMLAnchorElement): string | void {
function parseGistLink(link: HTMLAnchorElement): string | undefined {
if (link.host === 'gist.github.com') {
return getCleanPathname(link);
}

if (link.host === location.host && link.pathname.startsWith('gist/')) {
return link.pathname.replace('/gist', '').replace(/\/$/, '');
}

return undefined;
}

function isGist(link: HTMLAnchorElement): boolean {
const gistUrl = parseGistLink(link);
return Boolean(
gistUrl &&
!gistUrl.includes('.') && // Exclude links to embed files
gistUrl.includes('/', 1) // Exclude user links
);
return parseGistLink(link)?.replace(/[^/]/g, '').length === 1; // Exclude user links and file links
}

const isOnlyChild = (link: HTMLAnchorElement): boolean => link.textContent!.trim() === link.parentNode!.textContent!.trim();
Expand Down

0 comments on commit 1a9c4f9

Please sign in to comment.