fix an edge case in showmore (when many long paragraphs) (#93)

$subj

Co-authored-by: official-techsupport <official_techsupport@protonmail.com>
Reviewed-on: #93
Co-authored-by: official-techsupport <official-techsupport@noreply.fsdfsd.net>
Co-committed-by: official-techsupport <official-techsupport@noreply.fsdfsd.net>
pull/96/head
official-techsupport 2023-01-24 03:56:14 +00:00 committed by Aevann
parent c02c8312fa
commit 123cee6372
1 changed files with 3 additions and 2 deletions

View File

@ -428,13 +428,14 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=True, count_marseys
if showmore: if showmore:
# Insert a show more button if the text is too long or has too many paragraphs # Insert a show more button if the text is too long or has too many paragraphs
CHARLIMIT = 3000
pos = 0 pos = 0
for _ in range(20): for _ in range(20):
pos = sanitized.find('</p>', pos + 4) pos = sanitized.find('</p>', pos + 4)
if pos < 0: if pos < 0:
break break
if pos < 0 and len(sanitized) > 3000: if (pos < 0 and len(sanitized) > CHARLIMIT) or pos > CHARLIMIT:
pos = 2500 pos = CHARLIMIT - 500
if pos >= 0: if pos >= 0:
sanitized = (sanitized[:pos] + sanitized = (sanitized[:pos] +
showmore_regex.sub(r'\1<p><button class="showmore">SHOW MORE</button></p><d class="d-none">\2</d>', showmore_regex.sub(r'\1<p><button class="showmore">SHOW MORE</button></p><d class="d-none">\2</d>',