Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,9 @@ from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
|
|
| 7 |
from reportlab.lib.pagesizes import A4
|
| 8 |
from reportlab.lib.utils import ImageReader
|
| 9 |
from reportlab.pdfgen import canvas
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
load_dotenv()
|
| 12 |
api_token = os.environ.get("SYNAP")
|
|
@@ -448,13 +451,27 @@ Agora, seguindo rigorosamente TODAS as instruções acima, gere o desenvolviment
|
|
| 448 |
print("erro:", e)
|
| 449 |
print("Tentando novamente")
|
| 450 |
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
|
|
|
|
| 458 |
|
| 459 |
def save(self):
|
| 460 |
self.c.save()
|
|
|
|
| 7 |
from reportlab.lib.pagesizes import A4
|
| 8 |
from reportlab.lib.utils import ImageReader
|
| 9 |
from reportlab.pdfgen import canvas
|
| 10 |
+
import re
|
| 11 |
+
from html import escape
|
| 12 |
+
|
| 13 |
|
| 14 |
load_dotenv()
|
| 15 |
api_token = os.environ.get("SYNAP")
|
|
|
|
| 451 |
print("erro:", e)
|
| 452 |
print("Tentando novamente")
|
| 453 |
|
| 454 |
+
|
| 455 |
+
def limpar(self, texto: str) -> str:
|
| 456 |
+
if not texto:
|
| 457 |
+
return ""
|
| 458 |
+
|
| 459 |
+
# Escapa qualquer coisa perigosa primeiro
|
| 460 |
+
texto = escape(texto)
|
| 461 |
+
|
| 462 |
+
# Reverte apenas as tags PERMITIDAS pelo ReportLab
|
| 463 |
+
texto = texto.replace("<br/>", "<br/>")
|
| 464 |
+
texto = texto.replace("<br>", "<br/>")
|
| 465 |
+
texto = texto.replace("<strong>", "<strong>")
|
| 466 |
+
texto = texto.replace("</strong>", "</strong>")
|
| 467 |
+
|
| 468 |
+
# Normaliza <br>
|
| 469 |
+
texto = re.sub(r"<br\s*/?>", "<br/>", texto, flags=re.IGNORECASE)
|
| 470 |
+
|
| 471 |
+
# Remove excesso de quebras
|
| 472 |
+
texto = re.sub(r"(?:<br/>){3,}", "<br/><br/>", texto)
|
| 473 |
|
| 474 |
+
return texto.strip()
|
| 475 |
|
| 476 |
def save(self):
|
| 477 |
self.c.save()
|