Created
September 18, 2020 09:13
-
-
Save dnaga392/3f336e5b4ed27f0732e5e342636eb744 to your computer and use it in GitHub Desktop.
Convert a image syntax to mpe import style from markdown style.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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