実体参照に変換(不細工版)
たぶん動く。
by ethertank
HTML
<section>
<header>
<hgroup>
<h1>実体参照変換ツール</h1>
<h2>&、<、>、"、©、∀、ω 及び半角スペースを実体参照文字に変換します。</h2>
</hgroup>
</header>
<div>
<textarea id="input"><!DOCTYPE html><html lang="ja"><head><meta charset="utf-8" />
<title>まよまよ</title>
<style>
body { padding:0; color:#906; }
</style>
<script>
var S = "マヨうまい"; alert(S);
</script>
</head>
<body>
<header id="global_header">
<hgroup>
<h1 id="site_ID">まよランド</h1>
<h2 id="site_subTitle">まよ子のページだよ!</h2>
</hgroup>
</header>
<section>
<h1>まよ!</h1>
<p>まよまよまよまよ。まよ?まよまよ!</p>
<p>& & < > "(。-∀-)(`・ω・´)(´・ ω ・`)</p>
</section>
<footer><p><small>©2048 マヨ子 All Right Reserved.</small></p></footer>
</body></html></textarea>
</div>
<div>
<button id="button_01">実体参照に変換 →</button>
<button id="button_02">消去</button>
</div>
<div>
<textarea id="output" readonly></textarea>
</div>
</section>
CSS
@charset "utf-8";
html,body{margin:0;padding:0;height:100%;}
html{
overflow-y:scroll;
-webkit-background-size: 10px 10px;
-moz-background-size: 10px 10px;
background-size: 10px 10px;
background-color: #577e00;
background-image: -webkit-gradient(
radial,
center top, 0,
center top, 32,
from(#00c2bf),
color-stop(50%, #000),
to(#000)
);
background-image: -moz-radial-gradient(
center top, circle,
#00c2bf, #000, #000 32px
);
background-image: radial-gradient(
center top, circle,
#00c2bf, #000, #000 32px
);
}
body{color:#fff;background:transparent}
a{color:#fffe00}
section{ display:block; min-width: 300px; max-width: 800px; margin: 0 auto; padding:20px;}
h1,h2{
margin:0; font-weight:300;
font-family:KozGoPro-Light, "Hiragino Kaku Gothic Pro", "Trebuchet MS", Verdana, Meiryo,"MSP Gothic", sans-serif;
}
h1{ font-size:2.5em}
h2{ font-size:1.25em}
textarea,button{font-size:12px}
textarea {
width:100%; height:180px; resize:vertical;
border: 1px solid #fff;
padding:3px;
-webkit-box-shadow: 1px 1px 4px 0 rgba(0,0,0,0.5) inset;
-moz-box-shadow: 1px 1px 4px 0 rgba(0,0,0,0.5) inset;
box-shadow: 1px 1px 4px 0 rgba(0,0,0,0.5) inset;
}
button {vertical-align:top}
JavaScript
(function() {
document.createElement("section");
function addEvent(e, n, o, u) {
(e.addEventListener) ? e.addEventListener(n, o, u) : (e.attachEvent) ? e.attachEvent('on' + n, o) : "";
}
function id(id) {
var ID = document.getElementById(id);
return ID;
}
addEvent(window, "load", init, false);
function init() {
var input = id("input"),
output = id("output"),
button_01 = id("button_01"),
button_02 = id("button_02");
addEvent(button_01, "click", replaceButtonClick, false);
addEvent(button_02, "click", clearButtonClick, false);
function clearButtonClick() {
input.value = "";
output.value = "";
}
function replaceButtonClick() {
var INPUT = input.value;
E = INPUT;
E = E.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
E = E.replace(/ /g, " ").replace(/©/g, "©").replace(/∀/g, "∀").replace(/ω/g, "ω");
output.value = E;
}
}
})();