From 5005e55ca488dcd50011eefe0aba8cc5d7caa1ae Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 23 Sep 2021 00:27:08 +0200 Subject: [PATCH] fds --- files/routes/comments.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/files/routes/comments.py b/files/routes/comments.py index 3f2dacc85c..b3bbaee120 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -157,7 +157,7 @@ def api_comment(v): for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', body, re.MULTILINE): if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})') - body = body.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n") + body = re.sub('([^\n])\n([^\n])', r'\1\n\n\2', body) body_md = CustomRenderer().render(mistletoe.Document(body)) body_html = sanitize(body_md) @@ -280,7 +280,7 @@ def api_comment(v): url = upload_ibb(file=file) body = request.values.get("body") + f"\n![]({url})" - body = body.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n") + body = re.sub('([^\n])\n([^\n])', r'\1\n\n\2', body) body_md = CustomRenderer().render(mistletoe.Document(body)) body_html = sanitize(body_md) @@ -418,7 +418,7 @@ def api_comment(v): g.db.flush() body = random.choice(LONGPOST_REPLIES) - body = body.replace("\n", "\n\n").replace("\n\n\n\n\n\n", "\n\n").replace("\n\n\n\n", "\n\n").replace("\n\n\n", "\n\n") + body = re.sub('([^\n])\n([^\n])', r'\1\n\n\2', body) body_md = CustomRenderer().render(mistletoe.Document(body)) body_html2 = sanitize(body_md) c_aux = CommentAux( @@ -610,6 +610,7 @@ def edit_comment(cid, v): body = request.values.get("body", "")[:10000] for i in re.finditer('^(https:\/\/.*\.(png|jpg|jpeg|gif|webp|PNG|JPG|JPEG|GIF|WEBP|9999))', body, re.MULTILINE): if "wikipedia" not in i.group(1): body = body.replace(i.group(1), f'![]({i.group(1)})') + body = re.sub('([^\n])\n([^\n])', r'\1\n\n\2', body) body_md = CustomRenderer().render(mistletoe.Document(body)) body_html = sanitize(body_md)