Skip to content

Parses HTML strings into objects using flexible, composable filters.

License

Notifications You must be signed in to change notification settings

scalajs-io/html-to-json

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HtmlToJson API for Scala.js

html-to-json - Parses HTML strings into objects using flexible, composable filters.

Description

Parses HTML strings into objects using flexible, composable filters.

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.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)}")

Artifacts and Resolvers

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") 

About

Parses HTML strings into objects using flexible, composable filters.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages