I would like to have the visual representation of an HTML5 tag indicate when there are \'hard\' newlines as opposed to wrapping. For example, g
"T1" is the ID of a textarea. Using jQuery:
var content = $('#T1').html().replace(/¶/g,"") //get rid of existing indicator
content = $('#T1').html().replace(/\n/g,"¶\n") //add indicator
$('#T1').html(content)
You cannot do this without modifying the content of the textarea. You can't see what you don't have in your page. You'd need to strip out the paragraph character before saving. Hook up the code to the onkeyup event.
Live Demo
<style type="text/css">
#myform textarea {
border: 1px solid #000;
position: absolute;
}
#myform #source {
background: transparent;
z-index: 1;
}
#myform #mirror {
color: rgba(0,0,0,0.5);
z-index: -1;
}
</style>
<script type="text/javascript">
$("#source").keyup(function() {
$("#mirror").val($("#source").val().replace(/\n/g,"¶\n"));
});
</script>
<form id="myform">
<textarea id="source" rows="10" cols="40"></textarea>
<textarea id="mirror" rows="10" cols="40"></textarea>
</form>
Note: Tested on Firefox 3.6.x only. (IE will need some different CSS for opacity)