Skip to content

fix: prevent snake_case corruption#58

Merged
nicholasjpaterno merged 1 commit into
Epistates:mainfrom
alisaifee:fix-snake-case-corruption
Jun 5, 2026
Merged

fix: prevent snake_case corruption#58
nicholasjpaterno merged 1 commit into
Epistates:mainfrom
alisaifee:fix-snake-case-corruption

Conversation

@alisaifee

Copy link
Copy Markdown
Contributor

Problem

Instances of simple snake cased terms like a_b, i_am_a_snake were showing up corrupted because they were being mistaken for subscripts.

Sample document

- x^2
- x_2
- x_to_power_of_two
- x_subscript_two

Solution

Split the regex into two branches:

  • _{x} with braces always converts
  • _x without braces only converts when not followed by a letter or underscore

NOTE technically this problem might also exist for super script, but in normal markdown I can't think of an example where this would happen.

Demo

Before After

Instances of simple snake cased terms like a_b, i_am_a_snake were
showing up corrupted because they were being mistaken for subscripts.
@alisaifee alisaifee marked this pull request as ready for review June 3, 2026 00:57
@nicholasjpaterno

Copy link
Copy Markdown
Contributor

Thanks for the fix, @alisaifee! The two-branch regex approach is the right call and the added tests cover the real cases well. Merging.

@nicholasjpaterno nicholasjpaterno merged commit 4e4719e into Epistates:main Jun 5, 2026
1 check passed
@alisaifee

Copy link
Copy Markdown
Contributor Author

Thanks for the fix, @alisaifee! The two-branch regex approach is the right call and the added tests cover the real cases well. Merging.

Thank you for the quick turn around! I'm really enjoying using your project - and for whatever reason there is a lot of snake case in the markdown docs I work with so very quickly hit that issue. I was surprised that I managed to find and fix the issue but I think that's a testament to the quality of your code base - bravo!

@nicholasjpaterno

Copy link
Copy Markdown
Contributor

@alisaifee I'm really glad to hear that you're enjoying treemd and I appreciate your PR! It helps to polish the experience for everyone! PRs and feature requests are always welcome!

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