improve the showmore algo

pull/134/head
Aevann 2023-02-24 03:24:50 +02:00
parent ec1b304d0d
commit 9529cbbd61
3 changed files with 8 additions and 4 deletions

View File

@ -260,7 +260,11 @@ function changename(s1,s2) {
}
function showmore(t) {
const div = t.parentElement.nextElementSibling
let div = t
while (!(div.id && div.id.startsWith('comment-text-'))){
div = div.parentElement
}
div = div.getElementsByTagName('d')[0]
div.classList.toggle('d-none')
if (div.classList.contains('d-none'))
t.innerHTML = 'SHOW MORE'

View File

@ -106,7 +106,7 @@ color_regex = re.compile("[a-f0-9]{6}", flags=re.A)
# lazy match on the .*?, only match if there is trailing stuff
# Specifically match Snappy's way of formatting, this might break some losers' comments.
showmore_regex = re.compile(r"^(.*?</p>(?:</li></ul>)?)(\s*<p>.*)", flags=re.A|re.DOTALL)
showmore_regex = re.compile(r"^(.*?<\/[a-z]+>(?:<\/li><\/ul>)?)(\s*<[a-z]+>.*)", flags=re.A|re.DOTALL)
search_token_regex = re.compile('"([^"]*)"|(\S+)', flags=re.A)

View File

@ -537,14 +537,14 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=True, count_marseys
CHARLIMIT = 3000
pos = 0
for _ in range(20):
pos = sanitized.find('</p>', pos + 4)
pos = sanitized.find('>', pos + 4)
if pos < 0:
break
if (pos < 0 and len(sanitized) > CHARLIMIT) or pos > CHARLIMIT:
pos = CHARLIMIT - 500
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>',
showmore_regex.sub(r'\1<p><button class="showmore">SHOW MORE</button></p></ul><d class="d-none">\2</d>',
sanitized[pos:], count=1))
return sanitized.strip()