obsidian-tasks: Multi-line tasks (indented lines below a task items) are not shown in Reading mode and Tasks query results

Please check that this issue hasn’t been reported before.

  • I searched previous Bug Reports didn’t find any similar reports.

Expected Behavior

I have two items, one of them a task item with some lines below it (used Shift-Enter to insert these lines). This results in markdown:

- [ ] first line
        second line
        and so one
- not the same behavior for a normal item
    with some more lines
    and another line

The lines below the task item are not shown in read-mode. Rendering as

image

in edit mode it looks like

image

This happens only, when the task plugin is enabled.

See also: https://forum.obsidian.md/t/lines-below-task-item-not-visible/61807

Current behaviour

Lines are hidden.

Steps to reproduce

  1. Setup empty vault
  2. Paste markdown snippet from above
  3. Look (edit: in Reading mode)
  4. Install and enable task plugin
  5. Restart
  6. Look again (edit: in Reading mode)

Which Operating Systems are you using?

  • Android
  • iPhone/iPad
  • Linux
  • macOS
  • Windows

Obsidian Version

1.3.5

Tasks Plugin Version

4.0.0

Checks

  • I have tried it with all other plugins disabled and the error still occurs

Possible solution

No response

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 10
  • Comments: 26

Commits related to this issue

Most upvoted comments

As a case of “two birds with one stone”, would it be possible to consider the following lines of multi-line tasks as part of the description? Then it would be displayed and useable in filters. (I’m willing to contribute to this, if that seems like a reasonable approach.)

Hi @cvincent, many thanks again for your comments above…

Here are my initial ideas…

What the Tasks Reading Mode code does - and where is it?

I have just added JSDocs class descriptions to all the key classes involved in rendering, in this plugin. See https://github.com/obsidian-tasks-group/obsidian-tasks/commit/bf5e65bf161601f4698c3a621d4d62241c9226e7

Is this actually part of a rewrite of the Reading mode rendering?

My initial assumption: incrementally improve InlineRenderer.ts

Until recently, I had assumed that this issue could be solved by incrementally improving the Reading Mode implementation in Tasks code: InlineRenderer.ts.

My long comment above assumes that

Alternative approach: start afresh with handling Reading Mode

However the list of bugs associated with Reading Mode is long:

And the Obsidian API has changed a lot since InlineRenderer.ts was written.

So I am starting to wonder whether we should take a step back, and explore whether there are ways to:

  • add the same Tasks features in Reading mode (custom click-handling, and adding of CSS to elements of task lines)
  • but without all the current bugs and limitations…

I honestly do not know which is the best approach - and we should involve @ilandikov in discussions on this.

New tests added since my initial breakdown of this project

I wrote above that we didn’t have tests for any Obsidian code. However since then, we have written a way to visualise how Obsidian interprets Markdown, so we can use that info in tests with confidence:

And we now have tests that the HTML that Tasks generates when rendering task lines:

There is already a file showing how Obsidian parses and stores multi-line task and list items:

Obsidian’s ‘Strict line breaks’ option

I have done some experiments and established the ‘Strict line breaks’ option only changes how Obsidian renders Markdown.

It does not change how it parses Markdown.

That means that once Tasks supports rendering of multi-line tasks, it will need to:

  1. Honour that Obsidian setting
  2. Listen out for changes in this Obsidian setting, and re-render

Ideally those would be done in separate steps, to keep the PRs small and easy to reason about.

Hi @thesamim,

Would appreciate any feedback on the topic…

Sure, as you can see, this is one of quite a number of Issues and Discussions that is marked as High Priority:

That means I understand the importance of this issue.

And that it is effectively competing with all the other high priority ones.

There are a lot of factors going in to where amongst all those High Priority requests I spend my free time. There are very many more issues than I have time to address - and that will always be true.

I do not need any more comments here to persuade me of the value of doing this.

And as I was saying only on Discord earlier today

Just don’t ever add information-less “bump”-type comments as I treat them as a spam and a strong down-vote!

So, if this issue gets a bunch of “me-too” posts, it will drop significantly down the priority list and I may even remove the High Priority label from it.

When I say that this is a large body of work, here is the kind of thing that I mean…

tl;dr This isn’t a single-PR change, it’s a series of incremental changes, each of which needs to be safe, and the code on main needs to be releasable throughout the entire process.

If anyone is interested in committing to work on this, I would be available to answer questions, and would add links below to the relevant code locations.

Caveat: this is what I came up with, in about an hour of thinking about it. There may be other things I missed.

Requirements to make this change

