Skip to content

Commit b0b1320

Browse files
authored
Merge pull request #3119 from ilandikov/fix-list-item-rendering
fix: sub-list items now render OK - no bullet, number, callout/blockquote etc
2 parents 7bf7ae3 + 38b7678 commit b0b1320

File tree

6 files changed

+35
-5
lines changed

6 files changed

+35
-5
lines changed

resources/sample_vaults/Tasks-Demo/Manual Testing/Callouts and Block Quotes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,38 @@ sort by description
3535
## 2 Vanilla
3636

3737
- [ ] #task Task 1 Vanilla
38+
- Child list item of 'Task 1 Vanilla'
3839
- [ ] #task Task 2 Vanilla
3940

4041
## 3 Callout
4142

4243
> [!NOTE]
4344
>
4445
> - [ ] #task Task 1 Callout
46+
> - Child list item of 'Task 1 Callout'
4547
> - [ ] #task Task 2 Callout
4648
4749
### 3.1 Callout containing Blockquote
4850

4951
> [!NOTE]
5052
> >
5153
> > - [ ] #task Task 1 Callout containing Blockquote
54+
> > - Child list item of 'Task 1 Callout containing Blockquote'
5255
> > - [ ] #task Task 2 Callout containing Blockquote
5356
>
5457
5558
## 4 Blockquote
5659

5760
> - [ ] #task Task 1 Blockquote
61+
> - Child list item of 'Task 1 Blockquote'
5862
> - [ ] #task Task 2 Blockquote
5963
6064
### 4.1 Blockquote containing Callout
6165

6266
> > [!NOTE]
6367
> >
6468
> > - [ ] #task Task 1 Blockquote containing Callout
69+
> > - Child list item of 'Task 1 Blockquote containing Callout'
6570
> > - [ ] #task Task 2 Blockquote containing Callout
6671
6772
## 5 Numbered task in unordered list
@@ -82,4 +87,5 @@ x - [ ] #task wibble
8287
### 6.1 Task in numbered list
8388

8489
1. [ ] #task Task 1 Task in numbered list
90+
1. Child list item of 'Task 1 Task in numbered list'
8591
2. [ ] #task Task 2 Task in numbered list

src/Renderer/QueryResultsRenderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ export class QueryResultsRenderer {
290290

291291
private addListItem(taskList: HTMLUListElement, listItem: ListItem) {
292292
const li = createAndAppendElement('li', taskList);
293-
li.textContent = listItem.originalMarkdown;
293+
li.textContent = listItem.description;
294294
return li;
295295
}
296296

src/Task/ListItem.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { TaskRegularExpressions } from './TaskRegularExpressions';
2+
13
export class ListItem {
24
/** The original line read from file.
35
*
@@ -7,8 +9,10 @@ export class ListItem {
79

810
public readonly parent: ListItem | null = null;
911
public readonly children: ListItem[] = [];
12+
public readonly description: string;
1013

1114
constructor(originalMarkdown: string, parent: ListItem | null) {
15+
this.description = originalMarkdown.replace(TaskRegularExpressions.listItemRegex, '').trim();
1216
this.originalMarkdown = originalMarkdown;
1317
this.parent = parent;
1418

tests/Renderer/QueryResultsRenderer.test.QueryResultsRenderer_tests_parent-child_items.approved.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<a class="tasks-edit" title="Edit task" href="#"></a>
6161
</span>
6262
<ul class="contains-task-list plugin-tasks-query-result tasks-layout-hide-urgency">
63-
<li>- list item grand grand child</li>
63+
<li>list item grand grand child</li>
6464
</ul>
6565
</li>
6666
</ul>
@@ -86,7 +86,7 @@
8686
</span>
8787
<ul class="contains-task-list plugin-tasks-query-result tasks-layout-hide-urgency">
8888
<li>
89-
- non task grandchild
89+
non task grandchild
9090
<ul class="contains-task-list plugin-tasks-query-result tasks-layout-hide-urgency">
9191
<li
9292
class="task-list-item plugin-tasks-list-item"

tests/Renderer/QueryResultsRenderer.test.QueryResultsRenderer_tests_parent-child_items_reverse_sorted.approved.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
<a class="tasks-edit" title="Edit task" href="#"></a>
8181
</span>
8282
<ul class="contains-task-list plugin-tasks-query-result tasks-layout-hide-urgency">
83-
<li>- list item grand grand child</li>
83+
<li>list item grand grand child</li>
8484
</ul>
8585
</li>
8686
</ul>
@@ -106,7 +106,7 @@
106106
</span>
107107
<ul class="contains-task-list plugin-tasks-query-result tasks-layout-hide-urgency">
108108
<li>
109-
- non task grandchild
109+
non task grandchild
110110
<ul class="contains-task-list plugin-tasks-query-result tasks-layout-hide-urgency">
111111
<li
112112
class="task-list-item plugin-tasks-list-item"

tests/Task/ListItem.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,24 @@ describe('list item tests', () => {
7575
expect(parent.isRoot).toEqual(false);
7676
expect(child.isRoot).toEqual(false);
7777
});
78+
79+
it.each([
80+
['- ', true],
81+
['* ', true],
82+
['+ ', true],
83+
['17. ', true],
84+
[' - ', true],
85+
['> - ', true],
86+
['> > - ', true],
87+
])('should parse description with list item prefix: "%s"', (prefix: string, shouldPass) => {
88+
const description = 'stuff';
89+
const line = prefix + description;
90+
const listItem = new ListItem(line, null);
91+
expect(listItem.originalMarkdown).toEqual(line);
92+
if (shouldPass) {
93+
expect(listItem.description).toEqual(description);
94+
} else {
95+
expect(listItem.description).not.toEqual(description);
96+
}
97+
});
7898
});

0 commit comments

Comments
 (0)