Fix SVG images in raw HTML
authorLanius Trolling <lanius@laniustrolling.dev>
Sun, 28 Apr 2024 15:26:56 +0000 (11:26 -0400)
committerLanius Trolling <lanius@laniustrolling.dev>
Sun, 28 Apr 2024 15:26:56 +0000 (11:26 -0400)
src/jvmMain/kotlin/info/mechyrdia/lore/ParserHtml.kt
src/jvmMain/kotlin/info/mechyrdia/lore/ParserRaw.kt

index 17e67f40b36fe307c8e8bf80c2cc2d3e0dfcda3a..0975c943f7e5b69338f3ed1a94fe71ce718d859b 100644 (file)
@@ -302,7 +302,7 @@ class HtmlHeaderLexerTag(val tagCreator: TagCreator, val anchor: (String) -> Str
        }
 }
 
-fun repeatColorDigits(color: String) = when (color.length) {
+private fun repeatColorDigits(color: String) = when (color.length) {
        6 -> color
        3 -> {
                val (r, g, b) = color.toCharArray()
index 0356bca2479639f74c0689aaee41e6456a9ad891..afdf692ffb54cc896dc39cd6bc4d07623f9ff303 100644 (file)
@@ -92,13 +92,23 @@ enum class RawFactbookFormattingTag(val type: HtmlLexerTag) {
                val (width, height) = getSizeParam(param)
                val styleValue = getRawImageSizeStyleValue(width, height)
                
-               ({
-                       img(src = "/assets/images/$url") {
-                               width?.let { attributes["data-width"] = "$it" }
-                               height?.let { attributes["data-height"] = "$it" }
-                               style = styleValue
-                       }
-               })
+               if (url.endsWith(".svg"))
+                       ({
+                               iframe {
+                                       src = "/assets/images/$url"
+                                       width?.let { attributes["data-width"] = "$it" }
+                                       height?.let { attributes["data-height"] = "$it" }
+                                       style = styleValue
+                               }
+                       })
+               else
+                       ({
+                               img(src = "/assets/images/$url") {
+                                       width?.let { attributes["data-width"] = "$it" }
+                                       height?.let { attributes["data-height"] = "$it" }
+                                       style = styleValue
+                               }
+                       })
        }),
        MODEL(HtmlNotSupportedInRawViewTag("Unfortunately, raw view does not support interactive 3D model views")),
        QUIZ(HtmlNotSupportedInRawViewTag("Unfortunately, raw view does not support interactive quizzes")),