Skip to content

Instantly share code, notes, and snippets.

@dnaga392
Created September 18, 2020 09:13
Show Gist options
  • Save dnaga392/3f336e5b4ed27f0732e5e342636eb744 to your computer and use it in GitHub Desktop.
Save dnaga392/3f336e5b4ed27f0732e5e342636eb744 to your computer and use it in GitHub Desktop.
Convert a image syntax to mpe import style from markdown style.
"""
Convert a image syntax to mpe import style from markdown style.
![my-image.png](../image/my-image.png)
to
@import "../image/my-image.png" {alt="my-image.png"}
"""
import re
def convert(txt):
"""Convert image sintax."""
p = re.compile(r'!\[([^\s]+)\]\(([^\s]+)\)')
m = p.match(txt)
if not m:
return ""
txt = '@import "{1}" (alt="{0}")'.format(m.group(1), m.group(2))
return txt.replace('(', '{').replace(')', '}')
def test():
"""Run test function."""
txt = "![my-image.png](../image/my-image.png)"
print(convert(txt))
if __name__ == '__main__':
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment