platers / obsidian-linter

An Obsidian plugin that formats and styles your notes with a focus on configurability and extensibility.
https://platers.github.io/obsidian-linter/
MIT License
1.19k stars 80 forks source link

Bug: First letter in Title Case not Uppercase when preceded with numbers or special characters #1148

Closed ekarious closed 1 month ago

ekarious commented 1 month ago

Describe the Bug

When having a title like this

135_  A letter arrived

It gets formatted as

135 - a Letter Arrived

If the letter is in the lowercase words, It will be lowercased even if first letter in the header.

How to Reproduce

Steps to reproduce the behavior:

  1. Make a title similar to mine as the first word is not a letter
  2. Set Capitalize Headings to Title Case
  3. Ignore Cased Words to false
  4. Lowercase Words should have a inside for this example.
  5. Format the file
  6. See error in the first heading

Resources

data.json logs.txt

Expected Behavior

As the linter run, the header

135_  A letter arrived

should have been

135 - A letter arrived

Device

Additional Context

As additional context, take note that I am currently using a regex to modify the header to change _ -> - as: ^# (\d+)_ (.+)\n gm # $1 - $2\n As I am not an expert in regexes, maybe this can contribute to the bug.

ekarious commented 1 month ago

I know another issue was filed and fixed for this in 2022. But I still have the bug in my vault.

pjkaufman commented 1 month ago

Hey @ekarious , thanks for reporting this. This seems like the regex for finding valid words is likely hitting an issue where it is matching all digits. I do need to verify this though.

pjkaufman commented 1 month ago

Ok. I took a look and it looks like the issue is because it is not properly filtering out some single letter situations. It looks like if - or ' are by themselves with whitespace around them in the header before any letter, it gets considered to be the first "letter". This should not be too hard to fix (fingers crossed).

Thanks for bring this to our attention.

pjkaufman commented 1 month ago

I believe I have a fixed that is now merged into master and should go out with the next release. Please let us know if there is an issue with either.

ekarious commented 1 month ago

Thank you a lot ! :)