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

Simplify markdown parsing #27

Merged
merged 3 commits into from
Dec 1, 2023
Merged

Simplify markdown parsing #27

merged 3 commits into from
Dec 1, 2023

Conversation

Earlopain
Copy link
Contributor

While looking into the backtick issue I gave the code a lookover and suspected something with the regex logic being wrong.

I found the logic for that to be pretty hard to grasp/follow. I have refactored the code to hopefully be easier to understand.
Instead of going through the elements one by one in a loop and inquiring which step we are at, just use the match results from the regex.

The regex now matches everything which means we can branch on the match data and learn if we are in markdown or a codeblock, handling that as appropriate. The state is entirely contained within one iteration.

I benchmarked this and performance is on par with the current implementation.

Available since Ruby 2.3, min version of this gem is currently 2.6
Instead of using a walker, rely on the presence of regex matches.
@palkan
Copy link
Collaborator

palkan commented Dec 1, 2023

Thanks a lot!

@palkan palkan merged commit f94a787 into rubocop:master Dec 1, 2023
11 checks passed
@Earlopain Earlopain deleted the simplify-markdown-parsing branch December 1, 2023 12:44
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