showmore on too many newlines (works now) #90
|
@ -105,10 +105,9 @@ reddit_domain_regex = re.compile("(^|\s|\()https?:\/\/(reddit\.com|(?:(?:[A-z]{2
|
||||||
|
|
||||||
color_regex = re.compile("[a-f0-9]{6}", flags=re.A)
|
color_regex = re.compile("[a-f0-9]{6}", flags=re.A)
|
||||||
|
|
||||||
# lazy match on the {}?, only match if there is trailing stuff
|
# lazy match on the .*?, only match if there is trailing stuff
|
||||||
# Specifically match Snappy's way of formatting, this might break some losers' comments.
|
# Specifically match Snappy's way of formatting, this might break some losers' comments.
|
||||||
# showmore_regex = re.compile(r"^((.{3000,}?|(.*?<.*?){10,})?<\/p>(?:<\/li><\/ul>)?)(\s*<p>.*)", flags=re.A|re.DOTALL)
|
showmore_regex = re.compile(r"^(.*?</p>(?:</li></ul>)?)(\s*<p>.*)", flags=re.A|re.DOTALL)
|
||||||
showmore_regex = re.compile(r"^(.{3000,}?</p>(?:</li></ul>)?)(\s*<p>.*)", flags=re.A|re.DOTALL)
|
|
||||||
|
|
||||||
search_token_regex = re.compile('"([^"]*)"|(\S+)', flags=re.A)
|
search_token_regex = re.compile('"([^"]*)"|(\S+)', flags=re.A)
|
||||||
|
|
||||||
|
|
|
@ -410,10 +410,19 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=True, count_marseys
|
||||||
if '<pre>' not in sanitized and not sidebar:
|
if '<pre>' not in sanitized and not sidebar:
|
||||||
sanitized = sanitized.replace('\n','')
|
sanitized = sanitized.replace('\n','')
|
||||||
|
|
||||||
# if showmore and len(sanitized) > 3500 or sanitized.count('<') > 15:
|
if showmore:
|
||||||
# sanitized = showmore_regex.sub(r'\1<p><button class="showmore">SHOW MORE</button></p><d class="d-none">\4</d>', sanitized, count=1)
|
# Insert a show more button if the text is too long or has too many paragraphs
|
||||||
if showmore and len(sanitized) > 3500:
|
pos = 0
|
||||||
sanitized = showmore_regex.sub(r'\1<p><button class="showmore">SHOW MORE</button></p><d class="d-none">\2</d>', sanitized, count=1)
|
for _ in range(20):
|
||||||
|
pos = sanitized.find('</p>', pos + 4)
|
||||||
|
if pos < 0:
|
||||||
|
break
|
||||||
|
if pos < 0 and len(sanitized) > 3000:
|
||||||
|
pos = 2500
|
||||||
|
if pos >= 0:
|
||||||
|
sanitized = (sanitized[:pos] +
|
||||||
|
showmore_regex.sub(r'\1<p><button class="showmore">SHOW MORE</button></p><d class="d-none">\2</d>',
|
||||||
|
sanitized[pos:], count=1))
|
||||||
|
|
||||||
return sanitized.strip()
|
return sanitized.strip()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue