Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions titlecase/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,14 @@ def titlecase(text, callback=None, small_first_last=True, preserve_blank_lines=F
continue

if APOS_SECOND.match(word):
# Everything past the second letter was shouted along with
# the rest of the line, so it needs the same downcasing the
# other branches below give their words before recapping.
rest = word[3:].lower() if all_caps else word[3:]
if len(word[0]) == 1 and word[0] not in 'aeiouAEIOU':
word = word[0].lower() + word[1] + word[2].upper() + word[3:]
word = word[0].lower() + word[1] + word[2].upper() + rest
else:
word = word[0].upper() + word[1] + word[2].upper() + word[3:]
word = word[0].upper() + word[1] + word[2].upper() + rest
tc_line.append(word)
continue

Expand Down
8 changes: 8 additions & 0 deletions titlecase/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@
"O'GranGe",
"O'GranGe",
),
(
"D'ARTAGNAN AND THE THREE MUSKETEERS",
"d'Artagnan and the Three Musketeers",
),
(
"O'BRIEN'S HOUSE IS FOR SALE",
"O'Brien's House Is for Sale",
),
(
"o'melveny/o'doyle o'Melveny/o'doyle O'melveny/o'doyle o'melveny/o'Doyle o'melveny/O'doyle",
"O'Melveny/O'Doyle O'Melveny/O'Doyle O'Melveny/O'Doyle O'Melveny/O'Doyle O'Melveny/O'Doyle",
Expand Down