Skip to content

Commit

Permalink
Merge pull request obsidian-tasks-group#3119 from ilandikov/fix-list-…
Browse files Browse the repository at this point in the history
…item-rendering

fix: sub-list items now render OK - no bullet, number, callout/blockquote etc
  • Loading branch information
claremacrae authored Oct 14, 2024
2 parents 7bf7ae3 + 38b7678 commit b0b1320
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,38 @@ sort by description
## 2 Vanilla

- [ ] #task Task 1 Vanilla
- Child list item of 'Task 1 Vanilla'
- [ ] #task Task 2 Vanilla

## 3 Callout

> [!NOTE]
>
> - [ ] #task Task 1 Callout
> - Child list item of 'Task 1 Callout'
> - [ ] #task Task 2 Callout
### 3.1 Callout containing Blockquote

> [!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

> > [!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
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/Renderer/QueryResultsRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions src/Task/ListItem.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { TaskRegularExpressions } from './TaskRegularExpressions';

export class ListItem {
/** The original line read from file.
*
Expand All @@ -7,8 +9,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.replace(TaskRegularExpressions.listItemRegex, '').trim();
this.originalMarkdown = originalMarkdown;
this.parent = parent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<a class="tasks-edit" title="Edit task" href="#"></a>
</span>
<ul class="contains-task-list plugin-tasks-query-result tasks-layout-hide-urgency">
<li>- list item grand grand child</li>
<li>list item grand grand child</li>
</ul>
</li>
</ul>
Expand All @@ -86,7 +86,7 @@
</span>
<ul class="contains-task-list plugin-tasks-query-result tasks-layout-hide-urgency">
<li>
- non task grandchild
non task grandchild
<ul class="contains-task-list plugin-tasks-query-result tasks-layout-hide-urgency">
<li
class="task-list-item plugin-tasks-list-item"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<a class="tasks-edit" title="Edit task" href="#"></a>
</span>
<ul class="contains-task-list plugin-tasks-query-result tasks-layout-hide-urgency">
<li>- list item grand grand child</li>
<li>list item grand grand child</li>
</ul>
</li>
</ul>
Expand All @@ -106,7 +106,7 @@
</span>
<ul class="contains-task-list plugin-tasks-query-result tasks-layout-hide-urgency">
<li>
- non task grandchild
non task grandchild
<ul class="contains-task-list plugin-tasks-query-result tasks-layout-hide-urgency">
<li
class="task-list-item plugin-tasks-list-item"
Expand Down
20 changes: 20 additions & 0 deletions tests/Task/ListItem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,24 @@ describe('list item tests', () => {
expect(parent.isRoot).toEqual(false);
expect(child.isRoot).toEqual(false);
});

it.each([
['- ', true],
['* ', true],
['+ ', true],
['17. ', true],
[' - ', true],
['> - ', true],
['> > - ', true],
])('should parse description with list item prefix: "%s"', (prefix: string, shouldPass) => {
const description = 'stuff';
const line = prefix + description;
const listItem = new ListItem(line, null);
expect(listItem.originalMarkdown).toEqual(line);
if (shouldPass) {
expect(listItem.description).toEqual(description);
} else {
expect(listItem.description).not.toEqual(description);
}
});
});

0 comments on commit b0b1320

Please sign in to comment.