Closed jgillich closed 2 years ago
Thanks for submitting this, and I'm sorry for the super slow reply 😬
It appears to get mangled because you have multiple links on the same line. This is of course something I would like to support, so I will try to fix it when I have time :-)
I've added an initial failing unit test here with a smaller example: https://github.com/mathiassoeholm/markdown-link-updater/pull/17/files
I think I just figured out why this is happening: https://github.com/mathiassoeholm/markdown-link-updater/blob/main/src/pure-get-edits.ts#L146
The ranges are generated before editing, but once you replace a link, the positions of all other links on the same line change (and that isn't being accounted for). That's why it gets worse and worse for each link
If you're busy just let me know and I'll submit a fix
You're absolutely right :-)
All edits are generated by the pureGetEdits
function and are only applied afterward. This is also what makes the code easy to test, because pureGetEdits
has no side effects, but only returns information about what needs to be done.
If edits occur on the same line, they should account for the edit that comes before it.
Feel free to submit a fix, that can make this test pass: https://github.com/mathiassoeholm/markdown-link-updater/pull/17/files (assuming I used the correct range value on line 668 🤞).
If it's too much trouble, I can give it a go within the next two weeks :-)
Sample file from this repo
Moving that file to a sub-directory mangles the links
Haven't been able to figure out why but perhaps you have an idea.