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

com.mchange.sysadmin.taskrunner.htmlutil.scala Maven / Gradle / Ivy

There is a newer version: 0.1.4
Show newest version
package com.mchange.sysadmin.taskrunner

import org.jsoup.Jsoup // to verify and pretty-print HTML mail
import org.jsoup.parser.*

import scala.jdk.CollectionConverters.*

case class StepRunMaybeIndexed( run : AnyStepRun, mbIndex : Option[Int])

def colorClass( run : AnyStepRun ) = run match
  case completed : AnyStepRunCompleted =>
    if completed.success then "success" else "failure"
  case skipped : AnyStepRunSkipped =>
    "skipped"

def mbLabeledText( mlt : Option[Tuple2[HtmlSafeText,HtmlSafeText]]) : String =
  mlt match
    case Some( tup ) => labeledText( tup ).text
    case None        => ""

def labeledTextOrNA( label : HtmlSafeText, mbText : HtmlSafeText ) : String =
  if mbText.nonEmpty then
    labeledText( Tuple2(label,mbText) ).text
  else
    s"""
${label}: N/A
""" def prettyPrintHtml( rawHtmlText : String ) : String = Jsoup.parse( rawHtmlText ).html() def debugPrettyPrintHtml( rawHtmlText : String ) = val parser = new Parser(new HtmlTreeBuilder()) parser.setTrackErrors(100) parser.setTrackPosition(true) val doc = parser.parseInput(rawHtmlText,"./") parser.getErrors().asScala.foreach( err => System.err.println("[debug] Output HTML Parse Error: " + err) ) doc.html()




© 2015 - 2025 Weber Informatics LLC | Privacy Policy