このあとブックマークレット化したい。
→改良版へ
javascript: function getSelectedTextAndReplace() { IE='\v'=='v'; var SelectedText; if (IE) { SelectedText = document.selection.createRange().text; } else { SelectedText = window.getSelection().toString(); } alert (strToBloggerCodeTag(SelectedText)); } function strToBloggerCodeTag(str) { str = replaceAll(str, "<", "<"); str = replaceAll(str, ">", ">"); str = replaceAll(str, "<", "&lt;"); str = replaceAll(str, ">", "&gt;"); return "<pre class=\"prettyprint\">\n" + str + "\n</pre>"; } function replaceAll(expression, org, dest){ return expression.split(org).join(dest); } getSelectedTextAndReplace(); void(0);
参考
・Javascriptで選択文字列の取得 - Road To Nowhere