Spaces:
Sleeping
Sleeping
Commit
·
c03c193
1
Parent(s):
e2c15c5
Correções no novo método de conversão dos textos para .md
Browse files
app.py
CHANGED
|
@@ -36,11 +36,18 @@ app.config['MAX_CONTENT_LENGTH'] = 100 * 1024 * 1024
|
|
| 36 |
md = MarkdownIt()
|
| 37 |
|
| 38 |
def is_html_empty(html: str) -> bool:
|
| 39 |
-
"""
|
|
|
|
|
|
|
|
|
|
| 40 |
if not html:
|
| 41 |
return True
|
|
|
|
| 42 |
text_only = re.sub('<[^<]+?>', '', html)
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
@app.route('/')
|
| 46 |
def index():
|
|
|
|
| 36 |
md = MarkdownIt()
|
| 37 |
|
| 38 |
def is_html_empty(html: str) -> bool:
|
| 39 |
+
"""
|
| 40 |
+
Verifica de forma robusta se uma string HTML não contém texto visível,
|
| 41 |
+
lidando com entidades HTML.
|
| 42 |
+
"""
|
| 43 |
if not html:
|
| 44 |
return True
|
| 45 |
+
# 1. Remove todas as tags HTML
|
| 46 |
text_only = re.sub('<[^<]+?>', '', html)
|
| 47 |
+
# 2. Decodifica entidades HTML (ex: para ' ')
|
| 48 |
+
decoded_text = unescape(text_only)
|
| 49 |
+
# 3. Verifica se o texto restante está de fato vazio
|
| 50 |
+
return not decoded_text.strip()
|
| 51 |
|
| 52 |
@app.route('/')
|
| 53 |
def index():
|