Looking for Title Case
-
Edit->Convert Case to->Title Case does not exist.
Edit->Convert Case to->Proper Case capitalizes the first letter in every word (all other letters are lowercase). Title case would set all letters to lowercase and capitalize the first letter in all words that are not articles, conjunctions, or prepositions (with the exception of the first word of the title).
Is there a plugin that will help?
-
@Daniel-Combs
Probably the reason that this functionality is not in Notepad++ is that there are too many weird arbitrary rules, and different people will have different opinions about what constitutes proper “Title case”.That said, here’s a PythonScript script that will do approximately what you’re looking for:
''' ====== SOURCE ====== Requires PythonScript (https://github.com/bruderstein/PythonScript/releases) Based on this question: https://community.notepad-plus-plus.org/topic/26037/looking-for-title-case ====== DESCRIPTION ====== Converts a document to title case, according to the following rules: Let a "word" be any sequence of ASCII letters (a-z or A-Z) in the current document. if any word is in WORDS_TO_LEAVE_LOWERCASE and is NOT at the start of a line: represent the word as all lowercase otherwise: capitalize the word (the first letter is uppercase, and subsequent letters are lowercase) ====== EXAMPLE ====== Suppose you start with the document below, and WORDS_TO_LEAVE_LOWERCASE = {"a","an","and","as","at","but","by","for","if","in","nor","of","off","on","or","per","so","the","to","up","via","yet"} =========== foo is BAR, not thE DOG who wouldn't and could've done bAz the big man is very cool so many titles, so little time Words like b99 and Dog17bLAh are not affected, because they contain numbers =========== You will end with =========== Foo Is Bar, Not the Dog Who Wouldn't and Could've Done Baz The Big Man Is Very Cool So Many Titles, so Little Time Words Like b99 and Dog17bLAh Are Not Affected, Because They Contain Numbers =========== ''' from Npp import editor # edit this list to customize which words you want to leave lowercase WORDS_TO_LEAVE_LOWERCASE = {"a","an","and","as","at","but","by","for","if","in","nor","of","off","on","or","per","so","the","to","up","via","yet"} def replace_func(m): word = m.group(2).lower() space_char = m.group(1) is_line_start = space_char and space_char in '\r\n' if word in WORDS_TO_LEAVE_LOWERCASE and not is_line_start: return word return word.capitalize() editor.rereplace(r'(?i)(?:(?<=(\s))|\A)([a-z]+)\b', replace_func)There is probably some kind of way to do this using pure Notepad++ regular expressions, but every regex I came up with was a monstrosity and also kept failing for reasons I couldn’t understand.
-
M Mark Olson referenced this topic on
-
Hello, @daniel-combs, @mark-olson and All,
@daniel-combs, have also a look to this old post, below :
https://notepad-plus-plus.org/community/topic/130/convert-case-to/4
Best Regards,
guy038
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login