From 5902fa5822d4ce2ce7c2169725806bf4520a96b0 Mon Sep 17 00:00:00 2001
From: official-techsupport
Date: Sun, 22 Jan 2023 23:27:24 +0000
Subject: [PATCH] showmore on too many newlines (works now) (#90)
At this point I think we should stop abusing regexes to implement the showmore logic.
I also reduced the character constant to 3000/2500 and increased the line constant to 20 but I don't have any strong feelings about them.
Co-authored-by: official-techsupport
Reviewed-on: https://fsdfsd.net/rDrama/rDrama/pulls/90
Co-authored-by: official-techsupport
Co-committed-by: official-techsupport
---
files/helpers/regex.py | 5 ++---
files/helpers/sanitize.py | 17 +++++++++++++----
2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/files/helpers/regex.py b/files/helpers/regex.py
index aaec0161c..0eee98294 100644
--- a/files/helpers/regex.py
+++ b/files/helpers/regex.py
@@ -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)
-# 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.
-# showmore_regex = re.compile(r"^((.{3000,}?|(.*?<.*?){10,})?<\/p>(?:<\/li><\/ul>)?)(\s*
' not in sanitized and not sidebar:
sanitized = sanitized.replace('\n','')
- # if showmore and len(sanitized) > 3500 or sanitized.count('<') > 15:
- # sanitized = showmore_regex.sub(r'\1\4', sanitized, count=1)
- if showmore and len(sanitized) > 3500:
- sanitized = showmore_regex.sub(r'\1\2', sanitized, count=1)
+ if showmore:
+ # Insert a show more button if the text is too long or has too many paragraphs
+ pos = 0
+ for _ in range(20):
+ pos = sanitized.find('