wiki/javascript
Little routines
Markdown has an idiotic way of signaling code-blocks. This makes the copy-paste routine of authoring code for online viewing a little easier. Requires prototype.
function codificate(elem) {
var text = getTextAreaSelection(elem);
if (!text) return;
lines = text.split(/\n/);
text = lines.map(function (line) {
return ' ' + line + '\n';
}).inject('', function (text, line) {
return text + line;
});
setTextAreaSelection(elem, text);
}