TfTHacker / obsidian42-strange-new-worlds

Revealing the strange new world of connected thoughts in your vault.
https://tfthacker.com/SNW
MIT License
433 stars 13 forks source link

Add counter to headers #64

Closed sawft99 closed 1 year ago

sawft99 commented 1 year ago

I think having counters in headers would be useful. Shown in the red dot.

1

TfTHacker commented 1 year ago

Hi, there is support for headers. Can you show me the markdown so I can see if there is some issue?

CleanShot 2022-12-16 at 13 08 10

sawft99 commented 1 year ago

Hi, there is support for headers. Can you show me the markdown so I can see if there is some issue?

CleanShot 2022-12-16 at 13 08 10

This page referencing this page

At the bottom it references objective 1.1 but the header on that page does not have a counter.

image

Maybe because it's an h2?

sawft99 commented 1 year ago

Nah doesn't work on h1 either

TfTHacker commented 1 year ago

So this proved to be a very bizarre issue. Headings are a bit of a dark art in Obsidian, so I really can't explain it. But in your example there is a space between Engineering and technique. When you link to it, Obsidian removes that space (check your second document and notice the link doesn't have the extra space. In fact, when I click on the link it opens the "objectives" document, but doesn't jump to the header. Even Obsidian is confused.

When I remove the space from the heading and relink in the second document, both Obsidian behaves as expected and so does SNW.

So long story short, don't have extra blank spaces in headings :-)

It's a bizarre edge case. I can't fix it when even Obsidian can be confused by it.

sawft99 commented 1 year ago

That seems to be a coincidence and bad example. I have a tag in the title so probably why. However, none of my other ones seem to have a counter. Here's one without a weird space/tag issue that still doesn't bring up a counter. I tried removing the '|' symbol just to try it and I still didn't have one.

image

image

sawft99 commented 1 year ago

@TfTHacker Can this get reopened since as I demonstrated this happens in other titles that are formatted correctly? I have tons of links to my objectives file and none of the headers have a counter showing.

sawft99 commented 1 year ago

Doing some more work on my end and I noticed an instance where headers didn't popup. The header is "Application Programming Interface (API)". If I remove the parentheses so that is just "Application Programming Interface" the counter shows up.

danrthompson commented 1 year ago

Yes, it appears that links to headers do show the counter, and they seem to show the correct counter if there are multiple of them (as in, if there are two links linking to the same header, they'll show a count of 2, implying that the plug-in is able to detect the links).

But, there is no reference count on the header, which is unfortunate because that is a super important feature for me.

I'd be happy to pay a $20 bounty if you can get this working! :)

Thanks so much for you hard work!!

image
sawft99 commented 1 year ago

Some of my headers have counters. Just not when i have the parentheses in the header for this example

danrthompson commented 1 year ago

Mine do not at all unfortunately

danrthompson commented 1 year ago

@TfTHacker dunno if you saw my message above but I'd be happy to pay a $20 bounty for this. If that's not enough, let me know what would be.

No problem if you no longer are intending to maintain this project and don't have an interest in continuing with it (although I'll be very sad!!!)

danrthompson commented 1 year ago

For some reason this seems to be working again!

It seems like one key thing is that if you do an in-page link, you need to include the file. So if you're on a daily note page named 2023-02-15 and you're linking to #HeaderExample, then when you open a link and type #, then select the heading, it will by default render as [[#HeaderExample]]. This will work when you click on it, but it will not work for this plugin's reference counts.

So, instead you need to do [[journals/2023-02-15#HeaderExample]].

Also note that if you have your links set to Shortest possible it would by default render the link above without the folder name, so it would be [[2023-02-15#HeaderExample]], without the journals/ prefix. I think that may have been another cause of the issue. But when I made sure to include the file, and I changed the setting New link format from Shortest path when possible to Absolute path in vault, so that it does include the folder prefix, it started working again.

Not 100% sure that the absolute path in vault setting was part of the issue, but I think it was.

Anyway, hopefully this gets it working again for anyone else who was experiencing this issue.

sawft99 commented 1 year ago

Hopefully this can be patched so I don't have to change the links for all of my references.

danrthompson commented 1 year ago

Actually I take it back, it doesn't look like the absolute path thing is necessary. Just that you need to have the filename in the link, not just a header for same-page references. There is a weird bug that seems to happen where some of the reference counts on the links will be wrong if you use a mix of shortest and absolute though. So basically be consistent and use the filename in all cases.

But still take even this with a grain of salt - I just did 15 mins of testing so I could still be wrong about this. But it is working for me with shortest path links for same-page linking.

It could be that relative links are OK, shortest are not (because in a same page link relative and shortest are the same). It could mean that shortest and relative are OK. Not 100% sure. But it seems absolute is not necessary

TfTHacker commented 1 year ago

So I made some major effort on headers. Please test with 1.2.0 and let me know if there are still issues. 1.2.0 should come out in a day or two.