Reputation: 2574
I want use showdown.js library on my scalajs project.
How could I use scalajs to replace javascript code:
var converter = new showdown.Converter(),
text = '#hello, markdown!',
html = converter.makeHtml(text);
I have find a dependencies with jsDependencies += "org.webjars.bower" % "github-com-showdownjs-showdown" % "1.4.3" / "1.4.3/showdown.js" commonJSName "Showdown"
, but its not enough. Should I write a js.native binding to the library refer in scala.js document?
A example is welcome! Thanks
Upvotes: 0
Views: 170
Reputation: 22085
You should indeed write an @js.native
binding for the library, unless you find a published library that does it for you.
For the small example that you show, the binding would look like this:
@js.native
@JSGlobal("showdown.Converter")
class Converter extends js.Object {
def makeHtml(text: String): String = js.native
}
which then allows you to write
val converter = new Converter()
val text = "#hello, markdown!"
val html = converter.makeHtml(text)
Upvotes: 3