0

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>

lifeisfoo
  • 15,478
  • 6
  • 74
  • 115
Sarit Rotshild
  • 391
  • 3
  • 5
  • 21

1 Answers1

0

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:

<myTagLib:replaceUrls>${direction?.description}</myTagLib:replaceUrls>

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.

Community
  • 1
  • 1
lifeisfoo
  • 15,478
  • 6
  • 74
  • 115