Skip to content

Instantly share code, notes, and snippets.

@quarnster
Created September 27, 2012 18:54
Show Gist options
  • Save quarnster/3795725 to your computer and use it in GitHub Desktop.
Save quarnster/3795725 to your computer and use it in GitHub Desktop.
Convert WebEdit commands to Sublime Text 2 keybinding snippets
# Usage: python conv.py < input.txt > output.json
import re
import sys
for line in re.findall(r".*?=([^\"\n]+[^\n]+)", sys.stdin.read()):
count = 1
regex = re.compile(r"((\w+)=\"([^\"$\n]+)\")")
match = regex.search(line)
while match:
line = "%s%s=\\\"${%d:%s}\\\"%s" % (line[:match.start()], match.group(2), count, match.group(3), line[match.end():])
match = regex.search(line)
count += 1
line = re.sub(r"(\$\{\d+\:)\|(\})", r"\1$SELECTION\2", line)
if "|" in line:
line = line.replace("|", "${%d:$SELECTION}" % count)
print """{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "%s"
}
},""" % line
a=<a href="address" title="titleattribute">|</a>
nofollow=rel="nofollow"
img=<img src="|" alt="altattribute" />
img float=style="float:left;padding:10px;margin:0 10px 0 0;border:1px solid #e4e4e4;"\t|
inline style=style="|"\t
banner=<a href="|"><img src="imagelocation" alt="altattribute" /></a>
div class=<div class="classname">|</div>
div id=<div id="idname">|</div>
p=<p>\n|\n</p>
br=<br />|
2x br=<br />\n<br />|
em=<em>|</em>
h1=<h1>|</h1>
h2=<h2>|</h2>
h3=<h3>|</h3>
h4=<h4>|</h4>
h5=<h5>|</h5>
h6=<h6>|</h6>
ol=<ol>\n|\n</ol>
ul=<ul>\n|\n</ul>
li=<li>|</li>
span=<span>|</span>
strong=<strong>|</strong>
style=<style>\n|\n</style>
table=<table>\n|</table>
td=<td>|</td>
tr=<tr>|</tr>
*=(|)
lipsum=Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut ligula ipsum, hendrerit nec ultrices ut, fringilla id justo. Ut magna metus, condimentum nec consequat vitae, vehicula non magna. Aenean in odio vel arcu pharetra congue. Quisque est quam, pulvinar sit amet lobortis non, hendrerit eget lacus. In rutrum fringilla sapien, vitae aliquet mi lacinia ut. Nunc elementum pellentesque nibh, eget venenatis mauris scelerisque sit amet. Vivamus id ultricies tortor. Aliquam erat volutpat. Curabitur sit amet magna at nisi rhoncus fermentum. Nunc laoreet placerat libero et ullamcorper.|
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<a href=\"${1:address}\" title=\"${2:titleattribute}\">${3:$SELECTION}</a>"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "rel=\"${1:nofollow}\""
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<img src=\"${1:$SELECTION}\" alt=\"${2:altattribute}\" />"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "style=\"${1:float:left;padding:10px;margin:0 10px 0 0;border:1px solid #e4e4e4;}\"\t${2:$SELECTION}"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "style=\"${1:$SELECTION}\"\t"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<a href=\"${1:$SELECTION}\"><img src=\"${2:imagelocation}\" alt=\"${3:altattribute}\" /></a>"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<div class=\"${1:classname}\">${2:$SELECTION}</div>"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<div id=\"${1:idname}\">${2:$SELECTION}</div>"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<p>\n${1:$SELECTION}\n</p>"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<br />${1:$SELECTION}"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<br />\n<br />${1:$SELECTION}"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<em>${1:$SELECTION}</em>"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<h1>${1:$SELECTION}</h1>"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<h2>${1:$SELECTION}</h2>"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<h3>${1:$SELECTION}</h3>"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<h4>${1:$SELECTION}</h4>"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<h5>${1:$SELECTION}</h5>"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<h6>${1:$SELECTION}</h6>"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<ol>\n${1:$SELECTION}\n</ol>"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<ul>\n${1:$SELECTION}\n</ul>"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<li>${1:$SELECTION}</li>"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<span>${1:$SELECTION}</span>"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<strong>${1:$SELECTION}</strong>"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<style>\n${1:$SELECTION}\n</style>"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<table>\n${1:$SELECTION}</table>"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<td>${1:$SELECTION}</td>"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "<tr>${1:$SELECTION}</tr>"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "(${1:$SELECTION})"
}
},
{ "keys": [""], "command": "insert_snippet",
"args":
{
"contents": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut ligula ipsum, hendrerit nec ultrices ut, fringilla id justo. Ut magna metus, condimentum nec consequat vitae, vehicula non magna. Aenean in odio vel arcu pharetra congue. Quisque est quam, pulvinar sit amet lobortis non, hendrerit eget lacus. In rutrum fringilla sapien, vitae aliquet mi lacinia ut. Nunc elementum pellentesque nibh, eget venenatis mauris scelerisque sit amet. Vivamus id ultricies tortor. Aliquam erat volutpat. Curabitur sit amet magna at nisi rhoncus fermentum. Nunc laoreet placerat libero et ullamcorper.${1:$SELECTION}"
}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment