Community
    • Login

    Looking for Title Case

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 3 Posters 435 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Daniel CombsD
      Daniel Combs
      last edited by

      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?

      Mark OlsonM 1 Reply Last reply Reply Quote 0
      • Mark OlsonM
        Mark Olson @Daniel Combs
        last edited by Mark Olson

        @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.

        1 Reply Last reply Reply Quote 3
        • Mark OlsonM Mark Olson referenced this topic on
        • guy038G
          guy038
          last edited by

          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

          1 Reply Last reply Reply Quote 3
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors