KNHaw / ThunderbirdObsidianClipper

A Thunderbird extension to clip messages to the Obsidian notetaking application.
Mozilla Public License 2.0
16 stars 0 forks source link

Obsidian properties: list type #15

Closed BBazard closed 8 months ago

BBazard commented 9 months ago

Fantastic clipper, thank you! I think it would be great to make more use of the obsidian properties / frontmatter. I am using

---
Open Email: _MSGIDURI
Date: _MSGYEAR-_MSGMONTH-_MSGDAY _MSGHOUR:_MSGMIN:_MSGSEC
From: _MSGAUTHOR
To: _MSGRECIPENTS
Subject: "_MSGSUBJECT"
---

_MSGCONTENT

Now I would like to use a list property type for the field To (and Cc/Bc if they are added). Which requires to change the formatting to be yaml compatible

To: RECIPIENT1, RECIPIENT2

becomes

To:
  - RECIPIENT1
  - RECIPIENT2
KNHaw commented 9 months ago

OK. Seems doable. The easiest approach is to implement a _MSGRECIPIENTSLIST that gives the same data as _MSGRECIPENTS (and similar _MSGCCLIST and _MSGBCCLIST placeholders when I implement that issue too) but with the data formatted as a list.

I think this would serve your needs. Would you agree with that assessment?

BBazard commented 9 months ago

Yes, sounds good.

To be yaml compatible that would also be good to escape quotes, otherwise obsidian cannot parse the frontmatter.

"Kevin N. Haw" <notifications@github.com>

becomes

"\"Kevin N. Haw\" <notifications@github.com>"
KNHaw commented 9 months ago

Good. I'm chewing on it but am concerned about a few things from my original idea.

First, what happens in YAML if the properties are empty? For example, imagine a message with no one CC'd:

Recipients:
- "\"Kevin N. Haw\" <notifications@github.com>"
- "\"Bill Gates\" <bill@microsoft.com>"
CC:
BCC:
- "\"Sen. Elizabeth Warren\" <senwarren@senate.gov>"

Will YAML understand that there is nothing in the CC field or does it confuse it with BCC? If it can't handle that then I need way to not print "CC" here. That requires interaction between user content and message content, which I haven't done yet and adds more complexity. I can try it out myself but if you already know please enlighten me.

Second, your comment about escaping quotes is making me wonder about other syntactic pitfalls here. I'll do some searching but offhand do you know of a formal definition of the YAML syntax? I want to have every contingency handled in my code and have test cases to exercise it when I try this.

As always, thanks for using ObsidianClipper! I'm so happy it's useful to people.

BBazard commented 9 months ago

Nice thinking for the missing value edge case. After tests, I see that if a property is empty, obsidian just displays Empty, no special handling required.

Looking at some spec I see that Double-Quoted Style is the only style capable of expressing arbitrary strings: https://yaml.org/spec/1.2.2/#731-double-quoted-style

So the easiest way would be to just surround the string with " and escape " and \ Examples: string -> "string" "string" -> "\"string\"" \u0040 is '@' -> "\\u0040 is '@'"

It is admittedly less readable than just plain style. But since obsidian pretty-print the properties in live preview, I think it's good enough to convert everything to double quoted style.

PS: not sure how you test the obsidian properties, but I personally use the Toggle Live Preview/Source mode from the command palette.

KNHaw commented 8 months ago

OK. I just submitted v0.3.2 for approval with this and Issue #14 implemented. It should be pushed to users next week. I will close out this issue when it's live.

KNHaw commented 8 months ago

v0.3.2 is out so I'm going to close this issue. Please reopen or create a new issue if there are problems.

Thanks for using ObsidianClipper!