vault backup: 2025-12-26 02:09:22
All checks were successful
Deploy Quartz site to GitHub Pages / build (push) Successful in 2m29s
All checks were successful
Deploy Quartz site to GitHub Pages / build (push) Successful in 2m29s
This commit is contained in:
38
stroma/quiz/utils/obsidian_embed_plugin.py
Normal file
38
stroma/quiz/utils/obsidian_embed_plugin.py
Normal file
@@ -0,0 +1,38 @@
|
||||
__all__ = ["obsidian_embed"]
|
||||
|
||||
# https://help.obsidian.md/embeds
|
||||
|
||||
# Supported:
|
||||
# ![[image-4.png|292x316]]
|
||||
def parse_embed(inline, match, state):
|
||||
filename = match.group("filename")
|
||||
attrs = {}
|
||||
if "|" in filename:
|
||||
filename, size = filename.split("|", 1)
|
||||
else:
|
||||
size = None
|
||||
attrs["filename"] = filename
|
||||
if size:
|
||||
if "x" in size:
|
||||
width, height = size.split("x", 1)
|
||||
if width:
|
||||
attrs["width"] = int(width)
|
||||
if height:
|
||||
attrs["height"] = int(height)
|
||||
else:
|
||||
attrs["width"] = int(size)
|
||||
state.append_token({"type": "embed", "attrs": attrs})
|
||||
return match.end()
|
||||
|
||||
|
||||
INLINE_EMBED_PATTERN = (
|
||||
r'!\[\[' # begins with ![
|
||||
r'(?!\s)' # not whitespace
|
||||
r'(?P<filename>.+?)' # content between `![[xx]]`
|
||||
r'(?!\s)' # not whitespace
|
||||
r'\]\]' # closing ]
|
||||
)
|
||||
|
||||
|
||||
def obsidian_embed(md: "Markdown") -> None:
|
||||
md.inline.register('embed', INLINE_EMBED_PATTERN, parse_embed, before="link")
|
||||
Reference in New Issue
Block a user