mirror of
https://github.com/logancyang/obsidian-copilot.git
synced 2026-07-22 07:50:24 +00:00
Handle arbitrary leading and trailing spaces in variables (#282)
This commit is contained in:
parent
f7410774c8
commit
e78eee1829
2 changed files with 50 additions and 2 deletions
|
|
@ -252,10 +252,11 @@ export function extractChatHistory(memoryVariables: MemoryVariables): [string, s
|
|||
}
|
||||
|
||||
export function processVariableName(variableName: string): string {
|
||||
variableName = variableName.trim();
|
||||
// Check if the variable name is enclosed in double brackets indicating it's a note
|
||||
if (variableName.startsWith('[[') && variableName.endsWith(']]')) {
|
||||
// It's a note, so we remove the brackets and append '.md'
|
||||
return `${variableName.slice(2, -2)}.md`;
|
||||
return `${variableName.slice(2, -2).trim()}.md`;
|
||||
}
|
||||
// It's a path, so we just return it as is
|
||||
return variableName;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import * as Obsidian from 'obsidian';
|
||||
import { getNotesFromPath, isFolderMatch } from '../src/utils';
|
||||
import { getNotesFromPath, isFolderMatch, processVariableName } from '../src/utils';
|
||||
|
||||
|
||||
describe('isFolderMatch', () => {
|
||||
|
|
@ -94,4 +94,51 @@ describe('getNotesFromPath', () => {
|
|||
const files = await getNotesFromPath(vault, '');
|
||||
expect(files).toEqual([]);
|
||||
});
|
||||
|
||||
describe('processVariableName', () => {
|
||||
it('should return the note md filename', () => {
|
||||
const variableName = processVariableName('[[test]]');
|
||||
expect(variableName).toEqual('test.md');
|
||||
});
|
||||
|
||||
it('should return the note md filename with extra spaces 1', () => {
|
||||
const variableName = processVariableName(' [[ test]]');
|
||||
expect(variableName).toEqual('test.md');
|
||||
});
|
||||
|
||||
it('should return the note md filename with extra spaces 2', () => {
|
||||
const variableName = processVariableName('[[ test ]] ');
|
||||
expect(variableName).toEqual('test.md');
|
||||
});
|
||||
|
||||
it('should return the note md filename with extra spaces 2', () => {
|
||||
const variableName = processVariableName(' [[ test note ]] ');
|
||||
expect(variableName).toEqual('test note.md');
|
||||
});
|
||||
|
||||
it('should return the note md filename with extra spaces 2', () => {
|
||||
const variableName = processVariableName(' [[ test_note note ]] ');
|
||||
expect(variableName).toEqual('test_note note.md');
|
||||
});
|
||||
|
||||
it('should return folder path with leading slash', () => {
|
||||
const variableName = processVariableName('/testfolder');
|
||||
expect(variableName).toEqual('/testfolder');
|
||||
});
|
||||
|
||||
it('should return folder path without slash', () => {
|
||||
const variableName = processVariableName('testfolder');
|
||||
expect(variableName).toEqual('testfolder');
|
||||
});
|
||||
|
||||
it('should return folder path with trailing slash', () => {
|
||||
const variableName = processVariableName('testfolder/');
|
||||
expect(variableName).toEqual('testfolder/');
|
||||
});
|
||||
|
||||
it('should return folder path with leading spaces', () => {
|
||||
const variableName = processVariableName(' testfolder ');
|
||||
expect(variableName).toEqual('testfolder');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue