Task text color based on tag

What I’m trying to do

I’d love to be able to color the text of a task shown with dataview, based on a tag. For instance, I would have the task :

  • Buy eggs #groceries #2aa34b

I want the text “Buy eggs” in the color of the tag that represents the hex color.
I don’t expect dataview to “read” the tag color, I would set it up in advance (for instance, in a css snippets). Having the tag with the hex color code just helps to avoid having two tags associated with colors for the same entry.

Things I have tried

I found a snippet to color the actual tag text in this thread.
The main reason I would like this to work is to use it with the task calendar made by 702573N. There is an option to change the box/text color from the color property of a page, but I sometimes have different tasks topic on one page.

Thank you for your help!

the first thing that occurs to me is to use CSS selectors. You could theoretically find the selector for the tag itself, then use a selector for its task parent, then get the text for the task. Unfortunately, There is currently no way to select the parent of an element in CSS in a way that works across all browsers. Maybe wiser heads can answer about that…

1 Like

Are you expecting the solution to accomodate whatever hex code there is, or would you be satisfied with just a few colors?

Why do you want to explicitly specify color in each task and not based on groceries tag for example? I mean more useful would be to create - [ ] buy eggs #groceries and then this task would take the color based on the #groceries. The essence of this approach is to avoid overloaded use of colors and instead dedicate few chosen tags to have pre-defined colors. You also get consistency because now the tag comes with some color.

1 Like

I would be satisfied with a few colors. The hex code would only be to make sure I don’t have several tags with colors.

To avoid several tags with associated colors. That way, even if a task has #groceries AND #vegetables (just an example here), I can make sure there is only one color. I would still pre-define the color code tag, and the tasks would only have one color tag to avoid an overloaded use of colors.

If you pre-define your color tag then why don’t you give it more descriptive name like #personal? I like the idea of having consistent task coloring, but it could be achieved by tag ordering: first tag gives the color for example.

I’d be ok with that, but I still don’t know how to apply the color to the task’s text and not just the tag.