Skip to content

Instantly share code, notes, and snippets.

@longshorej
Created April 20, 2016 17:05
Show Gist options
  • Save longshorej/613831b3fc7aaf46e1cd71da67cda26f to your computer and use it in GitHub Desktop.
Save longshorej/613831b3fc7aaf46e1cd71da67cda26f to your computer and use it in GitHub Desktop.
scala nl2br with scalatags
import scalatags.Text.all._
object nl2br {
def apply(s: String): Modifier = {
val lines = s.replaceAllLiterally("\r\n", "\n").replaceAllLiterally("\r", "\n").split('\n')
lines.foldLeft(None: Option[Modifier]) { case (step, line) =>
Some(step.fold[Modifier](line)(previous => Vector[Modifier](previous, br, line)))
}.getOrElse("")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment