Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #3 from titoBouzout/master

Add entity decode/encode
  • Loading branch information...
commit ab5816e9144089da9b2dc93ca429411387895ad4 2 parents 0ecfd83 + 3fe4ebe
@dangelov authored
Showing with 43 additions and 1 deletion.
  1. +10 −0 Main.sublime-commands
  2. +2 −0  README.md
  3. +31 −1 hasher.py
View
10 Main.sublime-commands
@@ -30,6 +30,16 @@
"args": {}
},
{
+ "caption": "Hasher: Entity Encode",
+ "command": "entity_encode",
+ "args": {}
+ },
+ {
+ "caption": "Hasher: Entity Decode",
+ "command": "entity_decode",
+ "args": {}
+ },
+ {
"caption": "Hasher: Insert UNIX Timestamp",
"command": "current_unix_timestamp",
"args": {}
View
2  README.md
@@ -8,5 +8,7 @@ Hasher is a small Sublime Text 2 Plugin that generates hashes from the selected
* Base64 Decode
* URI Component Encode
* URI Component Decode
+* Entity Encode
+* Entity Decode
Use _Cmd + Shift + P_ on Mac or _Ctrl + Shift + P_ on Windows and type the command you need. Type _hasher_ to see available commands. More to come.
View
32 hasher.py
@@ -3,6 +3,7 @@
import urllib
import time
import base64
+import re
# test
@@ -39,7 +40,7 @@ def run(self, edit):
selected = self.view.substr(s)
txt = base64.b64encode(selected)
self.view.replace(edit, s, txt)
-
+
class Base64DecodeCommand(sublime_plugin.TextCommand):
def run(self, edit):
for s in self.view.sel():
@@ -71,6 +72,35 @@ def run(self, edit):
txt = unicode(txt.decode('utf8'));
self.view.replace(edit, s, txt);
+class EntityEncodeCommand(sublime_plugin.TextCommand):
+ def run(self, edit):
+ from htmlentitydefs import codepoint2name as cp2n
+ for s in self.view.sel():
+ if s.empty():
+ s = self.view.word(s)
+ buf = []
+ for pt in xrange(s.begin(), s.end()):
+ ch = self.view.substr(pt)
+ ch_ord = ord(ch)
+ try:
+ ch = '&%s;' % cp2n[ch_ord]
+ except:
+ pass
+ buf.append(ch)
+ self.view.replace(edit, s, ''.join(buf));
+
+class EntityDecodeCommand(sublime_plugin.TextCommand):
+ def run(self, edit):
+ for s in self.view.sel():
+ if s.empty():
+ s = self.view.word(s)
+
+ selected = unicode(self.view.substr(s))
+ import HTMLParser
+ HTMLParser = HTMLParser.HTMLParser()
+ selected = HTMLParser.unescape(selected)
+ self.view.replace(edit, s, selected);
+
class CurrentUnixTimestamp(sublime_plugin.TextCommand):
def run(self, edit):
for s in self.view.sel():
Please sign in to comment.
Something went wrong with that request. Please try again.