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) { return "<pre class=\"prettyprint\">\n" + escapeHTML(str) + "\n</pre>"; } function escapeHTML(strTarget){ var div = document.createElement('div'); var text = document.createTextNode(''); div.appendChild(text); text.data = strTarget; return div.innerHTML; } getSelectedTextAndReplace(); void(0);
参考
・Javascript/HTML特殊文字のエスケープ - 俺の基地