Molbap HF Staff commited on
Commit
34046df
·
2 Parent(s): 54aa468 cb8ab1b

Merge branch 'main' of https://huggingface.co/spaces/Molbap/Transformers-playthrough

Browse files
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -60,12 +60,29 @@ except Exception:
60
  _md_engine = _make_md_pythonmarkdown()
61
 
62
  def _obsidian_rewrites(text: str) -> str:
63
- # Obsidian image/file embeds and wiki links
64
- text = re.sub(r'!\[\[([^\]|]+)\]\]', r'![](static/\1)', text) # ![[file.png]]
65
- text = re.sub(r'\[\[([^\]|]+)\|([^\]]+)\]\]', r'[\2](\1)', text) # [[file|label]]
66
- text = re.sub(r'\[\[([^\]]+)\]\]', r'[\1](\1)', text) # [[file]]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  return text
68
 
 
69
  def md_to_html(text: str) -> str:
70
  text = _obsidian_rewrites(text)
71
  if _md_engine[0] == "markdown-it":
 
60
  _md_engine = _make_md_pythonmarkdown()
61
 
62
  def _obsidian_rewrites(text: str) -> str:
63
+ # 1) Obsidian image embeds: ![[img.png]] -> ![](file=content/img.png)
64
+ text = re.sub(r'!\[\[([^\]|]+)\]\]', r'![](file=content/\1)', text)
65
+
66
+ # 2) Standard Markdown images with relative paths: ![alt](path.png) -> ![alt](file=path.png)
67
+ # Skip if already http(s) or file=
68
+ text = re.sub(
69
+ r'!\[([^\]]*)\]\(((?!https?://|file=)[^)]+)\)',
70
+ r'![\1](file=\2)',
71
+ text,
72
+ )
73
+
74
+ # 3) Obsidian wiki links (non-image): [[file|label]] / [[file]]
75
+ text = re.sub(r'\[\[([^\]|]+)\|([^\]]+)\]\]', r'[\2](\1)', text)
76
+ text = re.sub(r'\[\[([^\]]+)\]\]', r'[\1](\1)', text)
77
+
78
+ # 4) Encode spaces in file= URLs so the browser doesn’t choke
79
+ def _enc(m):
80
+ return "file=" + m.group(1).replace(" ", "%20")
81
+ text = re.sub(r'file=([^)>\s]+)', _enc, text)
82
+
83
  return text
84
 
85
+
86
  def md_to_html(text: str) -> str:
87
  text = _obsidian_rewrites(text)
88
  if _md_engine[0] == "markdown-it":