Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -354,10 +354,11 @@ def send_feedback_via_email(name, email, feedback):
|
|
| 354 |
def extract_name(email):
|
| 355 |
return email.split('@')[0].capitalize()
|
| 356 |
|
| 357 |
-
|
|
|
|
| 358 |
"""
|
| 359 |
Cleans and formats text to handle special characters, encode URLs,
|
| 360 |
-
|
| 361 |
"""
|
| 362 |
# Normalize newlines
|
| 363 |
text = text.replace('\\n', '\n')
|
|
@@ -380,13 +381,14 @@ def clean_text(text):
|
|
| 380 |
|
| 381 |
text = re.sub(source_link_pattern, add_markdown_link, text)
|
| 382 |
|
| 383 |
-
# Fix
|
| 384 |
-
text = re.sub(r'
|
| 385 |
-
text = re.sub(r'
|
| 386 |
-
text = re.sub(r'
|
| 387 |
|
| 388 |
-
#
|
| 389 |
-
|
|
|
|
| 390 |
|
| 391 |
# Remove extra spaces and normalize
|
| 392 |
text = re.sub(r'\s+', ' ', text).strip()
|
|
@@ -419,7 +421,6 @@ def clean_text(text):
|
|
| 419 |
|
| 420 |
return cleaned_text
|
| 421 |
|
| 422 |
-
|
| 423 |
|
| 424 |
|
| 425 |
|
|
|
|
| 354 |
def extract_name(email):
|
| 355 |
return email.split('@')[0].capitalize()
|
| 356 |
|
| 357 |
+
|
| 358 |
+
def clean_and_format_text(text):
|
| 359 |
"""
|
| 360 |
Cleans and formats text to handle special characters, encode URLs,
|
| 361 |
+
fix italic blocks, handle inline tags, and ensure proper Markdown formatting.
|
| 362 |
"""
|
| 363 |
# Normalize newlines
|
| 364 |
text = text.replace('\\n', '\n')
|
|
|
|
| 381 |
|
| 382 |
text = re.sub(source_link_pattern, add_markdown_link, text)
|
| 383 |
|
| 384 |
+
# Fix italic blocks and remove unnecessary tags
|
| 385 |
+
text = re.sub(r'<i>(.*?)</i>', r'_\1_', text) # Convert <i>...</i> to Markdown italic (_..._)
|
| 386 |
+
text = re.sub(r'<b>(.*?)</b>', r'**\1**', text) # Convert <b>...</b> to Markdown bold (**...**)
|
| 387 |
+
text = re.sub(r'</?(?:i|b|strong|em)>', '', text) # Remove stray tags
|
| 388 |
|
| 389 |
+
# Handle inline tags like "a", "c", "v" breaking into separate lines
|
| 390 |
+
inline_tag_pattern = r'\b(a|c|v)\b'
|
| 391 |
+
text = re.sub(inline_tag_pattern, r'\1', text) # Fix single-character inline tags
|
| 392 |
|
| 393 |
# Remove extra spaces and normalize
|
| 394 |
text = re.sub(r'\s+', ' ', text).strip()
|
|
|
|
| 421 |
|
| 422 |
return cleaned_text
|
| 423 |
|
|
|
|
| 424 |
|
| 425 |
|
| 426 |
|