MonScoDocEssai/app/scodoc/safehtml.py

14 lines
352 B
Python
Raw Normal View History

2020-09-26 16:19:37 +02:00
from stripogram import html2text, html2safehtml
# permet de conserver quelques tags html
def HTML2SafeHTML(text, convert_br=True):
text = html2safehtml(text, valid_tags=("b", "a", "i", "br", "p"))
if convert_br:
return newline_to_br(text)
else:
return text
def newline_to_br(text):
return text.replace("\n", "<br/>")