summaryrefslogtreecommitdiff
path: root/source/features/embed-gist-inline.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'source/features/embed-gist-inline.tsx')
-rw-r--r--source/features/embed-gist-inline.tsx11
1 files changed, 4 insertions, 7 deletions
diff --git a/source/features/embed-gist-inline.tsx b/source/features/embed-gist-inline.tsx
index efb096f5..b7dc4dd5 100644
--- a/source/features/embed-gist-inline.tsx
+++ b/source/features/embed-gist-inline.tsx
@@ -6,7 +6,7 @@ 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);
}
@@ -14,15 +14,12 @@ function parseGistLink(link: HTMLAnchorElement): string | void {
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();