Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +13 -8
src/streamlit_app.py
CHANGED
|
@@ -92,27 +92,32 @@ def process_html_with_images(html_content, temp_dir, image_mapping):
|
|
| 92 |
absolute_path = os.path.abspath(os.path.join(temp_dir, relative_path))
|
| 93 |
file_url = f"file://{absolute_path}"
|
| 94 |
|
|
|
|
|
|
|
|
|
|
| 95 |
# Replace various image reference patterns
|
| 96 |
-
#
|
|
|
|
|
|
|
| 97 |
html_content = re.sub(
|
| 98 |
-
rf'src=["\']
|
| 99 |
-
f'src
|
| 100 |
html_content,
|
| 101 |
flags=re.IGNORECASE
|
| 102 |
)
|
| 103 |
|
| 104 |
-
# Pattern 2:
|
| 105 |
html_content = re.sub(
|
| 106 |
-
rf'url\(["\']?
|
| 107 |
f'url("{file_url}")',
|
| 108 |
html_content,
|
| 109 |
flags=re.IGNORECASE
|
| 110 |
)
|
| 111 |
|
| 112 |
-
# Pattern 3: href
|
| 113 |
html_content = re.sub(
|
| 114 |
-
rf'href=["\']
|
| 115 |
-
f'href
|
| 116 |
html_content,
|
| 117 |
flags=re.IGNORECASE
|
| 118 |
)
|
|
|
|
| 92 |
absolute_path = os.path.abspath(os.path.join(temp_dir, relative_path))
|
| 93 |
file_url = f"file://{absolute_path}"
|
| 94 |
|
| 95 |
+
# Escape the filename for regex
|
| 96 |
+
escaped_name = re.escape(original_name)
|
| 97 |
+
|
| 98 |
# Replace various image reference patterns
|
| 99 |
+
# Match filename with or without directory paths (images/, src/images/, ./images/, etc.)
|
| 100 |
+
|
| 101 |
+
# Pattern 1: src with any path prefix
|
| 102 |
html_content = re.sub(
|
| 103 |
+
rf'src=(["\'])(?:[^"\']*/)?' + escaped_name + r'\1',
|
| 104 |
+
f'src=\\1{file_url}\\1',
|
| 105 |
html_content,
|
| 106 |
flags=re.IGNORECASE
|
| 107 |
)
|
| 108 |
|
| 109 |
+
# Pattern 2: url() with any path prefix
|
| 110 |
html_content = re.sub(
|
| 111 |
+
rf'url\((["\']?)(?:[^)"\']*/)?{escaped_name}\1\)',
|
| 112 |
f'url("{file_url}")',
|
| 113 |
html_content,
|
| 114 |
flags=re.IGNORECASE
|
| 115 |
)
|
| 116 |
|
| 117 |
+
# Pattern 3: href with any path prefix
|
| 118 |
html_content = re.sub(
|
| 119 |
+
rf'href=(["\'])(?:[^"\']*/)?' + escaped_name + r'\1',
|
| 120 |
+
f'href=\\1{file_url}\\1',
|
| 121 |
html_content,
|
| 122 |
flags=re.IGNORECASE
|
| 123 |
)
|