Skip to content
Closed
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
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ Thanks for contributing! 🦋🙌
- [](# "same-page-definition-jump") [Avoids re-loading the page when jumping to function definition in the current file.](https://user-images.githubusercontent.com/16872793/90833649-7a5e2f80-e316-11ea-827d-a4e3ac8ced69.png)
- [](# "linkify-full-profile-readme-title") [Linkifies the readme text on profile pages.](https://user-images.githubusercontent.com/16872793/90910173-ebe4bf00-e3a4-11ea-8fc5-aea3d1a2e5e5.png)
- [](# "convert-pr-to-draft-improvements") [Moves the "Convert PR to Draft" button to the mergeability box and adds visual feedback to its confirm button.](https://user-images.githubusercontent.com/1402241/95644892-885f3f80-0a7f-11eb-8428-8e0fb0c8dfa5.gif)
- [](# "unlink-image-auto-links") [Removes unnecessary image auto links if they point to themselves.](https://user-images.githubusercontent.com/44045911/112277464-bb5b5f80-8cbc-11eb-9dc0-0268fc3a2b8a.png)
- [](# "clean-header-search-field") [Clears duplicate queries in the header search field.](https://user-images.githubusercontent.com/1402241/114177338-7c890300-9966-11eb-83a3-a711a76fae99.png)

<!-- Refer to style guide above. Keep this message between sections. -->
Expand Down
46 changes: 46 additions & 0 deletions source/features/unlink-image-auto-links.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import select from 'select-dom';
import * as pageDetect from 'github-url-detection';

import features from '.';
import GitHubURL from '../github-helpers/github-url';
import {isMarkdownFile} from '../github-helpers';

function isMarkupFile(): boolean {
if (isMarkdownFile()) {
return true;
}

// https://github.com/github/markup/blob/46908504f5099b15a88030749f0aeb52cd2f6799/README.md#markups
if (/\.(textile|rdoc|org|creole|(media)?wiki|rst|a(scii)?doc|asc|pod)$/.test(location.pathname)) {

@fregante fregante Apr 15, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's inline all the related extensions here, without using external "markdown" checks. Also it should just return /blah blah/.test(), no need for if/true/false

return true;
}

return false;
}

function getRawUrl(link: HTMLAnchorElement): string {
if (pageDetect.isSingleFile(link)) {
const rawLink = new GitHubURL(link.href).assign({route: 'raw'});
return rawLink.href;
}

return link.href;
}

function init(): void {
for (const image of select.all('.markdown-body a > img')) {
const link = image.parentElement as HTMLAnchorElement;

if (image.src === getRawUrl(link)) {
link.replaceWith(image);
}
}
}

void features.add(__filebasename, {
include: [
pageDetect.isRepoTree,
() => pageDetect.isSingleFile() && isMarkupFile()
],
init
});
1 change: 1 addition & 0 deletions source/refined-github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ import './features/select-all-notifications-shortcut';
import './features/no-duplicate-list-update-time';
import './features/view-last-pr-deployment';
import './features/global-search-filters';
import './features/unlink-image-auto-links';
import './features/clean-header-search-field';

// Add global for easier debugging
Expand Down