I am using laravel and if some one puts the link in the description it shows as simple text only not as a link.So what needs to be done if the link should appear as link and simple text as simple text.
Asked
Active
Viewed 362 times
2 Answers
0
You can use jquery
and regexp
as below to achieve the same or you should use some wysiwyg
editor
$(function(){
$("#yourTextArea").on("blur", function(){
var text = $(this).val();
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
var text1=text.replace(exp, "<a href='$1'>$1</a>");
var exp2 =/(^|[^\/])(www\.[\S]+(\b|$))/gim;
$(this).val(text1.replace(exp2, '$1<a target="_blank" href="http://$2">$2</a>'));
})
})

Sehdev
- 5,486
- 3
- 11
- 34
-
this creates the tag but it shows as it is in the description.For eg. Stich shrug at home in a very easy manner. You tube it should only show Youtube as a link but showing everything as a text – anonymous Mar 17 '20 at 06:26
-
-
I did not add anchor tag..the anchor tag is generated by the script you provided.This is what this shows as a simple text after submitting – anonymous Mar 17 '20 at 06:57
0
It is not possible to render HTML tags inside Textarea. It will treat it as a text. Either you make use of rich text editor or use div contenteditable.
Here is some more reference: Rendering HTML inside textarea

Anuj Shrestha
- 966
- 6
- 18
-
if used contenteditable you might need to add more JS to fetch the content and such.but the script provided by @Sehdev might able to handle your issue since contenteditable will render the anchor tag as proper link. – Anuj Shrestha Mar 17 '20 at 07:26
-
I have implemented the text editor summernote.It shows Html options while writing in the textarea and it changes according to the code but when it is submitted it shows the tags as
Stich shrug at home in a very easy manner. Great
– anonymous Mar 17 '20 at 07:58 -
Rich text editors use HTML and inline CSS to add the necessary designs. But if you are new to it I suggest that you research bit more about its security concerns, since `script` tag is also supported in it. I think summer-note has some options to disable the unnecessary options but you will need to sanitize the input before saving it to Database – Anuj Shrestha Mar 17 '20 at 09:10