diff --git a/docs/data-tables/obsidian-tasks.md b/docs/data-tables/obsidian-tasks.md index 1fc81af..facc5fe 100644 --- a/docs/data-tables/obsidian-tasks.md +++ b/docs/data-tables/obsidian-tasks.md @@ -29,4 +29,5 @@ Table Name: `obsidian_tasks` | scheduledDate | string | When the task is scheduled next ['⏳', 'scheduled::'] | | doDate | string | When to do the task ['πŸ’¨', 'do::'] | | priority | number | Priority of task based on indicator ['β«πŸ”ΌπŸ”½', 'priority::'] | -| cleanTask | string | The task string with all metadata removed. | \ No newline at end of file +| cleanTask | string | The task string with all metadata removed. | +| blockLink | string | manually specified block Link for the task | diff --git a/src/Parse/Parsers.ts b/src/Parse/Parsers.ts index e44da5b..d7145ab 100644 --- a/src/Parse/Parsers.ts +++ b/src/Parse/Parsers.ts @@ -21,10 +21,13 @@ export const parseTask = (taskString: string) => { let doDate: string | undefined; let priority; let cleanTask = taskString; + let blockLink: string | undefined; for (let index = 0; index < tokens.length; index++) { parseTags(tokens, index, tags, tagsNormalized); - + // Check to see is the token is a block link and if it is then set the block link property. The + // block link is in the form of a '^' character followed by only Latin letters, numbers, and dashes. + blockLink = parseBlockLink(tokens, index); dueDate = dueDate ?? parseDate(tokens, index, dueDatePrefixes); doneDate = doneDate ?? parseDate(tokens, index, doneDatePrefixes); startDate = startDate ?? parseDate(tokens, index, startDatePrefixes); @@ -77,9 +80,13 @@ export const parseTask = (taskString: string) => { } } + if (blockLink) { + cleanTask = cleanTask.replace(`^${blockLink}`, ''); + } + cleanTask = cleanTask.trim().slice(6); - return {tags, tagsNormalized, dueDate, doneDate, startDate, createDate, scheduledDate, doDate, priority, cleanTask}; + return {tags, tagsNormalized, dueDate, doneDate, startDate, createDate, scheduledDate, doDate, priority, cleanTask, blockLink}; }; const regex = /[[|(](.+?):: (.+?)[\]|)]/g; @@ -200,3 +207,11 @@ function parseTags(tokens: string[], index: number, tags: string[], tagsNormaliz } } } + +function parseBlockLink(tokens: string[], index: number) { + if (tokens[index].startsWith('^')) { + return tokens[index].slice(1); + } + + return undefined; +} diff --git a/src/TaskItem.ts b/src/TaskItem.ts index 1abcdad..707ccae 100644 --- a/src/TaskItem.ts +++ b/src/TaskItem.ts @@ -36,6 +36,7 @@ Table Name: `obsidian_tasks` | doDate | string | When to do the task ['πŸ’¨', 'do::'] | | priority | number | Priority of task based on indicator ['β«πŸ”ΌπŸ”½', 'priority::'] | | cleanTask | string | The task string with all metadata removed. | +| blockLink | string | Manually specified block Link for the task | // << docs-tables-obsidian-tasks */ @@ -61,6 +62,7 @@ export class TaskItem { public doDate: string; public priority: number; public cleanTask: string; + public blockLink: string; public listItem: ListItem; private _parsedTask: any; @@ -78,6 +80,7 @@ export class TaskItem { this.doDate = this._parsedTask.doDate; this.priority = this._parsedTask.priority; this.cleanTask = this._parsedTask.cleanTask; + this.blockLink = this._parsedTask.blockLink; this.page = listItem.path; this.path = listItem.path; diff --git a/tests/ParseTask.test.ts b/tests/ParseTask.test.ts index 18fbe7d..22a175f 100644 --- a/tests/ParseTask.test.ts +++ b/tests/ParseTask.test.ts @@ -1,10 +1,9 @@ /* eslint-disable @typescript-eslint/no-floating-promises */ import {describe, test} from 'node:test'; import assert from 'node:assert'; -import {ListItem} from 'ListItem'; -import {Note} from 'Note'; import {parseDataViewProperty, parseTask} from 'Parse/Parsers'; import {TaskItem} from 'TaskItem'; +import {ListItem} from 'ListItem'; describe('parse functions', () => { test('task parses tags correctly', () => { @@ -113,6 +112,12 @@ describe('parse functions', () => { assert.strictEqual(parsedTask.cleanTask, 'this is a task'); }); + test('task parses block link correctly', () => { + const parsedTask = parseTask('- [ ] this is a task πŸ“… 2022-03-05 [priority:: high] ^123ASD-asd'); + assert.strictEqual(parsedTask.blockLink, '123ASD-asd'); + assert.strictEqual(parsedTask.cleanTask, 'this is a task'); + }); + test('task parses are fast', () => { const sampleTask = '- [ ] this is a task #TasK #test [priority:: high] πŸ“… 2022-03-05 βœ… 2022-04-05'; let parsedTask = parseTask(sampleTask);