Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 text = '<html><body bgcolor=linen><p>' +
- 'This is <b>bold<\/b>!<\/p><\/body><\/html>';
- var tags = /[^<>]+|<(\/?)([A-Za-z]+)([^<>]*)>/g;
- var a, i;
- while ((a = tags.exec(text))) {
- for (i = 0; i < a.length; i += 1) {
- console.log(('// [' + i + '] ' + a[i]).entityify());
- }
- }
Add Comment
Please, Sign In to add comment