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

Merged
Aevann merged 1 commits from :master into master 2023-01-24 03:56:14 +00:00
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>',