PageRenderTime 5ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/wheels/view/sanitize.cfm

http://cfwheels.googlecode.com/
ColdFusion | 36 lines | 34 code | 2 blank | 0 comment | 1 complexity | 7cadf2e3e552c2fef2af36ed7f3be44b MD5 | raw file
Possible License(s): Apache-2.0, CPL-1.0
  1. <cffunction name="stripLinks" returntype="string" access="public" output="false" hint="Removes all links from an HTML string, leaving just the link text."
  2. examples=
  3. '
  4. ##stripLinks("<strong>Wheels</strong> is a framework for <a href="http://www.adobe.com/products/coldfusion/">ColdFusion</a>.")##
  5. -> <strong>Wheels</strong> is a framework for ColdFusion.
  6. '
  7. categories="view-helper,sanitize" functions="stripTags,h">
  8. <cfargument name="html" type="string" required="true" hint="The HTML to remove links from.">
  9. <cfreturn REReplaceNoCase(arguments.html, "<a.*?>(.*?)</a>", "\1" , "all")>
  10. </cffunction>
  11. <cffunction name="stripTags" returntype="string" access="public" output="false" hint="Removes all HTML tags from a string."
  12. examples=
  13. '
  14. ##stripTags("<strong>Wheels</strong> is a framework for <a href="http://www.adobe.com/products/coldfusion/">ColdFusion</a>.")##
  15. -> Wheels is a framework for ColdFusion.
  16. '
  17. categories="view-helper,sanitize" functions="stripLinks,h">
  18. <cfargument name="html" type="string" required="true" hint="The HTML to remove tag markup from.">
  19. <cfset var returnValue = "">
  20. <cfset returnValue = REReplaceNoCase(arguments.html, "<\ *[a-z].*?>", "", "all")>
  21. <cfset returnValue = REReplaceNoCase(returnValue, "<\ */\ *[a-z].*?>", "", "all")>
  22. <cfreturn returnValue>
  23. </cffunction>
  24. <cffunction name="h" returntype="string" access="public" output="false" hint="Escapes unsafe HTML. Alias for your CFML engine's `XMLFormat()` function."
  25. examples=
  26. '
  27. ##h("<b>This "is" a test string & it should format properly</b>")##
  28. -> &lt;b&gt;This &quot;is&quot; a test string &amp; it should format properly&lt;/b&gt;
  29. '
  30. categories="view-helper,sanitize" functions="stripLinks,stripTags">
  31. <cfargument name="content" type="string" required="true">
  32. <!--- you can't use argumentCollection --->
  33. <cfreturn $htmlFormat(arguments.content)>
  34. </cffunction>