Skip to content

[Bug] Empty task list items are parsed as normal bullet items and lose their checkbox #4680

Closed

Description

@Renakoni

Description

Empty task list items lose their task-list semantics when a Markdown file is opened in MarkText.

A task item with text, such as - [ ] a, is parsed correctly and rendered with a checkbox. However, an empty task item such as - [ ] or - [x] is parsed as a normal bullet list item whose text is the literal string [ ] or [x].

This means a valid todo-list placeholder is no longer clickable, the checkbox disappears, and a single task list can be split into a task list plus a normal bullet list.

Steps to Reproduce

Case 1: empty unchecked task item after a filled task item

Create a Markdown file with this content:

- [ ] a
- [ ] 

Note: the second line is - [ ] , with a trailing space after the closing bracket. Escaped form:

"- [ ] a\n- [ ] \n"

Then:

  1. Open the file in MarkText.
  2. Look at the second list item.
  3. Compare it with the first task item.

Optional persistence check:

  1. Click after a.
  2. Type any character, for example x.
  3. Save the file.
  4. Reopen the file or inspect it in a plain text editor.

Case 2: single empty task item

Create a Markdown file with this content:

- [ ] 

or:

- [x] 

Open it in MarkText.

Expected Behavior

Empty task list items should remain task list items.

For Case 1, MarkText should render one task list with two task items and two checkboxes:

- [ ] a
- [ ] 

The second item should be an empty unchecked task item. It should still show a checkbox and should not become a normal bullet item.

For Case 2, - [ ] should render as a single empty unchecked task item, and - [x] should render as a single empty checked task item.

Actual Behavior

For Case 1, MarkText renders only the first line as a task item. The second line becomes a normal bullet list item whose visible text is [ ].

Observed structure:

taskLists: 1
taskItems: 1
checkboxes: 1
bulletLists: 1
listItems: 2
visible text: "a\n\n[ ]"

So the original single task list is split into:

  1. A task list containing - [ ] a.
  2. A normal bullet list containing the literal text [ ].

If the document is edited and saved, the corrupted structure is persisted. For example, after changing a to ax, the file is saved as:

- [ ] ax

- [ ]

For Case 2, a single empty task item is also parsed as a normal bullet item:

- [ ] 

is rendered as a bullet item with visible text [ ], with no checkbox.

- [x] 

is rendered as a bullet item with visible text [x], with no checkbox.

Screenshots / Logs

No crash log is produced. This is a parsing / round-trip fidelity issue.

Image The problem appears to happen during Markdown parsing/token compatibility handling, before serialization.

The relevant path is:

  • packages/muya/src/utils/marked/lexBlock.ts
  • packages/muya/src/utils/marked/compatibleTaskList.ts
  • packages/muya/src/state/markdownToState.ts

compatibleTaskList.ts classifies unordered list items using item.task:

const listItemType = item.task ? 'task' : 'bullet';
item.listItemType = listItemType;
if (item.task)
    stripTaskMarker(item);

For a non-empty task item, such as:

- [ ] a

the lexer produces a list item with task: true, checked: false, and text a. It is then converted into a task-list-item.

For an empty task item, such as:

- [ ] 

the lexer produces a list item with task: false and text [ ]. After that, compatibleTaskList.ts marks it as a normal bullet item, and markdownToState.ts has no way to recover the intended checkbox semantics.

Observed token shape for - [ ] :

{
  "type": "list_item",
  "raw": "- [ ]",
  "task": false,
  "text": "[ ]",
  "listItemType": "bullet"
}

Because of this, the state tree becomes a bullet-list / list-item with paragraph text [ ], instead of a task-list / task-list-item with checked: false and empty children.

Opening a clean file and immediately saving may leave the original bytes unchanged because the desktop app still has the original Markdown cached. However, the UI is already wrong on open, and any edit that refreshes the Markdown from the parsed state will persist the corrupted structure on save.

Operating System

Windows

MarkText Version

0.20.0-beta.2

OS Version

Windows 11 Pro, version 10.0.26200, build 26200

Reproducibility

  • I can reliably reproduce this issue

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions