Revert "improve the showmore algo"

This reverts commit 9529cbbd61.
pull/134/head
Aevann 2023-02-24 09:29:46 +02:00
parent 6fcc525772
commit ae26306846
3 changed files with 6 additions and 16 deletions

View File

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

View File

@ -108,7 +108,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"^(.*?<\/[a-z]+>(?:<\/li><\/ul>)?)(\s*<[a-z]+>.*)", flags=re.A|re.DOTALL)
showmore_regex = re.compile(r"^(.*?</p>(?:</li></ul>)?)(\s*<p>.*)", flags=re.A|re.DOTALL)
search_token_regex = re.compile('"([^"]*)"|(\S+)', flags=re.A)

View File

@ -543,14 +543,14 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=True, count_marseys
CHARLIMIT = 3000
pos = 0
for _ in range(20):
pos = sanitized.find('>', pos + 4)
pos = sanitized.find('</p>', 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></ul><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>',
sanitized[pos:], count=1))
return sanitized.strip()