__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.+?)' # 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")