diff --git a/app.py b/app.py
index c00af11..6a43da7 100644
--- a/app.py
+++ b/app.py
@@ -15,6 +15,7 @@ from flask_limiter.util import get_remote_address
import google.generativeai as genai
import requests
from dotenv import load_dotenv
+import markdown
# Load environment variables
load_dotenv()
@@ -111,54 +112,7 @@ def is_valid_pdf(pdf_path):
return False
def format_summary(summary):
- """Converts markdown-like text to HTML formatting, including nested lists (both ordered and unordered)."""
- summary = re.sub(r'\*\*(.*?)\*\*', r'\1', summary) # Bold text
- summary = re.sub(r'\*(?!\s)(.*?)\*', r'\1', summary) # Italic text (ignoring lists)
-
- lines = summary.split('\n')
- formatted_lines = []
- list_stack = [] # Track nesting levels and types
-
- for line in lines:
- unordered_match = re.match(r'^(\s*)\*\s(.+)', line) # Matches "* item"
- ordered_match = re.match(r'^(\s*)(\d+)\.\s(.+)', line) # Matches "1. item"
-
- if unordered_match or ordered_match:
- indent = unordered_match.group(1) if unordered_match else ordered_match.group(1)
- level = len(indent) // 4 # Assume 4 spaces per indent level
-
- list_type = '
' if unordered_match else ''
- list_tag = '- {}
'.format(unordered_match.group(2) if unordered_match else ordered_match.group(3))
-
- # Close lists if necessary
- while list_stack and len(list_stack) > level:
- formatted_lines.append('{}>'.format(list_stack.pop()))
-
- # Open new lists if necessary
- while len(list_stack) < level:
- formatted_lines.append(list_type)
- list_stack.append(list_type[1:3]) # Store 'ul' or 'ol'
-
- # Handle list type switching (unordered ↔ ordered)
- if list_stack and list_stack[-1] != list_type[1:3]:
- formatted_lines.append('{}>'.format(list_stack.pop()))
- formatted_lines.append(list_type)
- list_stack.append(list_type[1:3])
-
- formatted_lines.append(list_tag)
-
- else:
- # Close any open lists before adding non-list content
- while list_stack:
- formatted_lines.append('{}>'.format(list_stack.pop()))
-
- formatted_lines.append(line.replace("\n", "
"))
-
- # Close any remaining lists
- while list_stack:
- formatted_lines.append('{}>'.format(list_stack.pop()))
-
- return '\n'.join(formatted_lines)
+ return markdown.markdown(summary)
def resize_image(image, max_size=1080):
width, height = image.size
diff --git a/requirements.txt b/requirements.txt
index f490267..1be8e17 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -9,3 +9,4 @@ flask-limiter==3.10.1
google-generativeai==0.8.3
requests==2.31.0
python-dotenv==1.0.1
+markdown==3.7