Skip to content

Commit 56e0f9a

Browse files
authored
Add isRenderedTextFile and hasRenderedText (#220)
1 parent 1dabb36 commit 56e0f9a

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

index.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,30 @@ TEST: addTests('isSingleFile', [
596596
'https://github.com/sindresorhus/refined-github/blob/master/.gitattributes',
597597
'https://github.com/sindresorhus/refined-github/blob/fix-narrow-diff/distribution/content.css',
598598
'https://github.com/sindresorhus/refined-github/blob/master/edit.txt',
599-
]);
599+
'isRenderedTextFile',
600+
]);
601+
602+
export const isRenderedTextFile = (url: URL | HTMLAnchorElement | Location = location): boolean => isSingleFile(url) && /\.(md|markdown|mdown|mkdn|textile|rdoc|org|creole|mediawiki|wiki|rst|asciidoc|adoc|asc|pod)$/i.test(url.pathname);
603+
TEST: addTests('isRenderedTextFile', [
604+
'https://github.com/sindresorhus/refined-github/blob/master/readme.md',
605+
'https://github.com/sindresorhus/refined-github/blob/master/README.markdown',
606+
'https://github.com/sindresorhus/refined-github/blob/main/docs/guide.mdown',
607+
'https://github.com/sindresorhus/refined-github/blob/main/CONTRIBUTING.mkdn',
608+
'https://github.com/sindresorhus/refined-github/blob/master/file.textile',
609+
'https://github.com/sindresorhus/refined-github/blob/master/file.rdoc',
610+
'https://github.com/sindresorhus/refined-github/blob/master/file.org',
611+
'https://github.com/sindresorhus/refined-github/blob/master/file.creole',
612+
'https://github.com/sindresorhus/refined-github/blob/master/file.mediawiki',
613+
'https://github.com/sindresorhus/refined-github/blob/master/file.wiki',
614+
'https://github.com/sindresorhus/refined-github/blob/master/file.rst',
615+
'https://github.com/sindresorhus/refined-github/blob/master/file.asciidoc',
616+
'https://github.com/sindresorhus/refined-github/blob/master/file.adoc',
617+
'https://github.com/sindresorhus/refined-github/blob/master/file.asc',
618+
'https://github.com/sindresorhus/refined-github/blob/master/file.pod',
619+
]);
620+
621+
export const hasRenderedText = (url: URL | HTMLAnchorElement | Location = location): boolean => isRepoRoot(url) || isRenderedTextFile(url);
622+
TEST: addTests('hasRenderedText', combinedTestOnly);
600623

601624
export const isFileFinder = (url: URL | HTMLAnchorElement | Location = location): boolean => Boolean(getRepo(url)?.path.startsWith('find/'));
602625
TEST: addTests('isFileFinder', [

0 commit comments

Comments
 (0)