refactor: remove ellipsis from all text truncation paths
- truncate_text_safely: slice to full max_length, drop trailing ... - truncate_text_preserving_tail: remove ... prefix/infix, adjust reserve from +4 to +1 - build_dynamic_alt: slice to DYNAMIC_ALT_MAX_LENGTH, drop ... - make_rich: remove … from hashtag rstrip chars - sync_feeds: remove conditional ... suffix in dry-run log
This commit is contained in:
@@ -1162,19 +1162,16 @@ def find_tail_preservation_start(text, primary_non_x_url):
|
||||
|
||||
return url_pos
|
||||
|
||||
|
||||
def truncate_text_safely(text, max_length=BSKY_TEXT_MAX_LENGTH):
|
||||
if grapheme_len(text) <= max_length:
|
||||
return text
|
||||
|
||||
# Truncate by grapheme clusters
|
||||
clusters = list(grapheme.graphemes(text))
|
||||
truncated = "".join(clusters[: max_length - 3])
|
||||
truncated = "".join(clusters[:max_length])
|
||||
last_space = truncated.rfind(" ")
|
||||
if last_space > TRUNCATE_MIN_PREFIX_CHARS:
|
||||
return truncated[:last_space] + "..."
|
||||
return truncated + "..."
|
||||
|
||||
return truncated[:last_space]
|
||||
return truncated
|
||||
def truncate_text_preserving_tail(text, tail_start, max_length=BSKY_TEXT_MAX_LENGTH):
|
||||
if (
|
||||
not text
|
||||
@@ -1191,13 +1188,13 @@ def truncate_text_preserving_tail(text, tail_start, max_length=BSKY_TEXT_MAX_LEN
|
||||
if not tail:
|
||||
return truncate_text_safely(text, max_length)
|
||||
|
||||
reserve = len(tail) + 4
|
||||
reserve = len(tail) + 1
|
||||
if reserve >= max_length:
|
||||
shortened_tail = tail[-(max_length - 3) :].strip()
|
||||
shortened_tail = tail[-max_length:].strip()
|
||||
first_space = shortened_tail.find(" ")
|
||||
if 0 <= first_space <= 30:
|
||||
shortened_tail = shortened_tail[first_space + 1 :].strip()
|
||||
return f"...{shortened_tail}"
|
||||
shortened_tail = shortened_tail[first_space + 1:].strip()
|
||||
return shortened_tail
|
||||
|
||||
available_prefix = max_length - reserve
|
||||
prefix = text[:tail_start].rstrip()
|
||||
@@ -1208,7 +1205,7 @@ def truncate_text_preserving_tail(text, tail_start, max_length=BSKY_TEXT_MAX_LEN
|
||||
if last_space > 20:
|
||||
prefix = prefix[:last_space].rstrip()
|
||||
|
||||
final_text = f"{prefix}... {tail}".strip()
|
||||
final_text = f"{prefix} {tail}".strip()
|
||||
final_text = re.sub(r"[ \t]+", " ", final_text)
|
||||
final_text = re.sub(r"\n{3,}", "\n\n", final_text).strip()
|
||||
|
||||
@@ -1217,7 +1214,6 @@ def truncate_text_preserving_tail(text, tail_start, max_length=BSKY_TEXT_MAX_LEN
|
||||
|
||||
return truncate_text_safely(text, max_length)
|
||||
|
||||
|
||||
def choose_final_visible_text(
|
||||
full_clean_text, primary_non_x_url=None, prefer_full_text_without_url=True
|
||||
):
|
||||
@@ -2291,7 +2287,7 @@ def make_rich(content):
|
||||
text_builder.text(word)
|
||||
|
||||
elif cleaned_word.startswith("#") and len(cleaned_word) > 1:
|
||||
clean_tag = cleaned_word[1:].rstrip(".,;:!?)'\"…")
|
||||
clean_tag = cleaned_word[1:].rstrip(".,;:!?)'\"")
|
||||
if clean_tag:
|
||||
text_builder.tag(cleaned_word, clean_tag)
|
||||
trailing = word[len(cleaned_word):]
|
||||
@@ -2323,7 +2319,7 @@ def build_dynamic_alt(raw_text, link_title=None):
|
||||
dynamic_alt = link_title.strip()
|
||||
|
||||
if len(dynamic_alt) > DYNAMIC_ALT_MAX_LENGTH:
|
||||
dynamic_alt = dynamic_alt[:DYNAMIC_ALT_MAX_LENGTH - 3] + "..."
|
||||
dynamic_alt = dynamic_alt[:DYNAMIC_ALT_MAX_LENGTH]
|
||||
elif not dynamic_alt:
|
||||
dynamic_alt = "Attached video or image from tweet"
|
||||
|
||||
@@ -3237,7 +3233,6 @@ def sync_feeds(args):
|
||||
if dry_run:
|
||||
logging.info(
|
||||
f" 📄 Text: {raw_text[:200]}"
|
||||
f"{'...' if len(raw_text) > 200 else ''}"
|
||||
)
|
||||
logging.info(
|
||||
f" 🔗 Primary external URL: "
|
||||
|
||||
Reference in New Issue
Block a user