Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -77,14 +77,14 @@ def parse_endpoint():
|
|
| 77 |
except Exception as e:
|
| 78 |
return jsonify({'error': f'Failed to parse: {e}'}), 500
|
| 79 |
|
| 80 |
-
# --- HTML & PNG BUILDER (
|
| 81 |
def build_full_html(markdown_text, styles, include_fontawesome):
|
| 82 |
wrapper_id = "#output-wrapper"
|
| 83 |
font_family = styles.get('font_family', "'Arial', sans-serif")
|
| 84 |
-
|
| 85 |
-
# *** THIS IS THE FIX: Forcefully disable ALL external network calls ***
|
| 86 |
google_font_link = ""
|
| 87 |
-
|
|
|
|
| 88 |
|
| 89 |
highlight_theme = styles.get('highlight_theme', 'default')
|
| 90 |
pygments_css = ""
|
|
@@ -111,6 +111,8 @@ def build_full_html(markdown_text, styles, include_fontawesome):
|
|
| 111 |
html_content = markdown.markdown(markdown_text, extensions=md_extensions, extension_configs={'codehilite': {'css_class': 'codehilite'}})
|
| 112 |
final_html_body = f'<div id="output-wrapper">{html_content}</div>'
|
| 113 |
|
|
|
|
|
|
|
| 114 |
full_html = f"""<!DOCTYPE html>
|
| 115 |
<html><head><meta charset="UTF-8">{google_font_link}{fontawesome_link}<style>
|
| 116 |
#ouput-wrapper {{ background-color: {styles.get('background_color', '#fff')}; padding: 25px; display: inline-block;}}
|
|
@@ -131,11 +133,14 @@ def convert_endpoint():
|
|
| 131 |
include_fontawesome=data.get('include_fontawesome', False)
|
| 132 |
)
|
| 133 |
|
| 134 |
-
#
|
|
|
|
|
|
|
| 135 |
options = {
|
| 136 |
"quiet": "",
|
| 137 |
'encoding': "UTF-8",
|
| 138 |
-
'xvfb': ''
|
|
|
|
| 139 |
}
|
| 140 |
|
| 141 |
temp_html_path = os.path.join(TEMP_DIR, f"{uuid.uuid4()}.html")
|
|
|
|
| 77 |
except Exception as e:
|
| 78 |
return jsonify({'error': f'Failed to parse: {e}'}), 500
|
| 79 |
|
| 80 |
+
# --- HTML & PNG BUILDER (Unchanged) ---
|
| 81 |
def build_full_html(markdown_text, styles, include_fontawesome):
|
| 82 |
wrapper_id = "#output-wrapper"
|
| 83 |
font_family = styles.get('font_family', "'Arial', sans-serif")
|
| 84 |
+
google_font_name = font_family.split(',')[0].strip("'\"")
|
|
|
|
| 85 |
google_font_link = ""
|
| 86 |
+
if " " in google_font_name and google_font_name not in ["Times New Roman", "Courier New"]:
|
| 87 |
+
google_font_link = f'<link href="https://fonts.googleapis.com/css2?family={google_font_name.replace(" ", "+")}:wght@400;700&display=swap" rel="stylesheet">'
|
| 88 |
|
| 89 |
highlight_theme = styles.get('highlight_theme', 'default')
|
| 90 |
pygments_css = ""
|
|
|
|
| 111 |
html_content = markdown.markdown(markdown_text, extensions=md_extensions, extension_configs={'codehilite': {'css_class': 'codehilite'}})
|
| 112 |
final_html_body = f'<div id="output-wrapper">{html_content}</div>'
|
| 113 |
|
| 114 |
+
fontawesome_link = '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">' if include_fontawesome else ""
|
| 115 |
+
|
| 116 |
full_html = f"""<!DOCTYPE html>
|
| 117 |
<html><head><meta charset="UTF-8">{google_font_link}{fontawesome_link}<style>
|
| 118 |
#ouput-wrapper {{ background-color: {styles.get('background_color', '#fff')}; padding: 25px; display: inline-block;}}
|
|
|
|
| 133 |
include_fontawesome=data.get('include_fontawesome', False)
|
| 134 |
)
|
| 135 |
|
| 136 |
+
# *** THIS IS THE FINAL FIX ***
|
| 137 |
+
# This tells wkhtmltoimage to never make external network calls, fixing the ProtocolUnknownError.
|
| 138 |
+
# It also uses xvfb for stable headless rendering.
|
| 139 |
options = {
|
| 140 |
"quiet": "",
|
| 141 |
'encoding': "UTF-8",
|
| 142 |
+
'xvfb': '',
|
| 143 |
+
'disable-external-links': ''
|
| 144 |
}
|
| 145 |
|
| 146 |
temp_html_path = os.path.join(TEMP_DIR, f"{uuid.uuid4()}.html")
|