Skip to content

Instantly share code, notes, and snippets.

@davidhellsing
Created September 12, 2011 19:51
Show Gist options
  • Save davidhellsing/1212201 to your computer and use it in GitHub Desktop.
Save davidhellsing/1212201 to your computer and use it in GitHub Desktop.
Simple bookmarklet to convert selected text to HTML entities
function n(f) {
return f.replace(/</g,"&lt;").replace(/>/g,"&gt;");
}
a = document.activeElement;
v = a.value;
s = a.selectionStart;
e = a.selectionEnd;
a.value = v.substr(0,s) + n(v.substr(s,e)) + v.substr(e,v.length);
/*
Bookmarklet code:
javascript:(function(){function%20n(f){return%20f.replace(/%3C/g,%22%26lt;%22).replace(/%3E/g,%22%26gt;%22);}a=document.activeElement;v=a.value;s=a.selectionStart;e=a.selectionEnd;a.value=v.substr(0,s)+n(v.substr(s,e))+v.substr(e,v.length);})();
/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment