Update app.py
Browse files
app.py
CHANGED
@@ -457,15 +457,15 @@ def process_body(text, title):
|
|
457 |
|
458 |
# Create an image preview card
|
459 |
preview_html = f"""
|
460 |
-
<div class="image-preview" style="margin: 10px 0; padding: 10px; background:
|
461 |
<div style="display: flex; align-items: center; margin-bottom: 8px;">
|
462 |
<span style="font-size: 20px; margin-right: 8px;">🖼️</span>
|
463 |
-
<span style="color: #
|
464 |
-
|
465 |
-
|
466 |
-
style="color: #
|
467 |
-
|
468 |
-
|
469 |
|
470 |
new_soup = BeautifulSoup(preview_html, 'html.parser')
|
471 |
img.replace_with(new_soup)
|
@@ -478,24 +478,24 @@ def process_body(text, title):
|
|
478 |
link['href'] = fix_stack_exchange_url(href)
|
479 |
link['target'] = '_blank'
|
480 |
link['rel'] = 'noopener noreferrer'
|
481 |
-
link['style'] = 'color: #
|
482 |
|
483 |
# Add paragraph styling
|
484 |
for p in soup.find_all(['p', 'div']):
|
485 |
if not any(cls in (p.get('class', []) or []) for cls in ['image-preview', 'question-card']):
|
486 |
current_style = p.get('style', '')
|
487 |
-
p['style'] = f"{current_style}; margin: 0.8em 0; line-height: 1.6; color: #
|
488 |
|
489 |
# Add list styling
|
490 |
for ul in soup.find_all(['ul', 'ol']):
|
491 |
-
ul['style'] = 'margin: 0.8em 0; padding-left: 1.5em; color: #
|
492 |
|
493 |
for li in soup.find_all('li'):
|
494 |
-
li['style'] = 'margin: 0.4em 0; line-height: 1.6; color: #
|
495 |
|
496 |
# Add code block styling
|
497 |
for code in soup.find_all(['code', 'pre']):
|
498 |
-
code['style'] = 'background:
|
499 |
|
500 |
return str(soup)
|
501 |
|
@@ -525,7 +525,7 @@ def format_question(q: Dict) -> str:
|
|
525 |
<div class="question-meta" style="font-size: 0.9em; margin-bottom: 15px;">
|
526 |
<span style="color: #219ebc; font-weight: 500;">{author}</span>
|
527 |
{' asked' if source == 'stack_exchange' else ' posted'} on
|
528 |
-
<span style="color: #
|
529 |
<div class="stats" style="margin-top: 5px;">
|
530 |
<span title="Upvotes"><span style="color: #219ebc;">▲</span> {upvotes}</span>
|
531 |
<span style="margin-left: 15px;" title="Comments"><span style="color: #219ebc;">💬</span> {num_comments}</span>
|
@@ -538,7 +538,7 @@ def format_question(q: Dict) -> str:
|
|
538 |
body = q.get('body', '')
|
539 |
if body:
|
540 |
content_html = f"""
|
541 |
-
<div class="question-content" style="margin-top: 20px; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; color: #
|
542 |
{process_body(body, title)}
|
543 |
</div>
|
544 |
"""
|
@@ -550,8 +550,8 @@ def format_question(q: Dict) -> str:
|
|
550 |
answers = [correct_answer] + incorrect_answers if incorrect_answers else [correct_answer]
|
551 |
answers_html = "".join([
|
552 |
f"""
|
553 |
-
<div class="answer-option" style="margin: 8px 0; padding: 10px; background: #f9fafc; border-radius: 6px; border: 1px solid #8ecae6; border-left: 3px solid {'#
|
554 |
-
<span style="color: #
|
555 |
{answer}
|
556 |
</span>
|
557 |
</div>
|
@@ -561,7 +561,7 @@ def format_question(q: Dict) -> str:
|
|
561 |
|
562 |
content_html = f"""
|
563 |
<div class="answers-container" style="margin-top: 15px;">
|
564 |
-
<div style="color: #
|
565 |
{answers_html}
|
566 |
</div>
|
567 |
"""
|
@@ -571,8 +571,8 @@ def format_question(q: Dict) -> str:
|
|
571 |
if correct_answer:
|
572 |
content_html = f"""
|
573 |
<div class="answer" style="margin-top: 15px; padding: 15px; background: #f9fafc; border-radius: 6px; border: 1px solid #8ecae6;">
|
574 |
-
<div style="color: #
|
575 |
-
<div style="color: #
|
576 |
</div>
|
577 |
"""
|
578 |
|
@@ -587,15 +587,15 @@ def format_question(q: Dict) -> str:
|
|
587 |
if not content_html:
|
588 |
if 'body' in q:
|
589 |
content_html = f"""
|
590 |
-
<div class="question-content" style="margin-top: 20px; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; color: #
|
591 |
{process_body(q['body'], title)}
|
592 |
</div>
|
593 |
"""
|
594 |
elif 'correct_answer' in q:
|
595 |
content_html = f"""
|
596 |
<div class="answer" style="margin-top: 15px; padding: 15px; background: #f9fafc; border-radius: 6px; border: 1px solid #8ecae6;">
|
597 |
-
<div style="color: #
|
598 |
-
<div style="color: #
|
599 |
</div>
|
600 |
"""
|
601 |
|
@@ -664,7 +664,7 @@ def format_question(q: Dict) -> str:
|
|
664 |
{metadata_html}
|
665 |
|
666 |
<div class="interests-bar" style="margin: 15px 0; padding: 10px; background: #f9fafc; border-radius: 6px; border: 1px solid #8ecae6; border-left: 3px solid #219ebc;">
|
667 |
-
<div style="color: #
|
668 |
<div style="color: #219ebc; font-weight: 500; margin-top: 5px;">{interests_str}</div>
|
669 |
</div>
|
670 |
|
|
|
457 |
|
458 |
# Create an image preview card
|
459 |
preview_html = f"""
|
460 |
+
<div class="image-preview" style="margin: 10px 0; padding: 10px; background: #f9fafc; border-radius: 6px;">
|
461 |
<div style="display: flex; align-items: center; margin-bottom: 8px;">
|
462 |
<span style="font-size: 20px; margin-right: 8px;">🖼️</span>
|
463 |
+
<span style="color: #219ebc;">{alt_text}</span>
|
464 |
+
</div>
|
465 |
+
<a href="{fixed_src}" target="_blank" rel="noopener noreferrer"
|
466 |
+
style="color: #219ebc; text-decoration: none;">View image</a>
|
467 |
+
</div>
|
468 |
+
"""
|
469 |
|
470 |
new_soup = BeautifulSoup(preview_html, 'html.parser')
|
471 |
img.replace_with(new_soup)
|
|
|
478 |
link['href'] = fix_stack_exchange_url(href)
|
479 |
link['target'] = '_blank'
|
480 |
link['rel'] = 'noopener noreferrer'
|
481 |
+
link['style'] = 'color: #219ebc; text-decoration: none;'
|
482 |
|
483 |
# Add paragraph styling
|
484 |
for p in soup.find_all(['p', 'div']):
|
485 |
if not any(cls in (p.get('class', []) or []) for cls in ['image-preview', 'question-card']):
|
486 |
current_style = p.get('style', '')
|
487 |
+
p['style'] = f"{current_style}; margin: 0.8em 0; line-height: 1.6; color: #333333;"
|
488 |
|
489 |
# Add list styling
|
490 |
for ul in soup.find_all(['ul', 'ol']):
|
491 |
+
ul['style'] = 'margin: 0.8em 0; padding-left: 1.5em; color: #333333;'
|
492 |
|
493 |
for li in soup.find_all('li'):
|
494 |
+
li['style'] = 'margin: 0.4em 0; line-height: 1.6; color: #333333;'
|
495 |
|
496 |
# Add code block styling
|
497 |
for code in soup.find_all(['code', 'pre']):
|
498 |
+
code['style'] = 'background: #f9fafc; padding: 0.2em 0.4em; border-radius: 4px; font-family: monospace; color: #333333;'
|
499 |
|
500 |
return str(soup)
|
501 |
|
|
|
525 |
<div class="question-meta" style="font-size: 0.9em; margin-bottom: 15px;">
|
526 |
<span style="color: #219ebc; font-weight: 500;">{author}</span>
|
527 |
{' asked' if source == 'stack_exchange' else ' posted'} on
|
528 |
+
<span style="color: #023047;">{created_date}</span>
|
529 |
<div class="stats" style="margin-top: 5px;">
|
530 |
<span title="Upvotes"><span style="color: #219ebc;">▲</span> {upvotes}</span>
|
531 |
<span style="margin-left: 15px;" title="Comments"><span style="color: #219ebc;">💬</span> {num_comments}</span>
|
|
|
538 |
body = q.get('body', '')
|
539 |
if body:
|
540 |
content_html = f"""
|
541 |
+
<div class="question-content" style="margin-top: 20px; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; color: #023047; line-height: 1.6;">
|
542 |
{process_body(body, title)}
|
543 |
</div>
|
544 |
"""
|
|
|
550 |
answers = [correct_answer] + incorrect_answers if incorrect_answers else [correct_answer]
|
551 |
answers_html = "".join([
|
552 |
f"""
|
553 |
+
<div class="answer-option" style="margin: 8px 0; padding: 10px; background: #f9fafc; border-radius: 6px; border: 1px solid #8ecae6; border-left: 3px solid {'#4caf50' if answer == correct_answer else '#8ecae6'};">
|
554 |
+
<span style="color: {'#4caf50' if answer == correct_answer else '#023047'}; font-weight: {'500' if answer == correct_answer else 'normal'};">
|
555 |
{answer}
|
556 |
</span>
|
557 |
</div>
|
|
|
561 |
|
562 |
content_html = f"""
|
563 |
<div class="answers-container" style="margin-top: 15px;">
|
564 |
+
<div style="color: #023047; margin-bottom: 10px; font-weight: 500;">Answer options:</div>
|
565 |
{answers_html}
|
566 |
</div>
|
567 |
"""
|
|
|
571 |
if correct_answer:
|
572 |
content_html = f"""
|
573 |
<div class="answer" style="margin-top: 15px; padding: 15px; background: #f9fafc; border-radius: 6px; border: 1px solid #8ecae6;">
|
574 |
+
<div style="color: #023047; margin-bottom: 10px; font-weight: 500;">Answer:</div>
|
575 |
+
<div style="color: #4caf50; font-weight: 500;">{correct_answer}</div>
|
576 |
</div>
|
577 |
"""
|
578 |
|
|
|
587 |
if not content_html:
|
588 |
if 'body' in q:
|
589 |
content_html = f"""
|
590 |
+
<div class="question-content" style="margin-top: 20px; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; color: #023047; line-height: 1.6;">
|
591 |
{process_body(q['body'], title)}
|
592 |
</div>
|
593 |
"""
|
594 |
elif 'correct_answer' in q:
|
595 |
content_html = f"""
|
596 |
<div class="answer" style="margin-top: 15px; padding: 15px; background: #f9fafc; border-radius: 6px; border: 1px solid #8ecae6;">
|
597 |
+
<div style="color: #023047; margin-bottom: 10px; font-weight: 500;">Answer:</div>
|
598 |
+
<div style="color: #4caf50; font-weight: 500;">{q['correct_answer']}</div>
|
599 |
</div>
|
600 |
"""
|
601 |
|
|
|
664 |
{metadata_html}
|
665 |
|
666 |
<div class="interests-bar" style="margin: 15px 0; padding: 10px; background: #f9fafc; border-radius: 6px; border: 1px solid #8ecae6; border-left: 3px solid #219ebc;">
|
667 |
+
<div style="color: #023047; font-size: 0.9em; font-weight: 500;">Common Interests:</div>
|
668 |
<div style="color: #219ebc; font-weight: 500; margin-top: 5px;">{interests_str}</div>
|
669 |
</div>
|
670 |
|