diff --git a/help/Features/Accepted File Formats.md b/help/Features/Accepted File Formats.md index 1951cc24..eb3410ce 100644 --- a/help/Features/Accepted File Formats.md +++ b/help/Features/Accepted File Formats.md @@ -4,7 +4,7 @@ Memo recognizes the following file formats: 1. Markdown files: `md`; 2. Image files: `png`, `jpg`, `jpeg`, `svg`, `gif`, `webp`; -3. Other formats: `doc`, `docx`, `rtf`, `txt`, `odt`, `xls`, `xlsx`, `ppt`, `pptm`, `pptx`, `pdf`. See full list of extensions [here](https://github.com/svsool/memo/blob/51d65f594978d30ee049feda710c3ce52ab64bad/src/utils/utils.ts#L12-L44). +3. Other formats: `doc`, `docx`, `rtf`, `txt`, `odt`, `xls`, `xlsx`, `ppt`, `pptm`, `pptx`, `pdf`. See full list of extensions [here](https://github.com/svsool/memo/blob/51d65f594978d30ee049feda710c3ce52ab64bad/src/utils/utils.ts#L12-L44). These default extensions can be changed using the `memo.links.customExtensions` configuration variable. This configuration variable is an array. Use the special case of `["*"]` to allow all extensions. Markdown files and image files can be referenced via regular links `[[image.png]]` or attached using embed links `![[image.png]]`. These file types also support on-hover and built-in previews ([[Notes and images preview.gif|see how it works]]). diff --git a/package.json b/package.json index 4b547055..aa58fe80 100644 --- a/package.json +++ b/package.json @@ -115,6 +115,39 @@ "description": "Whether to enable links completion in the editor. Reload required!", "type": "boolean" }, + "memo.links.customExtensions": { + "scope": "resource", + "description": "Other file extensions supported by links. Use a single entry of '*' to include all extensions.", + "default": [ + "doc", + "docx", + "rtf", + "txt", + "odt", + "xls", + "xlsx", + "ppt", + "pptm", + "pptx", + "pdf", + "pages", + "mp4", + "mov", + "wmv", + "flv", + "avi", + "mkv", + "mp3", + "webm", + "wav", + "m4a", + "ogg", + "3gp", + "flac", + "msg" + ], + "type": "array" + }, "memo.links.following.enabled": { "default": true, "scope": "resource", @@ -169,8 +202,7 @@ "scope": "resource", "description": "Whether to enhance built-in VSCode Markdown preview with links highlight, navigation and resource embedding. Reload required!", "type": "boolean" - } - } + } } }, "keybindings": [ { diff --git a/src/utils/utils.spec.ts b/src/utils/utils.spec.ts index 9e2f638d..8fbcae00 100644 --- a/src/utils/utils.spec.ts +++ b/src/utils/utils.spec.ts @@ -1181,6 +1181,23 @@ describe('findNonIgnoredFiles()', () => { }); }); + describe('when config includes py files', () => { + it('should find non-ignored files', async () => { + const prevConfig = getConfigProperty('memo.links.customExtensions', []); + await updateConfigProperty('memo.links.customExtensions', ['py']); + const allowedName = rndName(); + + await createFile(`${allowedName}.py`); + + const files = await findNonIgnoredFiles('**/*.py'); + + expect(files).toHaveLength(1); + expect(path.basename(files[0].fsPath)).toBe(`${allowedName}.py`); + + await updateConfigProperty('memo.links.customExtensions', prevConfig); + }); + }); + describe('when exclude param passed explicitly and search.exclude set', () => { it('should find non-ignored files', async () => { const prevConfig = getConfigProperty('search.exclude', {}); diff --git a/src/utils/utils.ts b/src/utils/utils.ts index fbe27a5e..ca4398eb 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -12,7 +12,38 @@ export const imageExts = ['png', 'jpg', 'jpeg', 'svg', 'gif', 'webp']; const imageExtsRegex = new RegExp(`.(${imageExts.join('|')})$`, 'i'); -export const otherExts = [ +export function getMemoConfigProperty( + property: 'links.format', + fallback: 'short', +): 'short' | 'long'; + +export function getMemoConfigProperty( + property: 'backlinksPanel.collapseParentItems', + fallback: null | boolean, +): boolean; + +export function getMemoConfigProperty( + property: 'links.preview.imageMaxHeight', + fallback: null | number, +): number; + +export function getMemoConfigProperty( + property: 'links.rules', + fallback: null | Array, +): LinkRuleT[]; + +export function getMemoConfigProperty(property: MemoBoolConfigProp, fallback: boolean): boolean; + +export function getMemoConfigProperty( + property: 'links.customExtensions', + fallback: null | Array, +): String[]; + +export function getMemoConfigProperty(property: string, fallback: T): T { + return getConfigProperty(`memo.${property}`, fallback); +} + +export const otherExts = getMemoConfigProperty('links.customExtensions', [ 'doc', 'docx', 'rtf', @@ -39,9 +70,12 @@ export const otherExts = [ '3gp', 'flac', 'msg', -]; +]); -const otherExtsRegex = new RegExp(`.(${otherExts.join('|')})$`, 'i'); +export const otherExtsRegex = + otherExts.length == 1 && otherExts[0] == '*' + ? new RegExp(`.*`, 'i') + : new RegExp(`.(${otherExts.join('|')})$`, 'i'); // Remember to edit accordingly when extensions above edited export const commonExtsHint = @@ -160,32 +194,6 @@ export type MemoBoolConfigProp = | 'backlinksPanel.enabled' | 'markdownPreview.enabled'; -export function getMemoConfigProperty( - property: 'links.format', - fallback: 'short', -): 'short' | 'long'; - -export function getMemoConfigProperty( - property: 'backlinksPanel.collapseParentItems', - fallback: null | boolean, -): boolean; - -export function getMemoConfigProperty( - property: 'links.preview.imageMaxHeight', - fallback: null | number, -): number; - -export function getMemoConfigProperty( - property: 'links.rules', - fallback: null | Array, -): LinkRuleT[]; - -export function getMemoConfigProperty(property: MemoBoolConfigProp, fallback: boolean): boolean; - -export function getMemoConfigProperty(property: string, fallback: T): T { - return getConfigProperty(`memo.${property}`, fallback); -} - export const matchAll = (pattern: RegExp, text: string): Array => { let match: RegExpMatchArray | null; const out: RegExpMatchArray[] = []; diff --git a/src/workspace/cache/cache.ts b/src/workspace/cache/cache.ts index 73a562d8..4b7289f7 100644 --- a/src/workspace/cache/cache.ts +++ b/src/workspace/cache/cache.ts @@ -92,7 +92,10 @@ export const cacheUris = async () => { const { findNonIgnoredFiles, imageExts, otherExts } = utils(); const markdownUris = await findNonIgnoredFiles('**/*.md'); const imageUris = await findNonIgnoredFiles(`**/*.{${imageExts.join(',')}}`); - const otherUris = await findNonIgnoredFiles(`**/*.{${otherExts.join(',')}}`); + const otherUris = + otherExts.length == 1 && otherExts[0] == '*' + ? await findNonIgnoredFiles('**/*') + : await findNonIgnoredFiles(`**/*.{${otherExts.join(',')}}`); workspaceCache.markdownUris = sortPaths(markdownUris, { pathKey: 'path', shallowFirst: true }); workspaceCache.imageUris = sortPaths(imageUris, { pathKey: 'path', shallowFirst: true });