Converting HTML note to Markdown results in new noteID which breaks any Joplin links to that note

Operating system

Windows

Joplin version

3.7.12

Desktop version info

Joplin 3.7.12 (prod, win32)

Device: win32, 11th Gen Intel(R) Core(TM) i9-11900K @ 3.50GHz
Client ID: a504afc6d2a6496b99a0931c22649537
Sync Version: 3
Profile Version: 53
Keychain Supported: Yes
Alternative instance ID: -
Sync target: Dropbox
Editor: Rich Text

Revision: bed73cd

Backup: 1.5.1
Combine notes: 1.2.3
Favorites: 1.3.2
Freehand Drawing: 4.3.0
Menu items, Shortcuts, Toolbar icons: 1.1.0
Note list (Preview): 1.1.0
Test Plugin: 1.0.01.0
Test Plugin: 1.0.0

Sync target

Dropbox

Editor

Rich Text Editor

What issue do you have?

I'm currently running into this issue which is blocking a lot of my conversion work, of bringing in notes from Evernote and repairing the broken Evernote internal links as a result.

I imported all my Evernote notes as HTML default, as preserving formatting is critical for some notes. I have been converting more casual notes I encounter into Markdown using the right click Convert To Markdown function on a note.

The problem is, if I go through and repair all my Evernote internal links to now point to their Joplin equivalents, but THEN later convert that linked to note from HTML to Markdown, the conversion process creates a whole new noteID for the resulting conversion instead of re-using the previous. What this means is that if I go to that fixed Joplin link and click on it, it will open the old HTML note now lying in the Trash (since after conversion the old note gets deleted)

It seems like the correct and proper thing to do here is to preserve the original noteID in the new converted note, so that previous Joplin links are not invalidated.
I would prefer this to be in core Joplin functionality, as it currently comes across as a bug. But in the meantime is there some way I could still manage to convert a note to markdown AND manually set its noteID using the plugin data api interface?

I've been investigating if there is a way to access the convertHtmlToMarkdown() command from a plugin, so I could create my own handler for the Convert To Markdown process to work around this problem until an official fix is done. Alas from what I can tell though this command is not public accessible through the plugin API.

I've looked more into the Joplin code for the conversion here and from what I can tell, the culprit is likely in const newNote = await Note.duplicate(note.id);, I haven't dug in further but I'm going to assume the duplicate() function assigns a brand new unique noteID to the duplicated note.

The newNote gets assigned all the updated properties from the old note, along with the converted body, but the noteID remains with the original note, which gets sent to the trash. I believe this could easily be worked around by assigning the unique noteID generated from duplicate() to the old note that goes into the trash, and assigning the old noteID to newNote. This way internal links to the note are correctly preserved.

However my ability to test this out is currently limited, I have pulled Joplin's source locally but I am still very unfamiliar with setting up the environment it requires (my experience is more with working in C# project solutions and game engines).

I'm going to go ahead and submit this as an official bug in GitHub since later today when I have a free moment.
Issue created: Converting HTML note to Markdown results in new noteID, which breaks any internal Joplin links to that original note · Issue #16252 · laurent22/joplin · GitHub