Created
April 20, 2016 17:05
-
-
Save longshorej/613831b3fc7aaf46e1cd71da67cda26f to your computer and use it in GitHub Desktop.
scala nl2br with scalatags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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