broadfield-dev commited on
Commit
dd6f661
·
verified ·
1 Parent(s): 405d1b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -11
app.py CHANGED
@@ -82,13 +82,9 @@ 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: Disable the external Google Fonts call ***
86
- # By setting this to an empty string, we prevent the HTTPS request that causes the error.
87
  google_font_link = ""
88
- # Original problematic code commented out:
89
- # google_font_name = font_family.split(',')[0].strip("'\"")
90
- # if " " in google_font_name and google_font_name not in ["Times New Roman", "Courier New"]:
91
- # google_font_link = f'<link href="https://fonts.googleapis.com/css2?family={google_font_name.replace(" ", "+")}:wght@400;700&display=swap" rel="stylesheet">'
92
 
93
  highlight_theme = styles.get('highlight_theme', 'default')
94
  pygments_css = ""
@@ -115,8 +111,6 @@ def build_full_html(markdown_text, styles, include_fontawesome):
115
  html_content = markdown.markdown(markdown_text, extensions=md_extensions, extension_configs={'codehilite': {'css_class': 'codehilite'}})
116
  final_html_body = f'<div id="output-wrapper">{html_content}</div>'
117
 
118
- 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 ""
119
-
120
  full_html = f"""<!DOCTYPE html>
121
  <html><head><meta charset="UTF-8">{google_font_link}{fontawesome_link}<style>
122
  #ouput-wrapper {{ background-color: {styles.get('background_color', '#fff')}; padding: 25px; display: inline-block;}}
@@ -125,7 +119,7 @@ def build_full_html(markdown_text, styles, include_fontawesome):
125
 
126
  return full_html
127
 
128
- # --- API ENDPOINT for Conversion (Unchanged) ---
129
  @app.route('/convert', methods=['POST'])
130
  def convert_endpoint():
131
  data = request.json
@@ -137,7 +131,7 @@ def convert_endpoint():
137
  include_fontawesome=data.get('include_fontawesome', False)
138
  )
139
 
140
- # We need xvfb because wkhtmltoimage is a headless browser
141
  options = {
142
  "quiet": "",
143
  'encoding': "UTF-8",
@@ -316,4 +310,4 @@ def index():
316
  """, highlight_styles=highlight_styles)
317
 
318
  if __name__ == "__main__":
319
- app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 7860)))
 
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
+ fontawesome_link = ""
 
 
 
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
  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;}}
 
119
 
120
  return full_html
121
 
122
+ # --- API ENDPOINT for Conversion (CHANGED) ---
123
  @app.route('/convert', methods=['POST'])
124
  def convert_endpoint():
125
  data = request.json
 
131
  include_fontawesome=data.get('include_fontawesome', False)
132
  )
133
 
134
+ # Use xvfb, which is required for stable headless rendering.
135
  options = {
136
  "quiet": "",
137
  'encoding': "UTF-8",
 
310
  """, highlight_styles=highlight_styles)
311
 
312
  if __name__ == "__main__":
313
+ app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 7860)))```