Skip to content

Instantly share code, notes, and snippets.

@BlackPrincess
Created September 19, 2013 06:20
Show Gist options
  • Select an option

  • Save BlackPrincess/6619685 to your computer and use it in GitHub Desktop.

Select an option

Save BlackPrincess/6619685 to your computer and use it in GitHub Desktop.
Play2 nlbr
import org.specs2.mutable._
class HelperSpec extends Specification {
"nlbr" should {
"newline character will be <br />" in {
views.html.helper.nlbr("foo\nbar").toString must contain ("<br />")
views.html.helper.nlbr("foo\r\nbar").toString must contain ("<br />")
views.html.helper.nlbr("foo\rbar").toString must contain ("<br />")
}
"Html should be escaped" in {
views.html.helper.nlbr("<h1>hoge</h1>").toString must not contain ("<h1>")
}
}
}
@**
* Convert Multi-line text to Html
*
* @param text text
*@
@(text:String)
@Html(text.split("[\n\r(\r\n)]").toSeq.map(HtmlFormat.escape).mkString("<br />"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment