Skip to content

Commit d8cef8b

Browse files
Copilotfregante
andcommitted
Add isRenderedTextFile and hasRenderedText functions
Implements detection for rendered text files including markdown, textile, rdoc, org, creole, mediawiki, wiki, rst, asciidoc, and pod files. The hasRenderedText function combines isRepoRoot with isRenderedTextFile to identify pages that display rendered text content. Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
1 parent 53f5c19 commit d8cef8b

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
@@ -594,7 +594,30 @@ TEST: addTests('isSingleFile', [
594594
'https://github.com/sindresorhus/refined-github/blob/master/.gitattributes',
595595
'https://github.com/sindresorhus/refined-github/blob/fix-narrow-diff/distribution/content.css',
596596
'https://github.com/sindresorhus/refined-github/blob/master/edit.txt',
597-
]);
597+
'isRenderedTextFile',
598+
]);
599+
600+
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);
601+
TEST: addTests('isRenderedTextFile', [
602+
'https://github.com/sindresorhus/refined-github/blob/master/readme.md',
603+
'https://github.com/sindresorhus/refined-github/blob/master/README.markdown',
604+
'https://github.com/sindresorhus/refined-github/blob/main/docs/guide.mdown',
605+
'https://github.com/sindresorhus/refined-github/blob/main/CONTRIBUTING.mkdn',
606+
'https://github.com/sindresorhus/refined-github/blob/master/file.textile',
607+
'https://github.com/sindresorhus/refined-github/blob/master/file.rdoc',
608+
'https://github.com/sindresorhus/refined-github/blob/master/file.org',
609+
'https://github.com/sindresorhus/refined-github/blob/master/file.creole',
610+
'https://github.com/sindresorhus/refined-github/blob/master/file.mediawiki',
611+
'https://github.com/sindresorhus/refined-github/blob/master/file.wiki',
612+
'https://github.com/sindresorhus/refined-github/blob/master/file.rst',
613+
'https://github.com/sindresorhus/refined-github/blob/master/file.asciidoc',
614+
'https://github.com/sindresorhus/refined-github/blob/master/file.adoc',
615+
'https://github.com/sindresorhus/refined-github/blob/master/file.asc',
616+
'https://github.com/sindresorhus/refined-github/blob/master/file.pod',
617+
]);
618+
619+
export const hasRenderedText = (url: URL | HTMLAnchorElement | Location = location): boolean => isRepoRoot(url) || isRenderedTextFile(url);
620+
TEST: addTests('hasRenderedText', combinedTestOnly);
598621

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

0 commit comments

Comments
 (0)