sumitc91 commited on
Commit
7bc4182
·
verified ·
1 Parent(s): b897612

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +27 -7
app.py CHANGED
@@ -307,9 +307,11 @@ def build_resource_cards() -> str:
307
 
308
  # Build grouped HTML
309
  groups = []
 
310
  for cat, sections in sorted(by_category.items()):
 
311
  groups.append(
312
- f"<details open class=\"group\"><summary>{cat}</summary>{''.join(sections)}</details>"
313
  )
314
 
315
  return "".join(groups)
@@ -317,15 +319,33 @@ def build_resource_cards() -> str:
317
 
318
  def extract_links_markdown_to_html(text: str) -> str:
319
  import re
 
320
 
321
- # Find bare URLs
322
- url_re = re.compile(r"https?://[^\s)]+")
323
- urls = list(dict.fromkeys(url_re.findall(text or "")))
324
- if not urls:
 
 
 
 
 
 
 
 
 
 
 
 
 
325
  return "<i>No links found in the last response.</i>"
 
326
  items = []
327
- for u in urls:
328
- items.append(f"<li>{make_icon(u)} <a href=\"{u}\" target=\"_blank\" rel=\"noopener noreferrer\">{u}</a></li>")
 
 
 
329
  return f"<ul>{''.join(items)}</ul>"
330
 
331
 
 
307
 
308
  # Build grouped HTML
309
  groups = []
310
+ default_collapsed = {"tmresources", "environments", "whomtocontact"}
311
  for cat, sections in sorted(by_category.items()):
312
+ open_attr = "" if cat.strip().lower() in default_collapsed else " open"
313
  groups.append(
314
+ f"<details{open_attr} class=\"group\"><summary>{cat}</summary>{''.join(sections)}</details>"
315
  )
316
 
317
  return "".join(groups)
 
319
 
320
  def extract_links_markdown_to_html(text: str) -> str:
321
  import re
322
+ from html import escape
323
 
324
+ content = text or ""
325
+
326
+ # First: markdown links [label](url)
327
+ md_link_re = re.compile(r"\[([^\]]+)\]\((https?://[^\s)]+)\)")
328
+ seen: dict[str, str] = {}
329
+ for label, url in md_link_re.findall(content):
330
+ label = label.strip()
331
+ seen.setdefault(url, label if label else url)
332
+
333
+ # Then: bare URLs not already captured
334
+ url_re = re.compile(r"(?<!\()https?://[^\s)]+")
335
+ for m in url_re.finditer(content):
336
+ url = m.group(0)
337
+ if url not in seen:
338
+ seen[url] = url
339
+
340
+ if not seen:
341
  return "<i>No links found in the last response.</i>"
342
+
343
  items = []
344
+ for url, label in seen.items():
345
+ icon = make_icon(url)
346
+ items.append(
347
+ f"<li>{icon} <a href=\"{url}\" target=\"_blank\" rel=\"noopener noreferrer\">{escape(label)}</a></li>"
348
+ )
349
  return f"<ul>{''.join(items)}</ul>"
350
 
351