I have the following gsp code:
<p class="common-text ">${direction?.description?.toHtml()?.decodeHTML()}</p>
direction?.description
is a text which the user entered in some input field. This text could includes website URLs like Visit my new site www.example.com
How can I verified if some of the text contains a URL, and if so display it as hyperlink?
The text above should be transformed to something like:
Visit my new site <a href="www.example.com"> www.example.com </a>
You have two way to do this.
Server side with a Grails taglib
You could create a custom Grails taglib that look for URLs in your text and replace with
<a>
tags when needed. It could be used like this:Client side with javascript
You can use a javascript library to search URLs in strings and then auto replace them with the proper hyperlink. See this question for more information about this techinque.