davraamides / todotxt-mode

MIT License
59 stars 12 forks source link

Feature request : in markdown use todotxt codeblocks instead of "Tasks" header #16

Closed jpbourgeon closed 4 years ago

jpbourgeon commented 4 years ago

Hi

I use your extension extensively. thanks for the good work.

In my opinion, in markdown files, it would be more aligned with both languages specifications to merge todotxt tasks into codeblocks instead of a tasks section. For example:

Replace this :

## Tasks
(A) @context +project task due:date
(B) @context +project2 task2 due:date
x YYYY-MM-DD @context2 +project2 task3 key:value

by this (I replaced the codeblocks backticks by singlequotes but you get it)

'''todotxt
(A) @context +project task due:date
(B) @context +project2 task2 due:date
x YYYY-MM-DD @context2 +project2 task3 key:value
'''

I see 3 reasons for this change:

It may be an opportunity to isolate the tasks inside markdown more efficiently to make all the good stuff of your extension available to todotxt codeblocks in markdown too (like sorting, tagging priorities, etc.) and even provide new opportunities like having multiple tasks sections in the same document with power comments before the codeblock <!-- todotxt:task_filtering_regex --> For an example:

## Project Todolist

<!-- todotxt:^.*\+project .*$ -->
'''todotxt
(A) @context +project task due:date
'''

## Project 2 completed tasks

<!-- todotxt:^x.*\+project2 .*$ -->
'''todotxt
x YYYY-MM-DD @context2 +project2 task3 key:value
'''

Thanks for considering this !

davraamides commented 4 years ago

Thanks for the interesting suggestions, Jean-Philippe. I've actually been jammed with work since I started living in lockdown a month ago so haven't had time to look at this but hopefully things will get more normal and I'll have time to look at this more carefully in the near future.

Note that the Markdown integration simply uses two regular expressions: todotxtmode.markdownDecorationBeginPattern and todotxtmode.markdownDecorationEndPattern, which have defaults of using a "Tasks" heading. Changing them to use a special codeblock pattern should work fine (as well as changing them to use "Tâches à faire" as you mention).

In terms of support of the other features within that region (sorting, priorities, etc.) I'll have to look and see how good a job I did generalizing the code!

jpbourgeon commented 4 years ago

Wonderful @davraamides !

I should have read the docs more carefully (RTFM) :-)

In my .code-workspace :

{
  //...
  "todotxtmode.markdownDecorationBeginPattern": "^\\`\\`\\`todotxt$",
  "todotxtmode.markdownDecorationEndPattern": "^\\`\\`\\`$",
}

Works like a charm 👍

I tried a few shortcut inside a code block (priority, completing task, archiving...) and it works quite well

davraamides commented 4 years ago

That's great. I'm going to close this for now. If you find problems, feel free to open another issue.

emesar commented 3 years ago

Hi - sorry for resurrecting an old thread, but for whatever reason I can't get the todotxtmode.markdownDecorationBeginPattern and todotxtmode.markdownDecorationEndPattern settings to work. I've tried a variety of different RegEx patterns (including the default and the code block example above) without success. Is this feature no longer supported? Or am I doing something horribly wrong? Appreciate any help!

davraamides commented 3 years ago

Hi emesar. Yes, this still works. I've pasted an image below showing an example. In addition to the two settings you mentioned, there is also the todotxtmode.markdownFilePattern pattern that defines the Markdown filenames that should have this behavior enabled. The default is ^.*\\.(md|markdown)$ which would match files ending in .md or in .markdown. Is it possible you are naming yours differently?

Screen Shot 2021-02-26 at 11 20 08 AM
emesar commented 3 years ago

Hi @davraamides, thanks for the quick response. Based on your feedback, I realized my issue might be with the specific RegEx flavor being used. Ended up discovering that while this didn't work:

{
  "todotxtmode.markdownDecorationBeginPattern": "^\\`\\`\\`todotxt$",
  "todotxtmode.markdownDecorationEndPattern": "^\\`\\`\\`$",
}

This did work:

{
  "todotxtmode.markdownDecorationBeginPattern": "^```todotxt$",
  "todotxtmode.markdownDecorationEndPattern": "^```$",
}

With that knowledge, I settled on the patterns I actually wanted: image

Seems to work perfectly now. Thanks for your help, and all of your great work on this extension!

davraamides commented 3 years ago

Good to hear. The regex patterns can be tricky, plus the pasting into these comments can mess them up (screen shots are better).