diff --git a/.vscode/settings.json b/.vscode/settings.json index 2ce2488..2c507c8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -19,16 +19,29 @@ "cSpell.words": [ "Backlink", "Backlinks", + "Berdn", "Devops", "Suping", + "ahazxm", + "andermerwed", "basenames", + "davovscapcom", + "digiguru", "filepath", "fullwidth", "jumplist", + "kolloch", + "lukakemperle", + "lukesmurray", "nevermind", "notetaking", "nvalt", + "pomdtr", "prefill", + "qbikez", + "quickfold", + "regexes", + "thomaskoppelaar", "unist", "vpackage", "vpublish", diff --git a/package.json b/package.json index 26bfbf6..243abe4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-markdown-notes", "displayName": "Markdown Notes", "description": "Navigate notes with [[wiki-links]], backlinks, and #tags (like Bear, Roam, etc). Automatically create notes from new inline [[wiki-links]]. Use Peek Definition to preview linked notes.", - "version": "0.0.13", + "version": "0.0.14", "publisher": "kortina", "repository": { "url": "https://github.com/kortina/vscode-markdown-notes.git", @@ -98,7 +98,7 @@ "vscodeMarkdownNotes.allowPipedWikiLinks": { "type": "boolean", "default": false, - "description": "States whether or not to use piped wikilinks. When set to false, this will ignore any '|' character and slugify it as normal." + "description": "States whether or not to use piped wiki-links. When set to false, this will ignore any '|' character and slugify it as normal." }, "vscodeMarkdownNotes.pipedWikiLinksSyntax": { "type": "string", @@ -107,20 +107,20 @@ "file|desc" ], "default": "file|desc", - "description": "Describes what piped wikilink syntax to use: either [[file|description]], or [[description|file]]." + "description": "Describes what piped wiki-link syntax to use: either [[file|description]], or [[description|file]]." }, "vscodeMarkdownNotes.pipedWikiLinksSeparator": { "type": "string", "default": "\\|", "pattern": "[^\\[\\]]+", - "patternErrorMessage": "Warning: This separator will unfortunately not work - It would break the wikilink syntax.", + "patternErrorMessage": "Warning: This separator will unfortunately not work - It would break the wiki-link syntax.", "markdownDescription": "States what separator should be used - **Note: Special regex characters should be escaped! Example: '|' should be '\\\\|'**" } }, "vscodeMarkdownNotes.triggerSuggestOnReplacement": { - "type": "boolean", - "default": true, - "description": "Trigger suggest on both insertion AND replacement of new character inside a wiki-link. Defaults true. Set false to only trigger suggest on insertion. See PR #69 for details." + "type": "boolean", + "default": true, + "description": "Trigger suggest on both insertion AND replacement of new character inside a wiki-link. Defaults true. Set false to only trigger suggest on insertion. See PR #69 for details." } }, "views": { diff --git a/src/NoteWorkspace.ts b/src/NoteWorkspace.ts index fc8febc..77b6957 100644 --- a/src/NoteWorkspace.ts +++ b/src/NoteWorkspace.ts @@ -23,9 +23,9 @@ enum SlugifyCharacter { none = 'NONE', } -enum PipedWikilinksSyntax { - filedesc = 'file|desc', - descfile = 'desc|file', +enum PipedWikiLinksSyntax { + fileDesc = 'file|desc', + descFile = 'desc|file', } type Config = { @@ -37,7 +37,7 @@ type Config = { newNoteTemplate: string; triggerSuggestOnReplacement: boolean; allowPipedWikiLinks: boolean; - pipedWikiLinksSyntax: PipedWikilinksSyntax; + pipedWikiLinksSyntax: PipedWikiLinksSyntax; pipedWikiLinksSeparator: string; }; @@ -50,7 +50,7 @@ export class NoteWorkspace { // This will allow us to potentially expose these as settings. static _rxTagNoAnchors = '\\#[\\w\\-\\_]+'; // used to match tags that appear within lines static _rxTagWithAnchors = '^\\#[\\w\\-\\_]+$'; // used to match entire words - static _rxWikiLink = "\\[\\[[^sep\\]]+(sep[^sep\\]]+)?\\]\\]"; // [[wiki-link-regex(|with potential pipe)?]] Note: "sep" will be replaced with pipedWikiLinksSeparator on compile + static _rxWikiLink = '\\[\\[[^sep\\]]+(sep[^sep\\]]+)?\\]\\]'; // [[wiki-link-regex(|with potential pipe)?]] Note: "sep" will be replaced with pipedWikiLinksSeparator on compile static _rxMarkdownWordPattern = '([\\_\\w\\#\\.\\/\\\\]+)'; // had to add [".", "/", "\"] to get relative path completion working and ["#"] to get tag completion working static _rxFileExtensions = '\\.(md|markdown|mdx|fountain)$'; static _defaultFileExtension = 'md'; @@ -68,8 +68,8 @@ export class NoteWorkspace { newNoteTemplate: NoteWorkspace._defaultNoteTemplate, triggerSuggestOnReplacement: NoteWorkspace._defaultTriggerSuggestOnReplacement, allowPipedWikiLinks: false, - pipedWikiLinksSyntax: PipedWikilinksSyntax.descfile, - pipedWikiLinksSeparator: "\\|", + pipedWikiLinksSyntax: PipedWikiLinksSyntax.descFile, + pipedWikiLinksSeparator: '\\|', }; static DOCUMENT_SELECTOR = [ // { scheme: 'file', language: 'markdown' }, @@ -93,7 +93,7 @@ export class NoteWorkspace { newNoteTemplate: c.get('newNoteTemplate') as string, triggerSuggestOnReplacement: c.get('triggerSuggestOnReplacement') as boolean, allowPipedWikiLinks: c.get('allowPipedWikiLinks') as boolean, - pipedWikiLinksSyntax: c.get('pipedWikiLinksSyntax') as PipedWikilinksSyntax, + pipedWikiLinksSyntax: c.get('pipedWikiLinksSyntax') as PipedWikiLinksSyntax, pipedWikiLinksSeparator: c.get('pipedWikiLinksSeparator') as string, }; } @@ -112,6 +112,7 @@ export class NoteWorkspace { static triggerSuggestOnReplacement() { return this.cfg().triggerSuggestOnReplacement; + } static allowPipedWikiLinks(): boolean { return this.cfg().allowPipedWikiLinks; @@ -138,7 +139,7 @@ export class NoteWorkspace { static rxWikiLink(): RegExp { // NB: MUST have g flag to match multiple words per line // return /\[\[[\w\.\-\_\/\\]+/i; // [[wiki-link-regex - this._rxWikiLink = this._rxWikiLink.replace(/sep/g,NoteWorkspace.pipedWikiLinksSeparator()); + this._rxWikiLink = this._rxWikiLink.replace(/sep/g, NoteWorkspace.pipedWikiLinksSeparator()); return new RegExp(this._rxWikiLink, 'gi'); } static rxMarkdownWordPattern(): RegExp { @@ -203,30 +204,25 @@ export class NoteWorkspace { } static cleanPipedWikiLink(noteName: string): string { - // Check whether or not we should remove the description if (NoteWorkspace.allowPipedWikiLinks()) { - let separator: string = NoteWorkspace.pipedWikiLinksSeparator(); - let capturegroup = "[^\\["+separator+"]+"; + let captureGroup = '[^\\[' + separator + ']+'; let regex: RegExp; if (NoteWorkspace.pipedWikiLinksSyntax() == 'file|desc') { - - // Should capture the "|desc" at the end of a wikilink - regex = new RegExp(separator + capturegroup +"$"); - + // Should capture the "|desc" at the end of a wiki-link + regex = new RegExp(separator + captureGroup + '$'); } else { - - // Should capture the "desc|" at the beginning of a wikilink - regex = new RegExp("^"+capturegroup+separator); + // Should capture the "desc|" at the beginning of a wiki-link + regex = new RegExp('^' + captureGroup + separator); } noteName = noteName.replace(regex, ''); // Remove description from the end return noteName; - // If piped wikilinks aren't used, don't alter the notename. + // If piped wiki-links aren't used, don't alter the note name. } else { return noteName; } diff --git a/src/Ref.ts b/src/Ref.ts index 545859e..131f018 100644 --- a/src/Ref.ts +++ b/src/Ref.ts @@ -81,8 +81,7 @@ export function getRefAt(document: vscode.TextDocument, position: vscode.Positio let r = new vscode.Range(s, e); ref = document.getText(r); if (ref) { - - // Check for piped wikilinks + // Check for piped wiki-links ref = NoteWorkspace.cleanPipedWikiLink(ref); return { diff --git a/src/test/jest/extension.test.ts b/src/test/jest/extension.test.ts index 819b36b..14ac2fe 100644 --- a/src/test/jest/extension.test.ts +++ b/src/test/jest/extension.test.ts @@ -99,37 +99,16 @@ test('noteNamesFuzzyMatchSlashes', () => { 'link-topic' ); // lower case is expected because 'slugifyTitle' includes toLowerCase - expect(NoteWorkspace.slugifyTitle('Link/Topic')).toEqual( - 'link-topic' - ); - expect(NoteWorkspace.normalizeNoteNameForFuzzyMatchText('Link/Topic')).toEqual( - 'link-topic' - ); - expect( - NoteWorkspace.noteNamesFuzzyMatch('dir/sub/link-topic.md', 'Link/Topic') - ).toBeTruthy(); - expect( - NoteWorkspace.noteNamesFuzzyMatch('dir/sub/Link-Topic.md', 'Link/Topic') - ).toBeTruthy(); - expect( - NoteWorkspace.noteNamesFuzzyMatch('dir/sub/link-topic.md', 'link/topic') - ).toBeTruthy(); - expect( - NoteWorkspace.noteNamesFuzzyMatch('dir/sub/Link-Topic.md', 'link/topic') - ).toBeTruthy(); - expect( - NoteWorkspace.noteNamesFuzzyMatch('dir/sub/link-topic.md', 'Link/topic') - ).toBeTruthy(); - expect( - NoteWorkspace.noteNamesFuzzyMatch('dir/sub/link-topic.md', 'link/Topic') - ).toBeTruthy(); - expect( - NoteWorkspace.noteNamesFuzzyMatch('dir/sub/Link-Topic.md', 'Link/topic') - ).toBeTruthy(); - expect( - NoteWorkspace.noteNamesFuzzyMatch('dir/sub/Link-Topic.md', 'link/Topic') - ).toBeTruthy(); - + expect(NoteWorkspace.slugifyTitle('Link/Topic')).toEqual('link-topic'); + expect(NoteWorkspace.normalizeNoteNameForFuzzyMatchText('Link/Topic')).toEqual('link-topic'); + expect(NoteWorkspace.noteNamesFuzzyMatch('dir/sub/link-topic.md', 'Link/Topic')).toBeTruthy(); + expect(NoteWorkspace.noteNamesFuzzyMatch('dir/sub/Link-Topic.md', 'Link/Topic')).toBeTruthy(); + expect(NoteWorkspace.noteNamesFuzzyMatch('dir/sub/link-topic.md', 'link/topic')).toBeTruthy(); + expect(NoteWorkspace.noteNamesFuzzyMatch('dir/sub/Link-Topic.md', 'link/topic')).toBeTruthy(); + expect(NoteWorkspace.noteNamesFuzzyMatch('dir/sub/link-topic.md', 'Link/topic')).toBeTruthy(); + expect(NoteWorkspace.noteNamesFuzzyMatch('dir/sub/link-topic.md', 'link/Topic')).toBeTruthy(); + expect(NoteWorkspace.noteNamesFuzzyMatch('dir/sub/Link-Topic.md', 'Link/topic')).toBeTruthy(); + expect(NoteWorkspace.noteNamesFuzzyMatch('dir/sub/Link-Topic.md', 'link/Topic')).toBeTruthy(); }); test('noteNamesFuzzyMatch', () => { @@ -199,8 +178,7 @@ test('Note.tagSet', () => { expect(tags).toEqual(new Set(['#another_tag', '#tag'])); }); - -describe("Wikilinks", () => { +describe('WikiLinks', () => { beforeEach(() => { NoteWorkspace.cfg = () => { let config = NoteWorkspace.DEFAULT_CONFIG; @@ -210,37 +188,29 @@ describe("Wikilinks", () => { }); test('cleanPipedWikiLinks', () => { - - expect(NoteWorkspace.cleanPipedWikiLink("description|file")).toEqual( - "file" - ); - expect(NoteWorkspace.cleanPipedWikiLink("description with lots of spaces, and other symbols|file.md")).toEqual( - "file.md" - ); - expect(NoteWorkspace.cleanPipedWikiLink("description|file")).toEqual( - "file" - ); - + expect(NoteWorkspace.cleanPipedWikiLink('description|file')).toEqual('file'); + expect( + NoteWorkspace.cleanPipedWikiLink('description with lots of spaces, and other symbols|file.md') + ).toEqual('file.md'); + expect(NoteWorkspace.cleanPipedWikiLink('description|file')).toEqual('file'); + // Odd case, but I suppose it should be treated - expect(NoteWorkspace.cleanPipedWikiLink("description|file|but-with-a-pipe-symbol.md")).toEqual( - "file|but-with-a-pipe-symbol.md" + expect(NoteWorkspace.cleanPipedWikiLink('description|file|but-with-a-pipe-symbol.md')).toEqual( + 'file|but-with-a-pipe-symbol.md' ); - }); - test("NoteWorkspace.noteNamesFuzzyMatch", () => { + test('NoteWorkspace.noteNamesFuzzyMatch', () => { expect( NoteWorkspace.noteNamesFuzzyMatch('filename.md', 'description|filename.md') ).toBeTruthy(); - + expect( NoteWorkspace.noteNamesFuzzyMatch('filename.md', 'description |filename.md') ).toBeTruthy(); - }); // Tests the different settings for piped wikilinks - test("Config changes", () => { - + test('Config changes', () => { // 1: Disable piped wikilinks NoteWorkspace.cfg = () => { let config = NoteWorkspace.DEFAULT_CONFIG; @@ -248,20 +218,16 @@ describe("Wikilinks", () => { return config; }; // Because of this change, these should not match anymore... - expect( - NoteWorkspace.noteNamesFuzzyMatch('filename.md', 'description|filename.md') - ).toBeFalsy(); + expect(NoteWorkspace.noteNamesFuzzyMatch('filename.md', 'description|filename.md')).toBeFalsy(); // ... And cleanPipedWikiLink should return the original string. - expect(NoteWorkspace.cleanPipedWikiLink("description|file")).toEqual( - "description|file" - ); + expect(NoteWorkspace.cleanPipedWikiLink('description|file')).toEqual('description|file'); // 2: Use a different separator NoteWorkspace.cfg = () => { let config = NoteWorkspace.DEFAULT_CONFIG; config.allowPipedWikiLinks = true; - config.pipedWikiLinksSeparator = "@"; + config.pipedWikiLinksSeparator = '@'; return config; }; @@ -269,15 +235,13 @@ describe("Wikilinks", () => { NoteWorkspace.noteNamesFuzzyMatch('filename.md', 'description@filename.md') ).toBeTruthy(); - expect(NoteWorkspace.cleanPipedWikiLink("description@file")).toEqual( - "file" - ); + expect(NoteWorkspace.cleanPipedWikiLink('description@file')).toEqual('file'); // 3: Use a different syntax NoteWorkspace.cfg = () => { let config = NoteWorkspace.DEFAULT_CONFIG; config.allowPipedWikiLinks = true; - config.pipedWikiLinksSeparator = "\\|"; + config.pipedWikiLinksSeparator = '\\|'; return config; }; @@ -289,12 +253,8 @@ describe("Wikilinks", () => { NoteWorkspace.noteNamesFuzzyMatch('filename.md', 'filename.md|description') ).toBeTruthy(); - expect(NoteWorkspace.cleanPipedWikiLink("file|description")).toEqual( - "file" - ); - + expect(NoteWorkspace.cleanPipedWikiLink('file|description')).toEqual('file'); }); - }); describe('NoteWorkspace.newNoteContent', () => { @@ -302,34 +262,34 @@ describe('NoteWorkspace.newNoteContent', () => { NoteWorkspace.cfg = () => { return { ...NoteWorkspace.DEFAULT_CONFIG, - newNoteTemplate: template + newNoteTemplate: template, }; }; - + return NoteWorkspace.newNoteContent(title); }; it('handles noteName tag', () => { - const template = "# ${noteName}\n\nThis is ${noteName}"; - - const content = newNote(template, "this is my test note!"); + const template = '# ${noteName}\n\nThis is ${noteName}'; + + const content = newNote(template, 'this is my test note!'); expect(content).toBe('# this is my test note!\n\nThis is this is my test note!'); }); it('handles escaped newlines', () => { - const template = "# Title\\n\\nContent"; - + const template = '# Title\\n\\nContent'; + const content = newNote(template, 'nevermind'); expect(content).toBe('# Title\n\nContent'); }); it('handles timestamp', () => { - const template = "# Title\n\nCreated: ${timestamp}\n"; - + const template = '# Title\n\nCreated: ${timestamp}\n'; + const content = newNote(template, 'nevermind'); const regex = /# Title\n\nCreated: (.*)\n/; - + expect(content).toMatch(regex); const matches = regex.exec(content); const date1 = Date.parse(matches![1]); diff --git a/test/sub/demo.md b/test/sub/demo.md index eb7ecb1..1caf811 100644 --- a/test/sub/demo.md +++ b/test/sub/demo.md @@ -27,7 +27,7 @@ View and navigate backlinks with an Explorer Panel. --- -`⌥F12` (`cmd+k cmd+n`) / Peek References / `editor.action.peekDefinition` +`⌥F12` (`cmd+k cmd+n`) / Peek References / `editor.action.referenceSearch.trigger` - for Wiki Link [[sub.md]] [[test]] - for Tag #tag @@ -41,7 +41,7 @@ View and navigate backlinks with an Explorer Panel. --- -`⇧⌥F12` (`ctr+⌥+r`) / Find All References / `references-view.find` +`⇧⌥F12` (`cmd+k cmd+f`) / Find All References / `references-view.find` - for Wiki Link [[sub.md]] [[test]] - for Tag #tag