How to use scalatags for svg

137 views Asked by At

Trying to get scalatags to produce svg output.

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)  // works 
    println(svg(height := "3", width := "4").render)  // does not work: "Not found: svg"

What am I supposed to import instead of "import scalatags.vdom.SvgTags"? The documentation https://com-lihaoyi.github.io/scalatags/ does not help.

1

There are 1 answers

0
nemoo On

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
    )