diff --git a/.gitignore b/.gitignore index 0de5bfa..90b0368 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ # Created by .ignore support plugin (hsz.mobi) web/js/generated gradle.properties +local.properties diff --git a/build.gradle b/build.gradle index c1490e1..a25b5ca 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ group 'nl.astraeus' -version '0.1.0-SNAPSHOT' +version '0.1.1-SNAPSHOT' apply plugin: 'kotlin2js' apply plugin: 'kotlin-dce-js' diff --git a/src/main/kotlin/nl/astraeus/komp/KompElement.kt b/src/main/kotlin/nl/astraeus/komp/KompElement.kt index 09d3213..2accfcc 100644 --- a/src/main/kotlin/nl/astraeus/komp/KompElement.kt +++ b/src/main/kotlin/nl/astraeus/komp/KompElement.kt @@ -130,7 +130,7 @@ class KompElement( return type == ElementType.KOMPONENT } - fun create(): Node = when(type) { + fun create(svg: Boolean = false): Node = when(type) { ElementType.KOMPONENT -> { val komp = komponent @@ -154,7 +154,11 @@ class KompElement( } ElementType.TEXT -> document.createTextNode(text) ElementType.UNSAFE -> { - val div = document.createElement("div") + val div = if (svg) { + document.createElementNS("http://www.w3.org/2000/svg","svg") + } else { + document.createElement("div") + } var result: Node? = null div.innerHTML = text @@ -177,7 +181,12 @@ class KompElement( result ?: throw IllegalStateException("No element found in unsafe content! [$text]") } ElementType.TAG -> { - val result = document.createElement(text) + var svg = text == "svg" + val result = if (svg) { + document.createElementNS("http://www.w3.org/2000/svg", text) + } else { + document.createElement(text) + } (attributes?.entries)?.forEach { entry -> result.setAttribute(entry.key, entry.value) @@ -193,7 +202,7 @@ class KompElement( } children?.forEach { child -> - result.append(child.create()) + result.append(child.create(svg)) } result