add internal Typograph (Типограф Муравьева)
This commit is contained in:
3199
cadpoint/web/EMT.py
Normal file
3199
cadpoint/web/EMT.py
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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+|> ", "> ", s, flags=re.IGNORECASE)
|
||||
s = re.sub(r"\n|\r|<p[^>]*>\s*</p>|<p> </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
|
||||
|
||||
@@ -6,10 +6,9 @@ from filer.fields.image import FilerFileField
|
||||
from ckeditor.fields import RichTextField
|
||||
from taggit.managers import TaggableManager
|
||||
from taggit.models import Tag, TaggedItem
|
||||
|
||||
import web.models
|
||||
from web.add_function import safe_html_special_symbols
|
||||
from web.add_function import safe_html_special_symbols, post_processing_html
|
||||
import urllib3
|
||||
import re
|
||||
import pytils
|
||||
import random
|
||||
import datetime
|
||||
@@ -220,8 +219,30 @@ class TbContent(models.Model):
|
||||
' <link target="_blank" />'
|
||||
'</preferences>'.encode('cp1251')})
|
||||
self.szContentBody = resp.data.decode('cp1251')
|
||||
self.bTypograf = False
|
||||
except:
|
||||
# если API типографа не доступен, то подключаем локальный типограф Муравьева
|
||||
import web.EMT as EMT
|
||||
emt_header = EMT.EMTypograph()
|
||||
emt_header.setup({'Text.paragraphs': 'off'})
|
||||
emt_header.set_text(self.szContentHead)
|
||||
self.szContentHead = emt_header.apply()
|
||||
emt_intro = EMT.EMTypograph()
|
||||
print("==================================== self.szContentBody\n", self.szContentIntro)
|
||||
print("-----------------")
|
||||
emt_intro.set_text(self.szContentIntro)
|
||||
# emt_intro.set_tag_layout(layout=EMT.LAYOUT_CLASS)
|
||||
self.szContentIntro = emt_intro.apply()
|
||||
self.szContentIntro = post_processing_html(self.szContentIntro)
|
||||
print(self.szContentIntro)
|
||||
emt_body = EMT.EMTypograph()
|
||||
print("==================================== self.szContentBody")
|
||||
print(self.szContentBody)
|
||||
print("-----------------")
|
||||
emt_body.set_text(self.szContentBody)
|
||||
# emt_body.set_tag_layout(layout=EMT.LAYOUT_CLASS)
|
||||
self.szContentBody = emt_body.apply()
|
||||
self.szContentBody = post_processing_html(self.szContentBody)
|
||||
print(self.szContentBody)
|
||||
self.bTypograf = False
|
||||
|
||||
super(TbContent, self).save(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user