Skip to content

Conversation

aaronjensen
Copy link

Prior to this, there was no newline between the text prior to the backlinks which caused it to not properly detect the backlink section.

This perhaps isn't the cleanest implementation, but it fixes things for me. It also gets rid of the extra newline at the end of files that was previously emitted.

Prior to this, there was no newline between the text prior to the backlinks
which caused it to not properly detect the backlink section.
@andymatuschak
Copy link
Owner

Thanks for submitting a pull request, Aaron. I don't really understand what you're trying to do here. Could you describe in more detail please?

@aaronjensen
Copy link
Author

aaronjensen commented Aug 31, 2020

Hi @andymatuschak,

Looks like I added another commit here, which I have removed.

But basically, I ran into an issue in my markdown files where note-link-janitor was not actually idempotent. It would not detect the backlink section on the second run, so it would actually treat it as content meaning it would consider links in the backlink section as backlinks, causing note-link-janitor to add recursive backlinks.

I tracked it down to the fact that when it adds the ## Backlinks section without an extra newline above it, causing it to hug the content of the section right above it. By adding an additional newline, ntoe-link-janitor would always properly detect the backlinks section.

The changes also normalize the newlines--they don't add an extra newline at the bottom of the file and it ensures that there's exactly 1 blank line above the backlinks section and 1 below (if there is anything below, 0 otherwise).

Here is a repro demonstrating the problematic behavior with the current version:

https://github.com/aaronjensen/note-link-janitor-idempotency-repro/commits/master

You can review the commits in reverse order to see what happens. The second run is the erroneous one.

If you run the version from this PR twice on the initial commit of that repo, it should not produce the recursive and redundant backlinks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants