Skip to content

Commit

Permalink
Don't shorten URLs in markdown code blocks (refined-github#939)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante authored and jgierer12 committed Jan 2, 2018
1 parent 1db302d commit 0495336
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
12 changes: 3 additions & 9 deletions source/content.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'webext-dynamic-content-scripts';
import onAjaxedPages from 'github-injection';
import {applyToLink as shortenLink} from 'shorten-repo-url';
import select from 'select-dom';
import domLoaded from 'dom-loaded';

Expand Down Expand Up @@ -55,6 +54,7 @@ import embedGistInline from './features/embed-gist-inline';
import expandCollapseOutdatedComments from './features/expand-collapse-outdated-comments';
import addJumpToBottomLink from './features/add-jump-to-bottom-link';
import addQuickReviewButtons from './features/add-quick-review-buttons';
import shortenLinks from './features/shorten-links';

import * as pageDetect from './libs/page-detect';
import {observeEl, safeElementReady, enableFeature} from './libs/utils';
Expand Down Expand Up @@ -135,14 +135,8 @@ function ajaxedPagesHandler() {
enableFeature(hideEmptyMeta);
enableFeature(removeUploadFilesButton);
enableFeature(addTitleToEmojis);

enableFeature(() => {
for (const a of select.all('a[href]')) {
shortenLink(a, location.href);
}
}, 'shorten-links');

enableFeature(linkifyCode); // Must be after link shortening #789
enableFeature(shortenLinks);
enableFeature(linkifyCode);

if (pageDetect.isIssueSearch() || pageDetect.isPRSearch()) {
enableFeature(addYoursMenuItem);
Expand Down
6 changes: 3 additions & 3 deletions source/features/linkify-urls-in-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import linkifyIssues from 'linkify-issues';
import {getOwnerAndRepo} from '../libs/page-detect';
import getTextNodes from '../libs/get-text-nodes';

const linkifiedURLClass = 'refined-github-linkified-code';
export const linkifiedURLClass = 'rgh-linkified-code';
const {
ownerName,
repoName
Expand All @@ -15,8 +15,8 @@ const options = {
repo: repoName,
type: 'dom',
baseUrl: '',
attrs: {
target: '_blank'
attributes: {
class: linkifiedURLClass // Necessary to avoid also shortening the links
}
};

Expand Down
9 changes: 9 additions & 0 deletions source/features/shorten-links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import select from 'select-dom';
import {applyToLink} from 'shorten-repo-url';
import {linkifiedURLClass} from './linkify-urls-in-code';

export default function () {
for (const a of select.all(`a[href]:not(.${linkifiedURLClass})`)) {
applyToLink(a, location.href);
}
}

0 comments on commit 0495336

Please sign in to comment.