Skip to content

Instantly share code, notes, and snippets.

@vestige
Created September 22, 2011 13:13
Show Gist options
  • Save vestige/1234731 to your computer and use it in GitHub Desktop.
Save vestige/1234731 to your computer and use it in GitHub Desktop.
tkbjs
document.writeln("");
document.writeln("Hello tkbjs");
Function.prototype.method = function(name, method) {
if (!this.prototype[name]) {
this.prototype[name] = method;
return this;
}
}
String.method('entityify', function () {
var character = {
'<' : '&lt;',
'>' : '&gt;',
'&' : '&amp;',
'"' : '&quot;'
};
return function () {
return this.replace(/[<>&"]/g, function (c) {
return character[c];
});
};
}());
var ttt = '<html><body bgcolor=linen><p>' +
'This is <b>bold<\/b>!<\/p><\/body><\/html>';
var tags = /[^<>]+|<(\/?)([A-Za-z]+)([^<>]*)>/g;
var a, i;
a = ttt.match(tags);
document.writeln(a.length);
for (index = 0; index < a.length; index += 1) {
document.writeln('//' + a[index].entityify());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment