public
Created

Convert WebEdit commands to Sublime Text 2 keybinding snippets

  • Download Gist
conv.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# 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
input.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
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.|
output.json
JSON
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
{ "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}"
}
},

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.