Last active
November 24, 2019 23:23
-
-
Save yue4u/1862328388339973180da605f21959f3 to your computer and use it in GitHub Desktop.
link svg for vue
This file contains hidden or 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
import re | |
import sys | |
xlink_re = re.compile('image id="(.+?)"[\s\S]+?(xlink:href=".+?)"') | |
file_name = sys.argv[1] | |
print(file_name) | |
def replace_link(match): | |
_txt = match.group(0) | |
_id = match.group(1) | |
_link = match.group(2) | |
return _txt.replace(_link, f":xlink:href=\"require('@/assets/{_id}.png')") | |
with open(file_name, 'r') as f: | |
i = f.read() | |
o = re.sub(xlink_re, replace_link, i) | |
print(o) | |
raw_name = file_name.replace('assets', '').replace('.', '-') | |
with open(f"components/{raw_name}-tmp.vue", 'w') as f: | |
f.write(f"""<template> | |
{o} | |
</template>""") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment