Spaces:
Sleeping
Sleeping
Update app.py
Browse files6 unmodified lines789101112131415435 unmodified lines4514524534514524534544554564544554564574584594604614624634644654664674684694704714724734744754764776 unmodified linesfrom reportlab.lib.pagesizes import A4from reportlab.lib.utils import ImageReaderfrom reportlab.pdfgen import canvasimport refrom html import escape
load_dotenv()api_token = os.environ.get("SYNAP")435 unmodified lines print("erro:", e) print("Tentando novamente")
def limpar(self, texto): texto = texto.replace("<img>", "<img>") texto = texto.replace("<p>", "<p>").replace("</p>", "</p>") texto = texto.replace("<div>", "<div>").replace("</div>", "</div>") texto = texto.replace("<h1>", "<h1>").replace("</h1>", "</h1>") return texto def limpar(self, texto: str) -> str: if not texto: return ""
# Escapa qualquer coisa perigosa primeiro texto = escape(texto)
# Reverte apenas as tags PERMITIDAS pelo ReportLab texto = texto.replace("<br/>", "<br/>") texto = texto.replace("<br>", "<br/>") texto = texto.replace("<strong>", "<strong>") texto = texto.replace("</strong>", "</strong>")
# Normaliza <br> texto = re.sub(r"<br\s*/?>", "<br/>", texto, flags=re.IGNORECASE)
# Remove excesso de quebras texto = re.sub(r"(?:<br/>){3,}", "<br/><br/>", texto)
return texto.strip() def save(self): self.c.save() app.py+23-6