From 5b57bc7ca1f226391f96e2bde6d270eea9e31063 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Mon, 14 Oct 2024 18:32:49 +0600 Subject: [PATCH 01/11] refactor: - add description field to List Item --- src/Task/ListItem.ts | 2 ++ tests/Task/ListItem.test.ts | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/Task/ListItem.ts b/src/Task/ListItem.ts index 447c849da7..cb373a60ac 100644 --- a/src/Task/ListItem.ts +++ b/src/Task/ListItem.ts @@ -7,8 +7,10 @@ export class ListItem { public readonly parent: ListItem | null = null; public readonly children: ListItem[] = []; + public readonly description: string; constructor(originalMarkdown: string, parent: ListItem | null) { + this.description = originalMarkdown; this.originalMarkdown = originalMarkdown; this.parent = parent; diff --git a/tests/Task/ListItem.test.ts b/tests/Task/ListItem.test.ts index 0e016b2354..6a5c907606 100644 --- a/tests/Task/ListItem.test.ts +++ b/tests/Task/ListItem.test.ts @@ -75,4 +75,10 @@ describe('list item tests', () => { expect(parent.isRoot).toEqual(false); expect(child.isRoot).toEqual(false); }); + + it('should parse description from markdown line', () => { + const listItem = new ListItem('- the dash should not be in the description', null); + expect(listItem.originalMarkdown).toEqual('- the dash should not be in the description'); + expect(listItem.description).toEqual('- the dash should not be in the description'); + }); }); From 91ac97f03fcfded6a56da7efc8f527e55e47f23f Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Mon, 14 Oct 2024 18:36:24 +0600 Subject: [PATCH 02/11] refactor: - initialise ListItem. description for one type of list --- src/Task/ListItem.ts | 2 +- tests/Task/ListItem.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Task/ListItem.ts b/src/Task/ListItem.ts index cb373a60ac..c782879ad2 100644 --- a/src/Task/ListItem.ts +++ b/src/Task/ListItem.ts @@ -10,7 +10,7 @@ export class ListItem { public readonly description: string; constructor(originalMarkdown: string, parent: ListItem | null) { - this.description = originalMarkdown; + this.description = originalMarkdown.replace(/^- /, ''); this.originalMarkdown = originalMarkdown; this.parent = parent; diff --git a/tests/Task/ListItem.test.ts b/tests/Task/ListItem.test.ts index 6a5c907606..ea2ae4b431 100644 --- a/tests/Task/ListItem.test.ts +++ b/tests/Task/ListItem.test.ts @@ -79,6 +79,6 @@ describe('list item tests', () => { it('should parse description from markdown line', () => { const listItem = new ListItem('- the dash should not be in the description', null); expect(listItem.originalMarkdown).toEqual('- the dash should not be in the description'); - expect(listItem.description).toEqual('- the dash should not be in the description'); + expect(listItem.description).toEqual('the dash should not be in the description'); }); }); From 884e8dd37564a18c8b843c811bd48f687275db7d Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Mon, 14 Oct 2024 18:39:06 +0600 Subject: [PATCH 03/11] test: - add failing test with numbered list --- tests/Task/ListItem.test.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/Task/ListItem.test.ts b/tests/Task/ListItem.test.ts index ea2ae4b431..69687f5225 100644 --- a/tests/Task/ListItem.test.ts +++ b/tests/Task/ListItem.test.ts @@ -81,4 +81,10 @@ describe('list item tests', () => { expect(listItem.originalMarkdown).toEqual('- the dash should not be in the description'); expect(listItem.description).toEqual('the dash should not be in the description'); }); + + it.failing('should parse description from numbered list', () => { + const listItem = new ListItem('17. the number and the dot should not be in the description', null); + expect(listItem.originalMarkdown).toEqual('17. the number and the dot should not be in the description'); + expect(listItem.description).toEqual('the number and the dot should not be in the description'); + }); }); From 193352bd767fc1ad37afac7789556faf80c89ce8 Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Mon, 14 Oct 2024 18:47:04 +0600 Subject: [PATCH 04/11] refactor: - support nested list items --- src/Task/ListItem.ts | 2 +- tests/Task/ListItem.test.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Task/ListItem.ts b/src/Task/ListItem.ts index c782879ad2..69bf3bd628 100644 --- a/src/Task/ListItem.ts +++ b/src/Task/ListItem.ts @@ -10,7 +10,7 @@ export class ListItem { public readonly description: string; constructor(originalMarkdown: string, parent: ListItem | null) { - this.description = originalMarkdown.replace(/^- /, ''); + this.description = originalMarkdown.replace(/^\s*- /, ''); this.originalMarkdown = originalMarkdown; this.parent = parent; diff --git a/tests/Task/ListItem.test.ts b/tests/Task/ListItem.test.ts index 69687f5225..b9aa9edf52 100644 --- a/tests/Task/ListItem.test.ts +++ b/tests/Task/ListItem.test.ts @@ -82,6 +82,12 @@ describe('list item tests', () => { expect(listItem.description).toEqual('the dash should not be in the description'); }); + it('should parse description from indented markdown line', () => { + const listItem = new ListItem(' - do stuff', null); + expect(listItem.originalMarkdown).toEqual(' - do stuff'); + expect(listItem.description).toEqual('do stuff'); + }); + it.failing('should parse description from numbered list', () => { const listItem = new ListItem('17. the number and the dot should not be in the description', null); expect(listItem.originalMarkdown).toEqual('17. the number and the dot should not be in the description'); From ad7e52293471ebc71c58a6b3c791dc7cb6c95bea Mon Sep 17 00:00:00 2001 From: Ilyas Landikov Date: Mon, 14 Oct 2024 18:50:10 +0600 Subject: [PATCH 05/11] fix: - fix rendering of list items with simple hyphen prefix --- src/Renderer/QueryResultsRenderer.ts | 2 +- ...ueryResultsRenderer_tests_parent-child_items.approved.html | 4 ++-- ...erer_tests_parent-child_items_reverse_sorted.approved.html | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Renderer/QueryResultsRenderer.ts b/src/Renderer/QueryResultsRenderer.ts index 702d81757d..760d75d185 100644 --- a/src/Renderer/QueryResultsRenderer.ts +++ b/src/Renderer/QueryResultsRenderer.ts @@ -290,7 +290,7 @@ export class QueryResultsRenderer { private addListItem(taskList: HTMLUListElement, listItem: ListItem) { const li = createAndAppendElement('li', taskList); - li.textContent = listItem.originalMarkdown; + li.textContent = listItem.description; return li; } diff --git a/tests/Renderer/QueryResultsRenderer.test.QueryResultsRenderer_tests_parent-child_items.approved.html b/tests/Renderer/QueryResultsRenderer.test.QueryResultsRenderer_tests_parent-child_items.approved.html index 421ee93573..92d37c21fe 100644 --- a/tests/Renderer/QueryResultsRenderer.test.QueryResultsRenderer_tests_parent-child_items.approved.html +++ b/tests/Renderer/QueryResultsRenderer.test.QueryResultsRenderer_tests_parent-child_items.approved.html @@ -60,7 +60,7 @@
    -
  • - list item grand grand child
  • +
  • list item grand grand child
@@ -86,7 +86,7 @@
  • - - non task grandchild + non task grandchild
      • -
      • - list item grand grand child
      • +
      • list item grand grand child
    @@ -106,7 +106,7 @@
    • - - non task grandchild + non task grandchild
      • Date: Mon, 14 Oct 2024 14:34:45 +0100 Subject: [PATCH 06/11] test: - Convert description tests to it.each() --- tests/Task/ListItem.test.ts | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/tests/Task/ListItem.test.ts b/tests/Task/ListItem.test.ts index b9aa9edf52..de59be4902 100644 --- a/tests/Task/ListItem.test.ts +++ b/tests/Task/ListItem.test.ts @@ -76,21 +76,16 @@ describe('list item tests', () => { expect(child.isRoot).toEqual(false); }); - it('should parse description from markdown line', () => { - const listItem = new ListItem('- the dash should not be in the description', null); - expect(listItem.originalMarkdown).toEqual('- the dash should not be in the description'); - expect(listItem.description).toEqual('the dash should not be in the description'); - }); - - it('should parse description from indented markdown line', () => { - const listItem = new ListItem(' - do stuff', null); - expect(listItem.originalMarkdown).toEqual(' - do stuff'); - expect(listItem.description).toEqual('do stuff'); - }); - - it.failing('should parse description from numbered list', () => { - const listItem = new ListItem('17. the number and the dot should not be in the description', null); - expect(listItem.originalMarkdown).toEqual('17. the number and the dot should not be in the description'); - expect(listItem.description).toEqual('the number and the dot should not be in the description'); + it.each([ + ['- the dash should not be in the description', 'the dash should not be in the description'], + [' - do stuff', 'do stuff'], + [ + '17. the number and the dot should not be in the description', + '17. the number and the dot should not be in the description', + ], + ])('list item description: "%s"', (line: string, expectedDescription: string) => { + const listItem = new ListItem(line, null); + expect(listItem.originalMarkdown).toEqual(line); + expect(listItem.description).toEqual(expectedDescription); }); }); From 4bc85b80ebc2f3813b81bb4d8e36dc5546efc26f Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Mon, 14 Oct 2024 14:40:38 +0100 Subject: [PATCH 07/11] test: - Remove repetition from tests of list item descriptions --- tests/Task/ListItem.test.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/Task/ListItem.test.ts b/tests/Task/ListItem.test.ts index de59be4902..3d9d61bf38 100644 --- a/tests/Task/ListItem.test.ts +++ b/tests/Task/ListItem.test.ts @@ -77,15 +77,18 @@ describe('list item tests', () => { }); it.each([ - ['- the dash should not be in the description', 'the dash should not be in the description'], - [' - do stuff', 'do stuff'], - [ - '17. the number and the dot should not be in the description', - '17. the number and the dot should not be in the description', - ], - ])('list item description: "%s"', (line: string, expectedDescription: string) => { + ['- ', true], + [' - ', true], + ['17. ', false], + ])('list item description: "%s"', (prefix: string, shouldPass) => { + const description = 'stuff'; + const line = prefix + description; const listItem = new ListItem(line, null); expect(listItem.originalMarkdown).toEqual(line); - expect(listItem.description).toEqual(expectedDescription); + if (shouldPass) { + expect(listItem.description).toEqual(description); + } else { + expect(listItem.description).not.toEqual(description); + } }); }); From 18eba92eeee0462ef7f7cba693b692749071a010 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Mon, 14 Oct 2024 14:41:59 +0100 Subject: [PATCH 08/11] test: - Clarify test name --- tests/Task/ListItem.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Task/ListItem.test.ts b/tests/Task/ListItem.test.ts index 3d9d61bf38..10aecb34b5 100644 --- a/tests/Task/ListItem.test.ts +++ b/tests/Task/ListItem.test.ts @@ -80,7 +80,7 @@ describe('list item tests', () => { ['- ', true], [' - ', true], ['17. ', false], - ])('list item description: "%s"', (prefix: string, shouldPass) => { + ])('should parse description with list item prefix: "%s"', (prefix: string, shouldPass) => { const description = 'stuff'; const line = prefix + description; const listItem = new ListItem(line, null); From 80c6a4a379132ef4ee2819c270ab0f2a0368fcc2 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Mon, 14 Oct 2024 14:48:47 +0100 Subject: [PATCH 09/11] test: add failing tests for other list item prefixes --- tests/Task/ListItem.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/Task/ListItem.test.ts b/tests/Task/ListItem.test.ts index 10aecb34b5..0e07380913 100644 --- a/tests/Task/ListItem.test.ts +++ b/tests/Task/ListItem.test.ts @@ -78,8 +78,12 @@ describe('list item tests', () => { it.each([ ['- ', true], - [' - ', true], + ['* ', false], + ['+ ', false], ['17. ', false], + [' - ', true], + ['> - ', false], + ['> > - ', false], ])('should parse description with list item prefix: "%s"', (prefix: string, shouldPass) => { const description = 'stuff'; const line = prefix + description; From cea93a309c00550fcc23234a3778ac81638ad5a3 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Mon, 14 Oct 2024 15:00:24 +0100 Subject: [PATCH 10/11] fix: Fix parsing of description for all supported list prefixes --- src/Task/ListItem.ts | 4 +++- tests/Task/ListItem.test.ts | 10 +++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Task/ListItem.ts b/src/Task/ListItem.ts index 69bf3bd628..b97584cd54 100644 --- a/src/Task/ListItem.ts +++ b/src/Task/ListItem.ts @@ -1,3 +1,5 @@ +import { TaskRegularExpressions } from './TaskRegularExpressions'; + export class ListItem { /** The original line read from file. * @@ -10,7 +12,7 @@ export class ListItem { public readonly description: string; constructor(originalMarkdown: string, parent: ListItem | null) { - this.description = originalMarkdown.replace(/^\s*- /, ''); + this.description = originalMarkdown.replace(TaskRegularExpressions.listItemRegex, '').trim(); this.originalMarkdown = originalMarkdown; this.parent = parent; diff --git a/tests/Task/ListItem.test.ts b/tests/Task/ListItem.test.ts index 0e07380913..7bd45ab3c0 100644 --- a/tests/Task/ListItem.test.ts +++ b/tests/Task/ListItem.test.ts @@ -78,12 +78,12 @@ describe('list item tests', () => { it.each([ ['- ', true], - ['* ', false], - ['+ ', false], - ['17. ', false], + ['* ', true], + ['+ ', true], + ['17. ', true], [' - ', true], - ['> - ', false], - ['> > - ', false], + ['> - ', true], + ['> > - ', true], ])('should parse description with list item prefix: "%s"', (prefix: string, shouldPass) => { const description = 'stuff'; const line = prefix + description; From 38b767872da919b19357fcd58b03b2f00518c1c4 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Mon, 14 Oct 2024 15:04:29 +0100 Subject: [PATCH 11/11] vault: Add some nested list items to test rendering of description --- .../Tasks-Demo/Manual Testing/Callouts and Block Quotes.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/resources/sample_vaults/Tasks-Demo/Manual Testing/Callouts and Block Quotes.md b/resources/sample_vaults/Tasks-Demo/Manual Testing/Callouts and Block Quotes.md index 9051fa6a26..45febb0cd4 100644 --- a/resources/sample_vaults/Tasks-Demo/Manual Testing/Callouts and Block Quotes.md +++ b/resources/sample_vaults/Tasks-Demo/Manual Testing/Callouts and Block Quotes.md @@ -35,6 +35,7 @@ sort by description ## 2 Vanilla - [ ] #task Task 1 Vanilla + - Child list item of 'Task 1 Vanilla' - [ ] #task Task 2 Vanilla ## 3 Callout @@ -42,6 +43,7 @@ sort by description > [!NOTE] > > - [ ] #task Task 1 Callout +> - Child list item of 'Task 1 Callout' > - [ ] #task Task 2 Callout ### 3.1 Callout containing Blockquote @@ -49,12 +51,14 @@ sort by description > [!NOTE] > > > > - [ ] #task Task 1 Callout containing Blockquote +> > - Child list item of 'Task 1 Callout containing Blockquote' > > - [ ] #task Task 2 Callout containing Blockquote > ## 4 Blockquote > - [ ] #task Task 1 Blockquote +> - Child list item of 'Task 1 Blockquote' > - [ ] #task Task 2 Blockquote ### 4.1 Blockquote containing Callout @@ -62,6 +66,7 @@ sort by description > > [!NOTE] > > > > - [ ] #task Task 1 Blockquote containing Callout +> > - Child list item of 'Task 1 Blockquote containing Callout' > > - [ ] #task Task 2 Blockquote containing Callout ## 5 Numbered task in unordered list @@ -82,4 +87,5 @@ x - [ ] #task wibble ### 6.1 Task in numbered list 1. [ ] #task Task 1 Task in numbered list + 1. Child list item of 'Task 1 Task in numbered list' 2. [ ] #task Task 2 Task in numbered list