Pine is a functional HTML5 and XML library for the Scala platform. It supports parsing, manipulating and rendering of HTML. Pine provides type-safe bindings for HTML5 generated from MDN. It implements an immutable tree which can be created directly from compile-time or runtime HTML/XML content. The tree may be manipulated and rendered back as HTML or as a browser node.
- Immutable and typed trees
- Type-safe bindings, generated from MDN
- Support for custom elements and attributes
- HTML5 and XML parser (recursive descent)
- Macros for compile-time HTML string/file parsing
- Tree manipulation
- Rendering as HTML strings
- DSL for common operations
- Unit and property-based tests
- Few dependencies
- Rendering as DOM nodes
- Updating nodes in DOM
- DSL for attaching/detaching events
Back end | Scala versions | Remarks |
---|---|---|
JVM | 2.11, 2.12 | Fully supported |
JavaScript | 2.11, 2.12 | Fully supported (1) |
LLVM | 2.11 | Experimental (2) |
- (1) Adds support for browser DOM
- (2) Presently, Scala Native does not support running ScalaTest/ScalaCheck test suites
import pine._
val url = "http://github.com/"
val root = html"<a href=$url>GitHub</a>"
println(root.toHtml) // <a href="http://github.com/">GitHub</a>
import pine.dom._
println(root.toDom) // [object HTMLAnchorElement]
Pine makes use of a language extension called literal types, see SIP-23. As of now, only Typelevel Scala implements this feature. However, it is likely to be included in future versions of Lightbend Scala (see this pull request).
scalaVersion := "2.12.2-bin-typelevel-4"
scalaOrganization := "org.typelevel"
scalacOptions += "-Yliteral-types"
addCompilerPlugin(
"org.scalamacros" % "paradise" % Paradise cross CrossVersion.patch)
libraryDependencies += scalaOrganization.value % "scala-reflect" % scalaVersion.value
libraryDependencies := libraryDependencies.value.filterNot(_.name == "scalajs-compiler")
addCompilerPlugin("org.scala-js" % "scalajs-compiler" % scalaJSVersion cross CrossVersion.patch)
libraryDependencies := libraryDependencies.value.filterNot(_.name == "nscplugin")
addCompilerPlugin("org.scala-native" % "nscplugin" % "0.2.1" cross CrossVersion.patch)
libraryDependencies += "tech.sparse" %% "pine" % "0.1.0" // JVM
libraryDependencies += "tech.sparse" %%% "pine" % "0.1.0" // JavaScript, LLVM
Pine is licensed under the terms of the Apache v2.0 licence.
- Tim Nieradzik
- Matt Hicks
- Anatoliy Kmetyuk