I have the following code:
function strong(){
var element = document.getElementById("deco");
var value = element.textContent || "";
var regex = /\*([a-zA-Z\d\w\s]+)\*/gi;
value = value.replace(regex, "<strong>$1</strong>"); // STRONG
element.innerHTML = value;
} strong();
<p id="deco">
*It is a long established* fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution
</p>
The function it fulfills is to make the sentences enclosed in asterisks strong, but... How can I convert the sentences enclosed in (+) into a link? Example:
+https://www.miweb.com+ Convert it to a link like this: https://www.miweb.com
I have tried adding and replacing the JavaScript variables like this:
function strong(){
var element = document.getElementById("newsfordecostrong");
var value = element.textContent || "";
var regex = /\*([a-zA-Z\d\w\s]+)\*/gi; // STRONG
var link = /\+([a-zA-Z\d\w\s]+)\+/gi; // LINK
value = value.replace(regex, "<strong>$1</strong>"); // STRONG
value = value.replace(link, "<a href='$1'>$1</a>"); // LINK
element.innerHTML = value;
} strong();
But it doesn't work, if I'm doing something wrong or could improve, I'd appreciate your feedback and answers.
you can do it like this: