Skip to content

Instantly share code, notes, and snippets.

@eltimn
Last active December 15, 2015 16:59

Revisions

  1. eltimn revised this gist Apr 2, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion MarkdownTypedField.scala
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ class NoVerbatimTransformer extends Transformer with Decorator {
    override def allowVerbatimXml: Boolean = false
    }

    trait MarkdownTypedField extends TextareaTypedField with LiftExtras {
    trait MarkdownTypedField extends TextareaTypedField {
    lazy val transformer = new NoVerbatimTransformer

    override def asHtml: NodeSeq = valueBox
  2. eltimn revised this gist Apr 2, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions MarkdownTypedField.scala
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,7 @@ import net.liftweb.record.field._
    import S._
    import Helpers._

    // https://github.com/chenkelmann/actuarius
    import eu.henkelmann.actuarius._

    class NoVerbatimTransformer extends Transformer with Decorator {
  3. eltimn created this gist Apr 2, 2013.
    32 changes: 32 additions & 0 deletions MarkdownTypedField.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    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._

    import eu.henkelmann.actuarius._

    class NoVerbatimTransformer extends Transformer with Decorator {
    override def deco = this
    override def allowVerbatimXml: Boolean = false
    }

    trait MarkdownTypedField extends TextareaTypedField with LiftExtras {
    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