Render a full list of references at the bottom of the note viewer#16
Render a full list of references at the bottom of the note viewer#16
Conversation
laurent22
left a comment
There was a problem hiding this comment.
That looks good overall. Your approach to create the reference list token and parse it in particular seems solid. I've just left a few comments.
By the way, could you create a documentation for the format you support? In particular what is this APA thing and what citation formats your plugin supports or creates. For example you have both "Steinbeck2003" and "bu-EtAl:2010:EMNLP". I suppose there's a reason for that, which should be explained in the Readme.
| const refs: Reference[] = parse(fileContent); | ||
| DataStore.setReferences(refs); | ||
|
|
||
| } catch (e) { } |
There was a problem hiding this comment.
I seem to remember you were previously displaying an error with the line number when the file could not be parsed. Was that removed? In general I think the user should be informed if their file can't be loaded. Can you use alert() here for example? Or joplin.views.dialogs.showMessage?
| */ | ||
| await joplin.contentScripts.onMessage(REFERENCE_LIST_CONTENT_SCRIPT_ID, (IDs: string[]) => { | ||
| let refs: string[] = []; | ||
| IDs = [...new Set(IDs)]; |
There was a problem hiding this comment.
You're often converting arrays to set and the other way around. Is there any reason for that? Isn't this code pretty much the same as IDS = IDS?
There was a problem hiding this comment.
Isn't this code pretty much the same as
IDS = IDS?
Not exactly. Previously, if there are multiple occurrences of the same reference, it will be rendered twice at the bottom.
There was a problem hiding this comment.
Ok I see. It's not very obvious that it's doing this so maybe add a comment?
| return ` | ||
| <h1 id="references_title" style="display:none">References</h1> | ||
| <ul id="references_list"></ul> | ||
| <style onload='${script.replace(/\n/g, ' ')}'/> |
There was a problem hiding this comment.
Any reason you used a style tag for this? Wouldn't it be possible to wrap your script string simply in a <script> tag? I think that would be more proper and perhaps more reliable too.
There was a problem hiding this comment.
Wouldn't it be possible to wrap your script string simply in a <script> tag? I think that would be more proper and perhaps more reliable too.
I tried that approach as it seems to be the most natural but for, some reason, it does not seem to work.
There was a problem hiding this comment.
Ok, I think this is fragile code that may break at some point or even work in some operating systems but not others. I think it didn't work with the script tag because you need to wait till the "webviewApi" is available. For this you can use the same pattern - just keep checking typeof webviewApi until it becomes available, then run your initialisation code.
There was a problem hiding this comment.
Whatever I put in the script tag does not get executed.
There was a problem hiding this comment.
I'm wondering if you're looking at all this the wrong way around. The plugin sets the HTML, and has all the references, so instead of adding a script that post messages, can't you directly set the HTML to the correct value from the plugin? Then you won't need a script at all inside the content script.
There was a problem hiding this comment.
In the documentation, there is no description of such approach (in markdown-it plugin section)
There was a problem hiding this comment.
It's not something about documentation, since it's specific to your plugin. But come to think of it, what I'm suggesting wouldn't work since the reference data is in the plugin process, and the content script in the main process, so there would still be a need for some kind of ipc call. So let's leave it as it is for now.
|
Renamed |
Yeah sure, before releasing the new version, I'm gonna do that in addition to updating the main GIF that shows the working mechanism of the plugin. |
| const referenceListView = document.getElementById("references_list"); | ||
| const referenceTitleView = document.getElementById("references_title"); | ||
| if (refs.length > 0) referenceTitleView.style.display = "block"; | ||
| refs.forEach(ref => referenceListView.innerHTML += ref); |
There was a problem hiding this comment.
Instead of setting innerHTML multiple times, which is slow, you could build up the HTML string in the loop, then set the inner HTML once at the end.
There was a problem hiding this comment.
My bad, I keep doing these silly mistakes 😃
|
DONE |
What has been done