I have a HTML form with a field in which the user can supply text. In that text they might want to include a link to another website amongst the plain text. Ideally, when they paste a URL from another source into the text area, it becomes clickable as they're editing. Is there a simple solution for implementing this feature without using external tools such as the one suggested in this answer?
Attempted Solutions
The closest I've gotten is by using a <div>contenteditable="true"</div> and dragging hyperlinks into the div. Unfortunately, when a div has contenteditable="true" anchors become un-clickable which was addressed here by holding the ctrl button to set contenteditable="false"; however, then we lose ctrl+v functionality. Additionally, I'm not sure how I will be able to submit the data if the tag is a <div> instead of <textarea>.
When using <textarea>, the link is copied as plain-text and isn't a clickable link. I believe anchors aren't allowed in a <textarea>.
I don't believe <input type="url"> works because the text area may contain content that isn't a URL.
Refer to snippet to see my attempts.
var content = document.getElementById('content');
document.addEventListener('keydown', function(event) {
if (event.keyCode === 17) { // when ctrl is pressed
content.contentEditable = false; // disable contentEditable
}
}, false);
document.addEventListener('keyup', function(event) {
if (event.keyCode === 17) { // when ctrl is released
content.contentEditable = true; // reenable contentEditable
}
}, false);
<textarea></textarea>
<div id="content" contenteditable="true"></div>
<input type="url">