Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: support for checking list item block-id in Note Updates #109

Closed
FeralFlora opened this issue Mar 26, 2023 · 10 comments
Closed

Feature: support for checking list item block-id in Note Updates #109

FeralFlora opened this issue Mar 26, 2023 · 10 comments
Labels
enhancement New feature or request

Comments

@FeralFlora
Copy link

FeralFlora commented Mar 26, 2023

Using this annot template:

---
callout: false
---

<% if (it.imgEmbed) { %>
- <%= it.imgEmbed %>
<% } %>
<% if (it.comment) { %>
- <% if (it.comment.startsWith('todo ')) { %>[ ] **<%= it.comment.substring(5) %>:**<% } else { %>**<%= it.comment %>:**<% } %>  
	- ==<%= it.text %>== [p. <%= it.pageLabel %>](zotero://open-pdf/library/items/<%= it.parentItem %>?page=<%= it.pageLabel %>&annotation=<%= it.key %>) ^<%= it.blockID %><% if (it.tags && it.tags.length > 0) { %> <% = it.tags.map(tag => '#' + tag.name).join(", ") %><% } %>  
<% } else if (it.text) { %>
- ==<%= it.text %>== [p. <%= it.pageLabel %>](zotero://open-pdf/library/items/<%= it.parentItem %>?page=<%= it.pageLabel %>&annotation=<%= it.key %>) ^<%= it.blockID %><% if (it.tags && it.tags.length > 0) { %> <% = it.tags.map(tag => '#' + tag.name).join(", ") %><% } %>  
<% } %>

Am I using the blockID wrong? Perhaps it doesn't work when comments and annotations are list items? In any case, I don't think the info from the settings is sufficient:

If you disable callout wrapping in annotation template, you need to make sure block-id is added properly in the template.

What does properly mean here?

@aidenlx
Copy link
Member

aidenlx commented Mar 27, 2023

well in obsidian, block-id should be placed at the end of a block, such as regular paragraph, blockquote, callout etc. the handling of list as a block is a bit tricky. You can place it at the end of a list item to refer to specific one item, or at new line right next to the end of list to refer to the entire list.

You can test if it works by placing block-id and check if the block can be refer to in internal link auto-complete. https://help.obsidian.md/Linking+notes+and+files/Internal+links#Link+to+a+block+in+a+note

@FeralFlora
Copy link
Author

well in obsidian, block-id should be placed at the end of a block, such as regular paragraph, blockquote, callout etc. the handling of list as a block is a bit tricky. You can place it at the end of a list item to refer to specific one item, or at new line right next to the end of list to refer to the entire list.

I tried adding block-ids to all list items in my annot template, but all the annotations are still being reimported and duplicated (a new set of every heading and annotation), each time I update the literature note. This happens with In-place Update of Existing Annotations either disabled or enabled (doesn't change the update behavior).

See this screen recording:
Obsidian_0FKDSX8hN1

At the end, I switched to Reading mode to demonstrate that the block-ids are recognized by Obsidian, since they disappear in Reading mode.

My current annot template is as follows:

---
callout: false
---

<% if (it.imgEmbed) { %>
- <%= it.imgEmbed %> ^<%= it.blockID %>\n
<% } %>
<% if (it.comment) { %>
- <% if (it.comment.startsWith('todo ')) { %>[ ] **<%= it.comment.substring(5) %>:**<% } else { %>**<%= it.comment %>:**<% } %> ^<%= it.blockID %>\n
	- ==<%= it.text %>== [p. <%= it.pageLabel %>](zotero://open-pdf/library/items/<%= it.parentItem %>?page=<%= it.pageLabel %>&annotation=<%= it.key %>) <% if (it.tags && it.tags.length > 0) { %> <% = it.tags.map(tag => '#' + tag.name).join(", ") %><% } %>^<%= it.blockID %>\n
<% } else if (it.text) { %>
- ==<%= it.text %>== [p. <%= it.pageLabel %>](zotero://open-pdf/library/items/<%= it.parentItem %>?page=<%= it.pageLabel %>&annotation=<%= it.key %>) <% if (it.tags && it.tags.length > 0) { %> <% = it.tags.map(tag => '#' + tag.name).join(", ") %><% } %>^<%= it.blockID %>\n
<% } %>

@FeralFlora
Copy link
Author

Another issue here is that if I reference a block in the literature note, which already has a block-id, in another note, Obsidian will not use this block-id, but will add another one.

See:
image

And here, embedded in another file:
image

This is strange, because Obsidian supports custom block-ids like ^something and will reuse those.

^something test:
image

^something Embedded in another file:
image

@aidenlx
Copy link
Member

aidenlx commented Mar 27, 2023

  • ==<%= it.text %>== [p. <%= it.pageLabel %>](zotero://open-pdf/library/items/<%= it.parentItem %>?page=<%= it.pageLabel %>&annotation=<%= it.key %>) <% if (it.tags && it.tags.length > 0) { %> <% = it.tags.map(tag => '#' + tag.name).join(", ") %><% } %>^<%= it.blockID %>\n

well you need a space before ^block-id to get it work properly, something like whatever in the paragraph ^block-id

@FeralFlora
Copy link
Author

I believe the output of this does have a space.

@aidenlx
Copy link
Member

aidenlx commented Mar 27, 2023

In your template some of the ^<%= it.blockID %> is right next to the previous text without space in between, you can see that the block-id is not recognized properly in editor because of that.

I haven't explictly support update at the level of list item yet, so currently using this template should get in-place updates working:

---
callout: false
---

<% if (it.imgEmbed) { %>
- <%= it.imgEmbed %> ^<%= it.blockID %>\n
<% } %>
<% if (it.comment) { %>
- <% if (it.comment.startsWith('todo ')) { %>[ ] **<%= it.comment.substring(5) %>:**<% } else { %>**<%= it.comment %>:**<% } %>\n
	- ==<%= it.text %>== [p. <%= it.pageLabel %>](it.backlink) <% if (it.tags && it.tags.length > 0) { %> <% = it.tags.map(tag => '#' + tag.name).join(", ") %><% } %>\n
<% } else if (it.text) { %>
- ==<%= it.text %>== [p. <%= it.pageLabel %>](it.backlink) <% if (it.tags && it.tags.length > 0) { %> <% = it.tags.map(tag => '#' + tag.name).join(", ") %><% } %>\n
<% } %>

 ^<%= it.blockID %>

This should work fine as long as you don't enable in-place update

---
callout: false
---

<% if (it.imgEmbed) { %>
- <%= it.imgEmbed %> ^<%= it.blockID %>\n
<% } %>
<% if (it.comment) { %>
- <% if (it.comment.startsWith('todo ')) { %>[ ] **<%= it.comment.substring(5) %>:**<% } else { %>**<%= it.comment %>:**<% } %> ^<%= it.blockID %>\n
	- ==<%= it.text %>== [p. <%= it.pageLabel %>](it.backlink) <% if (it.tags && it.tags.length > 0) { %> <% = it.tags.map(tag => '#' + tag.name).join(", ") %><% } %>\n
<% } else if (it.text) { %>
- ==<%= it.text %>== [p. <%= it.pageLabel %>](it.backlink) <% if (it.tags && it.tags.length > 0) { %> <% = it.tags.map(tag => '#' + tag.name).join(", ") %><% } %> ^<%= it.blockID %>\n
<% } %>

@aidenlx
Copy link
Member

aidenlx commented Mar 27, 2023

okay i see the problem, I haven't handle block-id inside list items during annotation checks, I'll mark this as a feature request since I haven't explictly support update at the level of list item yet

@aidenlx aidenlx added the enhancement New feature or request label Mar 27, 2023
@aidenlx aidenlx changed the title Update Literature Note duplicates all annotations despite adding blockIDs to annotations with annotations unwrapped by callouts. Feature: support for checking list item block-id in Note Updates Mar 27, 2023
@krillin666
Copy link

okay i see the problem, I haven't handle block-id inside list items during annotation checks, I'll mark this as a feature request since I haven't explictly support update at the level of list item yet

Since I'm using this with Logseq, would it be possible to add the blockids to property:: <%= it.blockID %> instead of ^<%= it.blockID %>

@FeralFlora
Copy link
Author

FeralFlora commented Mar 28, 2023

well you need a space before ^block-id to get it work properly, something like whatever in the paragraph ^block-id

That's not true. Try this test: Link to a block, so Obsidian generates a block-id. Then, delete the space so the block-id right next to the text. The block link will still work, and the block-id will still disappear in Reading mode. I just tested this.

Here's a demo of the test above:

Obsidian_hJMwOv0pbW

In your template some of the ^<%= it.blockID %> is right next to the previous text without space in between.

You are right about the fact that if there are tags, the block-id won't have a space. I didn't notice because:
a. Not that many of my annotations have tags
b. Like I wrote above, it doesn't affect the functionality of the block-ids.

I left out a space there because in the case of no tags, there would be two spaces before the block-id (the one before the tags and the one before the block-id. I fixed it by adding a space as you noted, and putting the space before the tags inside the tags' if statement.

you can see that the block-id is not recognized properly in editor because of that.

That's not what you can see in the screenshot below. The reason the block-id from Obsidian-Zotero is not recognized in these screenshots is because Obsidian added another block-id after I linked to the block, like I wrote.

image

Below, you are seeing the block embedded in another note. The Obsidian block-id is not visible, because they aren't visible in block embeds. Only the Obsidian-Zotero block-id is visible, because it is not recognized as a block-id after Obsidian added another block-id after it.

image

However, since the 1.0.1 update, Obsidian now reuses the Obsidian-Zotero block-ids when I link to or embed those blocks. I am not sure what changed. Did you provide a fix for that?

okay i see the problem, I haven't handle block-id inside list items during annotation checks, I'll mark this as a feature request since I haven't explictly support update at the level of list item yet

I guess this means that we are in agreement that the space was not the issue. So the examples you provided won't work yet?

@aidenlx
Copy link
Member

aidenlx commented Mar 29, 2023

since the 1.0.1 update, Obsidian now reuses the Obsidian-Zotero block-ids when I link to or embed those blocks. I am not sure what changed. Did you provide a fix for that

The update around this is not available before 1.0.2, maybe it's because your latest template fix the block-id formatting issue? The initial template introduced space after block-id, making it invaild, and the update template posted later seems to have that fixed.

In 1.0.2, the block-id in list item are detected as well, so it should not creating duplicates now.

@aidenlx aidenlx closed this as completed Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants