1

In mygsp.gsp file, I have:

<div><markdown:renderHtml text="${infoText}"/>/div>

In myfile.groovy, I have:

 def infoText = "For further details. <http:\\www.myurl.com>"

The output gives a hyperlink to myurl.com within the same page, after the string "For further details."

How can I:

  1. Hyperlink "myurl.com" to render in a new page?

  2. Overwrite "For further details." to represent myurl.com?

I am aiming to achieve through groovy, what HTML would say:

  <a href="www.myurl.com". target="_/blank">For Further details</a> 
  • is this a trivialized example? according to e.g. http://stackoverflow.com/questions/4425198/markdown-target-blank it might not be possible (or maybe depending on your markdown renderer) to do it with a markdown syntax. it might requre postprocessing of the generated html - but if this is all there is to do, you might be better off to just parse the infoText, pass down text and uri and render without markdown. – cfrick Aug 27 '14 at 10:29
  • Yes I have trivialized my example. Is there a reason why groovy prevents it? Can the use of Java HTML as shown in this example be amended to the variable 'infoText' - http://stackoverflow.com/questions/4476861/using-hyperlinks-in-java-file – Bauhinia purpurea Aug 27 '14 at 12:53
  • it is not a problem with groovy nor grails, but with your markdown renderer. see, if it can be done there out of the box. if not you must postprocess the result (e.g. write your own tag, call renderHtml there and then adjust the generated html) – cfrick Aug 27 '14 at 13:00

2 Answers2

1

I found the answer to #2.

As per the markdown syntax here: daringfireball.net/projects/markdown/syntax#links ,

my code should say:

def infotext = ""[For further details] (http:\www.myurl.com) ""

And it worked!

0

I find that this line in my Groovy DSL Script will show the "Link Text" as a link to https://myurl.com in the example:

def sDescription = '''<a href="https://myurl.com">Link Text</a>'''