Here's a basic contenteditable div on a basic page:
Code:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
#input {
width: 500px;
height: 400px;
border: 1px solid black;
}
</style>
</head>
<body>
<div id="input" contenteditable></div>
</body>
</html>
You can paste/type whatever into it, then later get its current content via javascript using:
Code:
document.getElementById('input').innerHTML
That will be a string you can parse with re or whatever string methods you want to employ.
You can also query the document tree of the element for information like (for instance):
Code:
document.getElementById('input').getElementsByTagName('a').length
to determine if and how many links are currently in there, then loop through those, getting thier innerHTML, href, etc. For example:
Code:
var atags = document.getElementById('input').getElementsByTagName('a'), atag = 0, hrefs = [], html = [], thetag;
while((thetag = atags[atag++])){
hrefs.push(thetag.href);
html.push(thetag.innerHTML);
}
You can also, if you want, cancel the div's editable status via:
Code:
document.getElementById('input').removeAttribute('contenteditable');
and reestablish it with:
Code:
document.getElementById('input').setAttribute('contenteditable', true);
Exactly what use you make of all this (you might not need nearly all of it) is up to you, you seemed to be doing pretty well with what you had already, were just getting stuck on how to accept hidden information (like links) on paste as input. This will solve that. It will also import any other tags and attributes. For instance, when pasting your demo line into the above div, I got this innerHTML (line breaks added for clarity):
HTML Code:
<span style="color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px;
background-color: rgb(250, 250, 250);">Welcome to </span><a href="http://www.dynamicdrive.com/" target="_blank"
style="color: rgb(31, 76, 185); text-decoration: none; font-family: Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif; font-size: 13px;
background-color: rgb(250, 250, 250);">Dynamic Drive</a><span style="color: rgb(51, 51, 51); font-family: Verdana, Arial, Tahoma,
Calibri, Geneva, sans-serif; font-size: 13px; background-color: rgb(250, 250, 250);">, the #1 place on the net to obtain free, original
DHTML & Javascripts to enhance your web site!</span><div><span style="color: rgb(51, 51, 51); font-family: Verdana, Arial,
Tahoma, Calibri, Geneva, sans-serif; font-size: 13px; background-color: rgb(250, 250, 250);"><br></span></div>
If you have any other questions feel free to ask.
Bookmarks