スペルミス、文構造ミスを修正するプログラムを作りたいです。問題は、このコードを実行すると、テキスト領域に挿入された記事が元のレイアウトで独自の段落構造を失うことです。はい、壊れています。では、記事の元のレイアウトと段落構造を維持しながら、テキスト領域のテキストを置き換えるにはどうすればよいでしょうか?とにかく独自の形状を維持するには? (私の言葉が正しいかどうかを確認するには、以下のサンプル記事をテキスト領域に貼り付けて実行してください。記事の段落レイアウトが壊れていることがわかります。)
-これはモノスプフォンで表示されます。最初のスペースは縞模様になりますが、他の白も存在します。Markdo ad HTL ae tur of in cod blo:-
<!DOCTYPE html>
<html>
<head>
<title>
</title>
</head>
<body>
<textarea id="myDiv" rows="100" cols="100"></textarea>
<button onclick="replaceText()">correct them!</button>
<script language="javascript">
function replaceText(){
var theDiv = document.getElementById("myDiv");
var theText = theDiv .innerHTML;
// Replace words
theText = theText.replace(/fineaple/gi, "pineapple");
theText = theText.replace(/terminater/gi, "terminator");
theText = theText.replace(/testacl/gi, "testicle");
theText = theText.replace(/sting/gi, "string");
theText = theText.replace(/watarmalon/gi, "watermelons");
theText = theText.replace(/th/gi, "the");
theText = theText.replace(/thi/gi, "this");
theText = theText.replace(/wil/gi, "will");
theText = theText.replace(/b/gi, "be");
theText = theText.replace(/disp/gi, "displayed");
theText = theText.replace(/monosp/gi, "mono spaced");
theText = theText.replace(/fon/gi, "font");
theText = theText.replace(/frst/gi, "first");
theText = theText.replace(/fou/gi, "four");
theText = theText.replace(/spac/gi, "spaces");
theText = theText.replace(/striped /gi, "stripped");
theText = theText.replace(/of/gi, "off");
theText = theText.replace(/bt/gi, "but");
theText = theText.replace(/al/gi, "all");
theText = theText.replace(/othe/gi, "other");
theText = theText.replace(/whites/gi, "white space");
theText = theText.replace(/prese/gi, "preserved");
theText = theText.replace(/markdo/gi, "markdown");
theText = theText.replace(/ad/gi, "and");
theText = theText.replace(/htl/gi, "html");
theText = theText.replace(/ae/gi, "are");
theText = theText.replace(/tur/gi, "turned");
theText = theText.replace(/cod/gi, "code");
theText = theText.replace(/blo/gi, "blocks");
theDiv.innerHTML = theText;
}
</script>
</body>
</html>