com-lihaoyi / scalatags

ScalaTags is a small XML/HTML construction library for Scala.
https://com-lihaoyi.github.io/scalatags/
MIT License
757 stars 117 forks source link

Usage question: How to use svg #251

Closed nemoo closed 1 year ago

nemoo commented 1 year ago

I cannot get svg support to run with scala 3.

How to reproduce in scala-cli: This snippet gives me an error "Not found: svg"

//> using scala "3"
//> using lib "com.lihaoyi::scalatags:0.12.0"

import scalatags.Text.all._
import scalatags.vdom.SvgTags

@main def go() =
    println(html(div("")).render)  
    println(svg(height := "3", width := "4").render)

What am I supposed to import instead of "import scalatags.vdom.SvgTags"?

nemoo commented 1 year ago

Got it to run thanks to the com-lihaoyi discord channel. To include also a svg rect, I had to use these three imports:

//> using lib "com.lihaoyi::scalatags:0.12.0"

import scalatags.Text.svgTags.*
import scalatags.Text.svgAttrs.*
import scalatags.Text.implicits.intAttr

@main def go() =
    println(
        svg(
            height := 3, 
            width := 4, 
            rect( 
                x := 1,
                y := 1,
                width := 1,
                height := 1
                )
        ).render
    )