stefanopagliari / bibnotes

360 stars 30 forks source link

Bug: some `{{UserNotes}}` still not retrieved #48

Closed chrisgrieser closed 2 years ago

chrisgrieser commented 2 years ago

I was going through my imports, and noticed that quite a few of them are still missing the {{UserNotes}}. While most of the time, the user notes now get extracted, I'd estimate that it's about a third of the notes where notes aren't extracted even though they should...

Here is a sample of a file where user notes aren't retrieved.

Sample.json.zip

chrisgrieser commented 2 years ago

also cc @MichaBrugger, I guess

MichaBrugger commented 2 years ago

Ill have look tomorrow 👍🏼

stefanopagliari commented 2 years ago

I found the line of code where the problem happens but I'm not sure why.

Basically here, the code takes the template and replace the placeholder {{UserNotes}} with the extractedUserNote

The value of the extractedUserNote here is "Überzeugung über zwei Routen (Dual-processing of human mind) \par 1. zentrale Route über explizite Argumente \par 2. periphere Route über Einstellungen und Emotionen \par wesnetliche Variablen der Persuasion (ähnlich zur Laswell-Formel) \par \beginitemize ıtem Kommunikator (Glaubwürdigkeit, Attraktivität, soziale Ähnlichkeit) ıtem Nachricht (gebildete Menschen reagieren eher auf Vernunft, uninteressierte, ungebildete Menschen eher auf Emotionen, gute Stimmung der Nachricht, Furchteinflößung der Nachricht) ıtem Art der Kommunikation ıtem Publikum -$>$ älteres Publikum wechselt seltener Einstellungen -$>$ Aussterben von Meinungen, aber auch Involviertheit und Vorbereitetheit des Publikums \enditemize"

But instead of replacing the placeholder {{UserNotes}}, this is retained inside the annotation in place of the $& character: "Überzeugung über zwei Routen (Dual-processing of human mind) \par 1. zentrale Route über explizite Argumente \par 2. periphere Route über Einstellungen und Emotionen \par wesnetliche Variablen der Persuasion (ähnlich zur Laswell-Formel) \par \beginitemize ıtem Kommunikator (Glaubwürdigkeit, Attraktivität, soziale Ähnlichkeit) ıtem Nachricht (gebildete Menschen reagieren eher auf Vernunft, uninteressierte, ungebildete Menschen eher auf Emotionen, gute Stimmung der Nachricht, Furchteinflößung der Nachricht) ıtem Art der Kommunikation ıtem Publikum -{{UserNotes}}gt;$ älteres Publikum wechselt seltener Einstellungen -{{UserNotes}}gt;$ Aussterben von Meinungen, aber auch Involviertheit und Vorbereitetheit des Publikums \enditemize"

From reading online I found that string.replace treats $& as a command to "insert the matched substring".


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace

This causes that line to be removed later in the code when the plugin search for {{}} placeholders that were left in the note and removes the entire sentence .

I'm not really sure how to deal with this. The solution I have found on Stack suggests replacing $& with something else, although that would end up editing the content of the note (assuming there is a legitimate reason for using $&) https://stackoverflow.com/questions/56148062/javascript-how-to-skip-in-replace-function

chrisgrieser commented 2 years ago

I think from my side, you can basically remove the $& – I think it's some artifact from the fact that those notes haven been converted from one app format to the other much too often...

stefanopagliari commented 2 years ago

@chrisgrieser, I have pushed an update (https://github.com/stefanopagliari/bibnotes/releases/tag/0.9.13) where I simply replaced "&$" with "& $". I don't feel great about this solution because it may change cases where those characters have a precise meaning, but I will keep an eye. Could you please let me know if it works for you?

chrisgrieser commented 2 years ago

Hmmm, using the very same sample from above, the notes unfortunately still do not get extracted :(

stefanopagliari commented 2 years ago

Is the source Myers2012e? If so would you mind sending me the very lengthy console logs that I have forgot to hide before pushing this version? It does work in my case.

chrisgrieser commented 2 years ago

obsidian.md-1643668517741.log yeah, it's still Meyers2012e.

However, I found a workaround by simply replacing all instances of $& in my Library.json – then bibnotes is able to read everything correctly.

Like, when you cannot pin down the issue, it's probably not worth to invest so much time in a problem that's probably a one-off, since I don't know whether other users would ever have the same problem (since my notes are a result from tons of converting between formats)

stefanopagliari commented 2 years ago

I suspect that the version you have is not the latest (the console.logs would be much longer), and probably the reason may be that I have forgot to update the number on manifest.json, so it may not update via BRAT. What I have done in the latest version is the same (replace $& in the comments).