summaryrefslogtreecommitdiff
path: root/source/features/embed-gist-inline.tsx
diff options
context:
space:
mode:
authorGravatar Federico Brigante <me@fregante.com> 2021-05-31 12:12:52 +0700
committerGravatar GitHub <noreply@github.com> 2021-05-31 12:12:52 +0700
commit7499bc3c0108adcb2d53aa76821323a9c96572e7 (patch)
treeb97c45a592a94869951e0884575e8ea0a1a663a2 /source/features/embed-gist-inline.tsx
parent9f9fe46e2d07377ca2194c3ef9ed3a7f0c374e2d (diff)
downloadrefined-github-7499bc3c0108adcb2d53aa76821323a9c96572e7.tar.gz
refined-github-7499bc3c0108adcb2d53aa76821323a9c96572e7.tar.zst
refined-github-7499bc3c0108adcb2d53aa76821323a9c96572e7.zip
`embed-gist-inline` fix: Exclude gist user links on Enterprise (#4433)
Diffstat (limited to 'source/features/embed-gist-inline.tsx')
-rw-r--r--source/features/embed-gist-inline.tsx23
1 files changed, 18 insertions, 5 deletions
diff --git a/source/features/embed-gist-inline.tsx b/source/features/embed-gist-inline.tsx
index 5221fa9e..efb096f5 100644
--- a/source/features/embed-gist-inline.tsx
+++ b/source/features/embed-gist-inline.tsx
@@ -4,13 +4,26 @@ import select from 'select-dom';
import * as pageDetect from 'github-url-detection';
import features from '.';
+import {getCleanPathname} from '../github-helpers';
-const isGist = (link: HTMLAnchorElement): boolean =>
- !link.pathname.includes('.') && // Exclude links to embed files
- (
- (link.hostname.startsWith('gist.') && link.pathname.includes('/', 1)) || // Exclude user links
- link.pathname.startsWith('gist/')
+function parseGistLink(link: HTMLAnchorElement): string | void {
+ if (link.host === 'gist.github.com') {
+ return getCleanPathname(link);
+ }
+
+ if (link.host === location.host && link.pathname.startsWith('gist/')) {
+ return link.pathname.replace('/gist', '').replace(/\/$/, '');
+ }
+}
+
+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
);
+}
const isOnlyChild = (link: HTMLAnchorElement): boolean => link.textContent!.trim() === link.parentNode!.textContent!.trim();