Spaces:
Sleeping
Sleeping
Mahdi Naser Moghadasi
commited on
Commit
·
1306b1b
1
Parent(s):
5715157
Simplify content styling to fix HTML rendering issues
Browse files- Remove complex regex patterns that were causing malformed HTML
- Use simple, robust styling approach that won't break
- Keep only essential styling: answer boxes, fill-in-blanks, checkboxes, rating scales
- Remove problematic header and list styling that was causing conflicts
- This should fix the issue where CSS attributes were showing as literal text
- Content should now render properly in Gradio HTML component
app.py
CHANGED
|
@@ -1862,15 +1862,18 @@ def convert_math_to_html(text):
|
|
| 1862 |
return text
|
| 1863 |
|
| 1864 |
def apply_content_styling(content, content_type):
|
| 1865 |
-
"""Apply
|
| 1866 |
import re
|
| 1867 |
|
| 1868 |
-
#
|
| 1869 |
content = re.sub(r'="[^"]*style="[^"]*"[^"]*"', '', content)
|
| 1870 |
content = re.sub(r'="[^"]*color: [^"]*"[^"]*"', '', content)
|
| 1871 |
content = re.sub(r'="[^"]*background: [^"]*"[^"]*"', '', content)
|
|
|
|
|
|
|
|
|
|
| 1872 |
|
| 1873 |
-
#
|
| 1874 |
styled_content = f"""
|
| 1875 |
<div style="
|
| 1876 |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
@@ -1887,43 +1890,16 @@ def apply_content_styling(content, content_type):
|
|
| 1887 |
</div>
|
| 1888 |
"""
|
| 1889 |
|
| 1890 |
-
#
|
| 1891 |
-
styled_content = re.sub(r'^# ([^<\n]+)$', r'<h1 style="color: #2c3e50; border-bottom: 3px solid #3498db; padding-bottom: 10px; margin-bottom: 20px; font-size: 2.2em;">\1</h1>', styled_content, flags=re.MULTILINE)
|
| 1892 |
-
styled_content = re.sub(r'^## ([^<\n]+)$', r'<h2 style="color: #34495e; margin-top: 30px; margin-bottom: 15px; font-size: 1.8em; border-left: 4px solid #3498db; padding-left: 15px;">\1</h2>', styled_content, flags=re.MULTILINE)
|
| 1893 |
-
styled_content = re.sub(r'^### ([^<\n]+)$', r'<h3 style="color: #2c3e50; margin-top: 25px; margin-bottom: 12px; font-size: 1.4em;">\1</h3>', styled_content, flags=re.MULTILINE)
|
| 1894 |
-
|
| 1895 |
-
# Style bold text - simple approach
|
| 1896 |
-
styled_content = re.sub(r'\*\*([^*]+?)\*\*', r'<strong style="color: #2c3e50; font-weight: 600;">\1</strong>', styled_content)
|
| 1897 |
-
|
| 1898 |
-
# Style answer boxes
|
| 1899 |
styled_content = re.sub(r'\[ANSWER: ([^\]]+)\]', r'<span style="background: #e8f4fd; border: 2px solid #3498db; padding: 4px 8px; border-radius: 4px; font-weight: bold; color: #2c3e50;">[ANSWER: \1]</span>', styled_content)
|
| 1900 |
|
| 1901 |
-
# Style fill-in-blank spaces
|
| 1902 |
styled_content = re.sub(r'___+', r'<span style="border-bottom: 2px solid #3498db; min-width: 40px; display: inline-block; margin: 0 5px;"> </span>', styled_content)
|
| 1903 |
|
| 1904 |
-
# Style checkboxes
|
| 1905 |
styled_content = re.sub(r'\[ \]', r'<input type="checkbox" style="margin-right: 8px; transform: scale(1.2);">', styled_content)
|
| 1906 |
styled_content = re.sub(r'☐', r'<input type="checkbox" style="margin-right: 8px; transform: scale(1.2);">', styled_content)
|
| 1907 |
styled_content = re.sub(r'☑', r'<input type="checkbox" checked style="margin-right: 8px; transform: scale(1.2);">', styled_content)
|
| 1908 |
|
| 1909 |
-
#
|
| 1910 |
-
styled_content = re.sub(r'\[(\d+)\]', r'<span style="background: #ecf0f1; border: 1px solid #bdc3c7; padding: 5px 10px; margin: 0 2px; border-radius: 4px; cursor: pointer; transition: all 0.2s;">\1</span>', styled_content)
|
| 1911 |
-
|
| 1912 |
-
# Style lists - be more careful
|
| 1913 |
-
styled_content = re.sub(r'^- ([^<\n]+)$', r'<li style="margin-bottom: 8px; padding-left: 10px;">\1</li>', styled_content, flags=re.MULTILINE)
|
| 1914 |
-
styled_content = re.sub(r'^(\d+)\. ([^<\n]+)$', r'<li style="margin-bottom: 8px; padding-left: 10px; list-style-type: decimal;">\2</li>', styled_content, flags=re.MULTILINE)
|
| 1915 |
-
|
| 1916 |
-
# Style horizontal rules
|
| 1917 |
-
styled_content = re.sub(r'^---$', r'<hr style="border: none; height: 2px; background: linear-gradient(to right, #3498db, #2ecc71); margin: 30px 0;">', styled_content, flags=re.MULTILINE)
|
| 1918 |
-
|
| 1919 |
-
# Style interactive elements
|
| 1920 |
-
styled_content = re.sub(r'\[INTERACTIVE: ([^\]]+)\]', r'<div style="background: #f8f9fa; border: 2px dashed #3498db; padding: 15px; margin: 15px 0; border-radius: 8px; text-align: center; color: #7f8c8d; font-style: italic;">🎮 INTERACTIVE: \1</div>', styled_content)
|
| 1921 |
-
|
| 1922 |
-
# Style media elements
|
| 1923 |
-
styled_content = re.sub(r'\[MEDIA: ([^\]]+)\]', r'<div style="background: #e8f5e8; border: 2px solid #27ae60; padding: 15px; margin: 15px 0; border-radius: 8px; text-align: center; color: #27ae60; font-weight: bold;">🎥 MEDIA: \1</div>', styled_content)
|
| 1924 |
-
|
| 1925 |
-
# Style math expressions - be more specific
|
| 1926 |
-
styled_content = re.sub(r'([A-Za-z]+ = [^<\n=]+)(?![^<]*>)', r'<div style="background: #f8f9fa; border-left: 4px solid #e74c3c; padding: 10px 15px; margin: 10px 0; font-family: \'Courier New\', monospace; font-size: 1.1em; color: #2c3e50;">\1</div>', styled_content)
|
| 1927 |
|
| 1928 |
return styled_content
|
| 1929 |
|
|
|
|
| 1862 |
return text
|
| 1863 |
|
| 1864 |
def apply_content_styling(content, content_type):
|
| 1865 |
+
"""Apply simple and robust styling to educational content"""
|
| 1866 |
import re
|
| 1867 |
|
| 1868 |
+
# Clean up any malformed HTML first
|
| 1869 |
content = re.sub(r'="[^"]*style="[^"]*"[^"]*"', '', content)
|
| 1870 |
content = re.sub(r'="[^"]*color: [^"]*"[^"]*"', '', content)
|
| 1871 |
content = re.sub(r'="[^"]*background: [^"]*"[^"]*"', '', content)
|
| 1872 |
+
content = re.sub(r'="[^"]*border: [^"]*"[^"]*"', '', content)
|
| 1873 |
+
content = re.sub(r'="[^"]*padding: [^"]*"[^"]*"', '', content)
|
| 1874 |
+
content = re.sub(r'="[^"]*margin: [^"]*"[^"]*"', '', content)
|
| 1875 |
|
| 1876 |
+
# Simple styling approach - just wrap in a clean container
|
| 1877 |
styled_content = f"""
|
| 1878 |
<div style="
|
| 1879 |
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
|
|
| 1890 |
</div>
|
| 1891 |
"""
|
| 1892 |
|
| 1893 |
+
# Only apply basic styling that won't break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1894 |
styled_content = re.sub(r'\[ANSWER: ([^\]]+)\]', r'<span style="background: #e8f4fd; border: 2px solid #3498db; padding: 4px 8px; border-radius: 4px; font-weight: bold; color: #2c3e50;">[ANSWER: \1]</span>', styled_content)
|
| 1895 |
|
|
|
|
| 1896 |
styled_content = re.sub(r'___+', r'<span style="border-bottom: 2px solid #3498db; min-width: 40px; display: inline-block; margin: 0 5px;"> </span>', styled_content)
|
| 1897 |
|
|
|
|
| 1898 |
styled_content = re.sub(r'\[ \]', r'<input type="checkbox" style="margin-right: 8px; transform: scale(1.2);">', styled_content)
|
| 1899 |
styled_content = re.sub(r'☐', r'<input type="checkbox" style="margin-right: 8px; transform: scale(1.2);">', styled_content)
|
| 1900 |
styled_content = re.sub(r'☑', r'<input type="checkbox" checked style="margin-right: 8px; transform: scale(1.2);">', styled_content)
|
| 1901 |
|
| 1902 |
+
styled_content = re.sub(r'\[(\d+)\]', r'<span style="background: #ecf0f1; border: 1px solid #bdc3c7; padding: 5px 10px; margin: 0 2px; border-radius: 4px; cursor: pointer;">\1</span>', styled_content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1903 |
|
| 1904 |
return styled_content
|
| 1905 |
|