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

teststate.domzipper.HtmlScrub.scala Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
package teststate.domzipper

/**
 * Arbitrary preprocessor that [[DomZipper]] applies before returning any HTML text.
 */
case class HtmlScrub(run: String => String) {
  def >>(that: HtmlScrub): HtmlScrub =
    HtmlScrub(run andThen that.run)

  def <<(that: HtmlScrub): HtmlScrub =
    that >> this
}

object HtmlScrub {

  def replaceAll(regex: String, replacement: String): HtmlScrub = {
    val r = regex.r
    HtmlScrub(r.replaceAllIn(_, replacement))
  }

  def empty: HtmlScrub =
    HtmlScrub(identity)

  val removeComments: HtmlScrub =
    replaceAll("", "")

  def default = removeComments
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy