Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: full link path replacement applied section by section rather than full file #17

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

HyperEpsilon
Copy link

This fixes an error that occurs if a wikilink appears both in the frontmatter and in the main body of a note.

Previous implementation had the regex search the body of the text, but apply the replacement to the entire note. If there existed a [[wikilink]] in the frontmatter that was formatted exactly the same as a [[wikilink]] in the main body, then the link in the frontmatter would be the one replaced when regex.replace() was called.

My solution is as follows:

  1. Using regex.exec find the borders of all sections which have to be skipped (frontmatter, code fences, code blocks, excalidraw)
  2. Break the text into an array of skippable sections and all other text
  3. Apply the wikilink replacement individually to each section not skipped

This could potentially be refactored to do the conversion while splitting, but I did it this way to take advantage of asynchronous map

Splitting the note into sections and applying the link replacement regex section by section avoids an issue where a file link appears both in the frontmatter (or some other skipped section) and in the note body. The old method would replace the link within the frontmatter, causing quartz to break with invalid characters.
@HyperEpsilon
Copy link
Author

Now that I think about it, maybe I should condense this down for readability.

The promises could be added to the array, then call await promise.all after the regex has finished splitting

@HyperEpsilon
Copy link
Author

Okay, should be good at this point

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.

1 participant