tommcfarlin / title-capitalization-for-wordpress

[WordPress] Properly capitalizes post titles and heading elements in the post content when saving and updating posts.
GNU General Public License v2.0
46 stars 7 forks source link

Sometimes first word of markdown header not title cased #25

Closed afragen closed 8 years ago

afragen commented 8 years ago

Because the title case script doesn't recognize markdown headers the first word of a header wasn't capitalized if it was one of the excluded words, ( a, the, on, and, etc)

See #24

tommcfarlin commented 8 years ago

When you mention "Sometimes..." can you give examples of when they are and when they aren't?

I want to try to reproduce it on my end, too.

afragen commented 8 years ago

If you have something like the following in your post body.

### the quick brown fox jumps over the lazy dog

after processing it will be

### the Quick Brown Fox Jumps Over the Lazy Dog

This is because the toTitleCase() strips the surrounding html tags, title cases the string and then adds the html tags back. The function is set to capitalize the first word of a sentence.

Without the modification to the regex looking for the html tags the first work looks like ### the instead of the. Consequently it's not capitalized.

This would occur only with markdown headers and only if the first word is one of those usually excluded for being capitalized.

tommcfarlin commented 8 years ago

Eventually, I want to create an interface that will allow us to plug in different rulesets for locales or capitalization types. The library I'm currently using is fair but obviously leaves something to be desired.

Since it's open source, I don't mind:

That's probably the first step to what I'd like to do with the interface in 2.0.0.

afragen commented 8 years ago

It's fairly good, efficient code but hasn't been updated in 6 years. I put in a couple of PRs back to it with my mods.

It may be more efficient to fork it and maintain it ourselves or just include it directly in the plugin. That way we can create whatever interface of filter hook into the regents.

I haven't looked to see if there's a multilingual title case repo.

afragen commented 8 years ago

So I refactored TitleCase a bit, removed the nested ternary functions and generally made it easier to read. It should still work and now be a little easier to extend. #28

afragen commented 8 years ago

Fixed in #28