add internal Typograph (Типограф Муравьева)

This commit is contained in:
e-serg
2022-12-16 23:47:26 +03:00
parent 0e2719afa7
commit 20ca688a35
3 changed files with 3239 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from cadpoint.settings import *
import re
def check_cookies(request) -> bool:
@@ -37,3 +38,16 @@ def safe_html_special_symbols(s: str) -> str:
result = result.replace('<br />', ' ')
result = result.replace('<br>', ' ')
return result
def post_processing_html(s: str) -> str:
s = re.sub(r"\s+", " ", s, flags=re.IGNORECASE)
s = re.sub(r">\s+|>&nbsp;", "> ", s, flags=re.IGNORECASE)
s = re.sub(r"\n|\r|<p[^>]*>\s*</p>|<p>&nbsp;</p>", "", s, flags=re.IGNORECASE)
s = re.sub(r"</p>\s*<br[^>]*>", "</p>", s, flags=re.IGNORECASE)
s = re.sub(r"<br[^>]*>\s*<p>|<p[^>]*>\s*<p[^>]*>", "<p>", s, flags=re.IGNORECASE)
s = re.sub(r"</p>\s*</p>", "</p>", s, flags=re.IGNORECASE)
s = re.sub(r"<br[^>]*>\s*<br[^>]*>", "<br />", s, flags=re.IGNORECASE)
s = re.sub(r"<p><blockquote>", "<blockquote>", s, flags=re.IGNORECASE)
s = re.sub(r"</blockquote></p>", "</blockquote>", s, flags=re.IGNORECASE)
return s