Skip to content

Commit

Permalink
Allow non-breaking spaces to tie together title blocks in draft creation
Browse files Browse the repository at this point in the history
For example, this allows “Mrs. Seacole” to be entered as “Mrs. Seacole” to be kept on the same line during title generation.
  • Loading branch information
robinwhittleton authored and acabal committed Dec 26, 2023
1 parent 9462d7a commit 1d71187
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion se/commands/create_draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def _get_word_widths(string: str, target_height: int) -> list:
"""

words = []
for word in reversed(string.split()):
# Forcing a split on " " means that we can use non-breaking spaces to tie together blocks (e.g. Mrs. Seacole)
for word in reversed(string.strip().split(" ")):
width = 0

for char in word:
Expand Down
8 changes: 6 additions & 2 deletions se/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1128,8 +1128,8 @@ def titlecase(text: str) -> str:
# So, convert to all lowercase first.
text = text.lower()

# Replace all white space except hair space with a space character
text = regex.sub(fr"[^\S{se.HAIR_SPACE}]+", " ", text)
# Replace all white space except hair spaces and non-breaking spaces with a space character
text = regex.sub(fr"[^\S{se.HAIR_SPACE}{se.NO_BREAK_SPACE}]+", " ", text)

text = pip_titlecase(text)

Expand Down Expand Up @@ -1259,6 +1259,10 @@ def titlecase(text: str) -> str:
# Like `Will-o’-the-Wisp`
text = regex.sub(r"(?<=-)(O’|The)-", lambda result: result.group(1).lower() + "-", text)

# Fix non-breaking spaces - we can assume that they’re intentionally used in names
# If `titlecase` is fixed we can remove this, see https://github.com/ppannuto/python-titlecase/issues/95
text = regex.sub(fr"{se.NO_BREAK_SPACE}([a-z])", lambda result: " " + result.group(1).upper(), text)

return text

def make_url_safe(text: str) -> str:
Expand Down

0 comments on commit 1d71187

Please sign in to comment.