All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.taig.backmail.PlaintextPrinter.scala Maven / Gradle / Ivy

The newest version!
package io.taig.backmail

object PlaintextPrinter extends Printer:
  override def print(email: Message): String = email.body.map(print).mkString

  def print(template: Template): String = template match
    case Template.Alert(children, _) => "***\n" + children.map(print).mkString + "\n***"
    case Template.Block(children, paragraph) =>
      children.map(print).mkString + (if paragraph then "\n\n" else "")
    case Template.Button(children, href) =>
      val target = href.toList.map(apply).mkString
      val label = children.map(print).mkString
      s"$label: $target"
    case Template.Headline(children) => s"${children.map(print).mkString}\n\n"
    case Template.Linebreak          => "\n"
    case Template.Link(children, href) =>
      val target = href.toList.map(apply).mkString
      val label = children.map(print).mkString
      s"$label ($target)"
    case Template.Space          => "\n\n"
    case Template.Text(children) => children.map(apply).mkString

  def apply(value: Value): String = value match
    case Value.Plain(value)  => value
    case Value.Secret(value) => value




© 2015 - 2025 Weber Informatics LLC | Privacy Policy