Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add function to add raw SVG elements #13

Open
NikkyAI opened this issue Feb 8, 2022 · 0 comments
Open

add function to add raw SVG elements #13

NikkyAI opened this issue Feb 8, 2022 · 0 comments

Comments

@NikkyAI
Copy link
Contributor

NikkyAI commented Feb 8, 2022

having the option to insert "raw" child elements from string would be convenient

example:

fun generateSVG(
    shapeViewBox: String = "0 0 100 100",
    shapeContent: String = """<path d="M0 13.3333C0 5.96954 5.96954 0 13.3333 0H86.6667C94.0305 0 100 5.96954 100 13.3333V86.6667C100 94.0305 94.0305 100 86.6667 100H13.3333C5.96954 100 0 94.0305 0 86.6667V13.3333Z" fill="currentColor"/>"""
): String {
    val svg = SVG.svg {
        /* ...*/
        children += SVG.svg {
            id = "shape"
            width = "100%"
            height = "100%"
            attributes["x"] = "0"
            attributes["y"] = "0"
            viewBox = shapeViewBox
            body = "replace_shape"
        }
    }
    return buildString {
        svg.render(this, RenderMode.INLINE)
    }.replace("replace_shape", "\n" +shapeContent + "\n")
}

i recently came across a problem in which i was given raw svg paths and viewport of a SVG and had to assemble nested SVGs out of them

i solved it by assigning a "replace_thing" value to tthe body of the nested SVGs and did some string manipulation on the rendered output

regardless.. a nicer api would make this type of problem easier to solve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant