Created
September 22, 2011 13:13
-
-
Save vestige/1234731 to your computer and use it in GitHub Desktop.
tkbjs
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
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 = { | |
'<' : '<', | |
'>' : '>', | |
'&' : '&', | |
'"' : '"' | |
}; | |
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