Created
August 19, 2021 07:23
-
-
Save ababup1192/56dc15d12a7b5db3e43d664f5e3a13f0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import Dependencies._ | |
ThisBuild / scalaVersion := "2.13.6" | |
ThisBuild / version := "0.1.0-SNAPSHOT" | |
ThisBuild / organization := "com.example" | |
ThisBuild / organizationName := "example" | |
lazy val root = (project in file(".")) | |
.settings( | |
name := "Scala Seed Project", | |
libraryDependencies ++= Seq( | |
scalaTest % Test, | |
"org.scala-lang.modules" %% "scala-xml" % "2.0.1" | |
) | |
) | |
// See https://www.scala-sbt.org/1.x/docs/Using-Sonatype.html for instructions on how to publish to Sonatype. |
This file contains hidden or 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 example | |
import scala.xml._ | |
import scala.xml.transform._ | |
object Hello extends App { | |
val xml = """ | |
|<root> | |
|<p><a href="http://[email protected]">abc</a></p> | |
|<p><a href="http://foo.com">abc</a></p> | |
|<h1> | |
| <p><a href="http://[email protected]">abc</a></p> | |
|</h1> | |
|</root> | |
""".stripMargin | |
val rule = new RuleTransformer(new RewriteRule { | |
override def transform(n: Node): NodeSeq = n match { | |
case e: Elem if (e \\ "p" \\ "a" \@ "href").contains("@") => | |
<p>{(e \\ "p" \ "a").text}</p> | |
case _ => n | |
} | |
}) | |
println(rule.transform(XML.loadString(xml))) | |
//<root> | |
//<p>abc</p> | |
//<p><a href="http://foo.com">abc</a></p> | |
//<h1> | |
// <p>abc</p> | |
//</h1> | |
//</root> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
abcefghi