html-to-json - Parses HTML strings into objects using flexible, composable filters.
Parses HTML strings into objects using flexible, composable filters.
$ sbt clean publish-local
Before running the tests the first time, you must ensure the npm packages are installed:
$ npm install
Then you can run the tests:
$ sbt test
import io.scalajs.JSON
import io.scalajs.jquery.JQueryElement
import io.scalajs.npm.htmltojson._
import scalajs.js
val content =
"""<div>
|<img src="http://some/server/image.jpg">
|<a href="/a/link/to/something">This is a link</a>
|This is a test
|</div>""".stripMargin
val linkParser = HtmlToJson.createParser(
js.Array("a[href]",
js.Dictionary(
"text" -> (($a: JQueryElement) => $a.text()),
"href" -> (($a: JQueryElement) => $a.attr("href"))
)))
println(s"linkParser = ${JSON.stringify(linkParser)}")
To add the HtmlToJson
binding to your project, add the following to your build.sbt:
libraryDependencies += "io.scalajs.npm" %%% "html-to-json" % "0.5.0"
Optionally, you may add the Sonatype Repository resolver:
resolvers += Resolver.sonatypeRepo("releases")