mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
Handle extraneous html/text when generating titles for microblog content
This commit is contained in:
parent
843e9d060a
commit
424f8e004f
1 changed files with 4 additions and 3 deletions
|
@ -250,9 +250,10 @@ def microblog_content_to_title(html: str) -> str:
|
|||
|
||||
title = ''
|
||||
for tag in soup.find_all('p'):
|
||||
title = tag.get_text()
|
||||
title = tag.get_text(separator=" ")
|
||||
break
|
||||
else:
|
||||
html = html.replace('<', '.', 1)
|
||||
title = shorten_string(html, 160)
|
||||
|
||||
period_index = title.find('.')
|
||||
|
@ -270,9 +271,9 @@ def microblog_content_to_title(html: str) -> str:
|
|||
return title
|
||||
|
||||
if end_index != -1:
|
||||
if question_index != -1:
|
||||
if question_index != -1 and question_index == end_index:
|
||||
end_index += 1 # Add the ? back on
|
||||
if exclamation_index != -1:
|
||||
if exclamation_index != -1 and exclamation_index == end_index:
|
||||
end_index += 1 # Add the ! back on
|
||||
title = title[:end_index]
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue