Hey,
would you be interested in adding the nl2br filter?
I would make a pr if you want.
My current implementation is:
class Nl2BrFilter : Filter {
private val newlineRegex = Regex("(\r\n|\r|\n)")
override fun apply(
input: Any?,
args: Map<String?, Any?>?,
self: PebbleTemplate?,
context: EvaluationContext?,
lineNumber: Int
): Any? {
if (input == null) {
return null
}
if (input !is String) {
throw IllegalArgumentException("nl2br filter only supports String input")
}
return input.replace(newlineRegex, "<br>")
}
override fun getArgumentNames(): List<String?>? {
return null
}
}
This is not what I would use I just did it because the implementation is easy.
In pebble I would not use regexs and loop through each char of the string.
Hey,
would you be interested in adding the
nl2brfilter?I would make a pr if you want.
My current implementation is:
This is not what I would use I just did it because the implementation is easy.
In pebble I would not use regexs and loop through each char of the string.