Created
July 24, 2018 18:05
-
-
Save pravic/3846b0ea17a2480c35bf92eb41c0d68f to your computer and use it in GitHub Desktop.
Sublime snippets to VSCode
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
def parse_xml_snippet(root): | |
snippet = {} | |
description = None | |
for node in root: | |
if node.tag == 'content': | |
snippet['body'] = list(node.text.lstrip().splitlines()) | |
elif node.tag == 'tabTrigger': | |
snippet['prefix'] = node.text | |
elif node.tag == 'description': | |
snippet['description'] = node.text | |
return snippet | |
def read_snippets(): | |
import os | |
import xml.etree.ElementTree as ET | |
snippets = {} | |
files_count = 0 | |
for fd in os.scandir(): | |
if fd.is_file(): | |
name, ext = os.path.splitext(fd.name) | |
if ext == '.sublime-snippet': | |
files_count += 1 | |
try: | |
xml = ET.parse(fd.name) | |
snippets[name] = parse_xml_snippet(xml.getroot()) | |
except Exception as e: | |
print(e) | |
pass | |
pass | |
print("loaded %d / %d snippets" % (len(snippets), files_count)) | |
return snippets | |
def save_snippets(snippets): | |
import json | |
with open('rust.json', 'w', encoding='utf8') as file: | |
json.dump(snippets, file, indent=2) | |
print('saved') | |
pass | |
snippets = read_snippets() | |
save_snippets(snippets) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment