Merge branch 'main' of https://huggingface.co/spaces/Molbap/Transformers-playthrough
Browse files
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
|
| 64 |
-
text = re.sub(r'!\[\[([^\]|]+)\]\]', r' -> 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]] -> 
|
| 64 |
+
text = re.sub(r'!\[\[([^\]|]+)\]\]', r'', text)
|
| 65 |
+
|
| 66 |
+
# 2) Standard Markdown images with relative paths:  -> 
|
| 67 |
+
# Skip if already http(s) or file=
|
| 68 |
+
text = re.sub(
|
| 69 |
+
r'!\[([^\]]*)\]\(((?!https?://|file=)[^)]+)\)',
|
| 70 |
+
r'',
|
| 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":
|