Skip to content

Latest commit

 

History

History
75 lines (53 loc) · 1.65 KB

README.md

File metadata and controls

75 lines (53 loc) · 1.65 KB

HtmlParser2 API for Scala.js

htmlparser2 - Fast & forgiving HTML/XML/RSS parser.

Description

A forgiving HTML/XML/RSS parser. The parser can handle streams and provides a callback interface.

Build Dependencies

Build/publish the SDK locally

$ sbt clean publish-local

Running the tests

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

Examples

  import io.scalajs.nodejs.console
  import io.scalajs.npm.htmlparser2._
  import scala.scalajs.js
  
  val parser = new Parser(
    new ParserHandler {

      override def onopentag(name: String, attribs: js.Dictionary[String]) {
        if (name == "script" && attribs("type") == "text/javascript") {
          console.log("JS! Hooray!")
        }
      }

      override def ontext(text: String): Unit = console.log("-->", text)

      override def onclosetag(tagname: String) {
        if (tagname == "script") {
          console.log("That's it?!")
        }
      }
    },
    new ParserOptions(decodeEntities = true)
  )
  parser.write("Xyz <script type='text/javascript'>var foo = '<<bar>>'</script>")
  parser.end()

Artifacts and Resolvers

To add the HtmlParser2 binding to your project, add the following to your build.sbt:

libraryDependencies += "io.scalajs.npm" %%% "htmlparser2" % "0.5.0"

Optionally, you may add the Sonatype Repository resolver:

resolvers += Resolver.sonatypeRepo("releases")