Last active
December 15, 2015 16:59
-
-
Save eltimn/5293540 to your computer and use it in GitHub Desktop.
A lift Record Field for storing and converting Markdown. Uses Actuarius - https://github.com/chenkelmann/actuarius
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
package code.model | |
import scala.xml._ | |
import net.liftweb.util._ | |
import net.liftweb.common._ | |
import net.liftweb.http.S | |
import net.liftweb.record._ | |
import net.liftweb.record.field._ | |
import S._ | |
import Helpers._ | |
// https://github.com/chenkelmann/actuarius | |
import eu.henkelmann.actuarius._ | |
class NoVerbatimTransformer extends Transformer with Decorator { | |
override def deco = this | |
override def allowVerbatimXml: Boolean = false | |
} | |
trait MarkdownTypedField extends TextareaTypedField { | |
lazy val transformer = new NoVerbatimTransformer | |
override def asHtml: NodeSeq = valueBox | |
.flatMap { v => tryo(XML.loadString("<div>%s</div>".format(transformer(v)))) } | |
.openOr(<div>Error converting text to HTML</div>) | |
} | |
class MarkdownField[OwnerType <: Record[OwnerType]](rec: OwnerType, maxLength: Int) | |
extends StringField(rec, maxLength) with MarkdownTypedField | |
class OptionalMarkdownField[OwnerType <: Record[OwnerType]](rec: OwnerType, maxLength: Int) | |
extends OptionalStringField(rec, maxLength) with MarkdownTypedField |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment