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

Adjust regex so that it does not strip links inadvertently #232

Merged
merged 2 commits into from
Mar 9, 2024

Conversation

pcraig3
Copy link
Contributor

@pcraig3 pcraig3 commented Feb 21, 2024

The issue with the current implementation seems to stem from the regex pattern mistakenly capturing and modifying links that should be left untouched, especially when they contain colons (:) or semicolons (;) that are part of a normal URL or anchor reference (#).

This was leading to issues where text would be lost where a paragraph would contain more than one link and a semi-colon.

eg:

  • for this input:
    • Citation 4. [footnote 4](#ftnt4) Citation 5. [footnote 5](#ftnt5) Citation 6; [footnote 6](#ftnt6)
  • we were getting this output:
    • <p>Citation 4. <a href="#ftnt4">footnote 4</a> Citation 5. <a href=";">footnote 5</a></p>
  • when what we wanted was this:
    • <p>Citation 4. <a href="#ftnt4">footnote 4</a> Citation 5. <a href="#ftnt5">footnote 5</a> Citation 6; <a href="#ftnt6">footnote 6</a></p>

This PR fixes this so that regular links are preserved, but keeps in place the logic stripping bad protocols.

Closes this issue:

The issue with the current implementation seems to stem from the
regex pattern mistakenly capturing and modifying links that should
be left untouched, especially when they contain colons (:) or
semicolons (;) that are part of a normal URL or anchor reference (#).

This was leading to issues where text would be lost where a paragraph
would contain more than one link and a semi-colon.

eg:

- for this input:
  - Citation 4. [footnote 4](#ftnt4) Citation 5. [footnote 5](#ftnt5) Citation 6; [footnote 6](#ftnt6)
- we were getting this output:
  - <p>Citation 4. <a href="#ftnt4">footnote 4</a> Citation 5. <a href=";">footnote 5</a></p>
- when what we wanted was this:
  - <p>Citation 4. <a href="#ftnt4">footnote 4</a> Citation 5. <a href="#ftnt5">footnote 5</a> Citation 6; <a href="#ftnt6">footnote 6</a></p>

This PR fixes this so that regular links are preserved, but keeps in
place the logic stripping bad protocols.

Closes this issue:
- agusmakmun#229
@agusmakmun agusmakmun merged commit ca11c4e into agusmakmun:master Mar 9, 2024
13 checks passed
@agusmakmun
Copy link
Owner

Hello @pcraig3, thank you so much for making this changes. 🙌

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.

None yet

2 participants