This has probably been done to death, but here’s my version of how to “HTML-ify” HTML text in SharePoint calculated fields into rendered HTML using jQuery:
|
<span style="font-family: Lucida Console,monospace;"><span style="color: #4d70ea;">var </span><span style="color: #e87400;">htmlPattern = /[^<]*<([^ ]+)[^<]+<\/\1>.*/;</span> <span style="color: #4d70ea;">var </span><span style="color: #e87400;">ltPattern = /&lt;/g;</span> <span style="color: #4d70ea;">var </span><span style="color: #e87400;">gtPattern = /&gt;/g;</span></span> <span style="font-family: Lucida Console,monospace;"><span style="color: #e87400;">$(selectors).each(</span><span style="color: #4d70ea;">function</span><span style="color: #e87400;">(index, item){</span> <span style="color: #4d70ea;">var </span><span style="color: #e87400;">html = $(item).html().replace(ltPattern, </span><span style="color: #a56dbc;">"<"</span><span style="color: #e87400;">).replace(gtPattern, </span><span style="color: #a56dbc;">">"</span><span style="color: #e87400;">);</span></span> <span style="font-family: Lucida Console,monospace;"> <span style="color: #4d70ea;">if</span><span style="color: #e87400;">(!htmlPattern.test(html)) { </span><span style="color: #4d70ea;">return</span><span style="color: #e87400;">; }</span></span> <span style="font-family: Lucida Console,monospace;"> <span style="color: #e87400;">$(item).html(html);</span> <span style="color: #e87400;">});</span></span> |
Perhaps the most interesting part of this script is the regular expression used...