My personal philosophy is to always review PRs carefully, to be as confident as I can be that changes (by me and others) do not accidentally cause breakages for users.

This means I only accept PRs to Tasks that contain individual changes, and where any refactorings have been made in small, incremental changes.

I need to either:

  • Be able to view the before-and-after code side by side, and reason about all the changes
  • Or the PR is made up of small commits, each of which I can review as above

Exceptions to this are:

  • There were already extremely thorough unit tests before the refactoring was started

Unfortunately any code in Plugins that imports types from Obsidian like Plugin, MetadataCache, Vault… were not written to be unit-tested… so do not have Jest tests in most plugins.

An exception to this is the Projectswhich may give ideas. (Its licence is Apache - I don’t know if that is compatible with Tasks’ MIT licence.)

How to make this change

I see this change a series of PRs, each of which addresses an incremental part of the project.

For example, there could be some initial PRs to:

  • Add thorough test coverage for the areas that will change
  • Refactor to unify areas of code where the same thing is done in multiple ways
  • Update the storage in Task so that it is capable of reading and writing multi-line tasks
    • But do not expose the feature yet
  • Update the rendering so that it does handle multi-line tasks
    • But do not expose the feature yet
  • Update the Task toggling code so that it handles multi-line tasks
    • But do not expose the feature yet

etc

How to change the Markdown reading and writing code

It would need to make sure that multiline tasks are both:

  • read correctly
  • written back out as multiple lines, with the line-breaks in the same places, and the same indentation as before

Storing tasks

  • Currently the relevant data in a task is stored like this
    • Would need to look at the code to see where those variables

Task.ts

Searching tasks

  • task.originalMarkdown is a documented facility in - Task Properties - so somehow this would need to be maintained, in order to not break user searches
    • At a minimum, that documentation would need to be updated to say how multi-line tasks are represented.

Rendering of tasks

Places to consider:

  • Rendering in Reading Mode
  • Rendering in Live Preview
  • Rendering Search Results (has code in common with Reading Mode)

Users interacting with tasks

  • the Edit Task modal…
    • It’s currently designed for the description to be a single line.
    • It’s text box would fit multiple lines already, but how would the user control indentation?
  • Toggling tasks

Testing

  • Jest tests would of course be needed
  • This is big enough that the Smoke Tests would also need to include a simple test of interacting with a multi line task

User Documentation

Hi @cvincent, many thanks for your kind message. Things have changed a bit with the code since I wrong the long list of steps above, so I will need some time to reply thoroughly, which I plan to do in the next few days.

@claremacrae I was reading through your comment as I am making initial considerations on whether to commit some time to this issue. I appreciate the clear explanation of your process and your deliberate approach.

I have a question. Have you thought about how Tasks would interact with this option in Obsidian?

Image

My use case, for context, is that I do most of my note editing in NeoVim where it is configured to hard-wrap long lines as I’m typing when a line extends beyond a certain column. So in my case, and per the Markdown specs according to the setting description in Obsidian, when this setting is on, single line breaks in a task item should be ignored, and the text instead joined together as though it were on a single line, which happens to be my desired behavior. In this mode, some of the concerns you outlined wouldn’t be an issue at all (e.g., the editor window would not actually need to support multiple lines). But, for this to be a complete feature, as this is a user preference in base Obsidian, the implementation would likely need to understand this setting and do the right thing in both cases.

What are your thoughts? And thank you for this excellent plugin!

I use <br> to replace \n, and it works for me.

For those who want to still a workaround of having a very descriptive task that needs to span multiple lines, an alternative is to basically hyperlink your task.


...

- [ ] Perform [[this-markdown-page#task_description|task]]

...

...

...

# Tasks/Appendix
## task_description
Have your multiline 
task under this heading
supporting all markdown syntax

Sorry for not responding earlier, Clare! I missed the notification and failed to add a “come back to this” to my tasks tracker. 😅 Work also picked up a bit, so I haven’t had as much “learning time” as before.

That’s definitely a larger chunk of work than I would have hoped for, but I completely agree with the philosophy. I’m out of time for looking at things today, but I will try to make time tomorrow for digging into that some.

One of the benefits of multiple PRs could also be more distributed work, with regards to both time and persons. Hopefully others will be able to build on things as well.

@floli I’ve just noticed you’ve pasted the same image link in twice, and it’s not obvious because the image is not shown.

Please kindly edit the report above and paste in the actual images, rather than links to them…

  • to ensure that the data is here and not lost in case anything happens to the forum post
  • and to save people here from have to click away from this report to understand it.

Many thanks.