https://kotlinlang.org logo
#compose-web
Title
# compose-web
j

javaru

01/27/2023, 9:24 PM
We need to use a non-standard unicode character from a custom font. When we try to use the escape sequence inside
Text()
, for example:
Text("")
, the resultant HTML has the ampersand escaped:

rather than showing the character. How can we use an HTML escape sequence either in a
Text()
or other element function?
a

Adam S

01/27/2023, 9:52 PM
I think to set raw content you have to use a disposable effect to access the scope element. This is used in the project to set the content of a code block to be some unescaped Kotlin code https://github.com/JetBrains/compose-jb/blob/5d18d0a79dd26a0d5880bdb8c0bb7b8870c9421b/examples/web-landing/src/jsMain/kotlin/com/sample/content/CodeSnippets.kt#L263-L266 although it’s better to use
textContent
instead of
innerText
j

javaru

01/27/2023, 11:18 PM
Thanks Adam. I gave that a try and couldn’t get it to work. It’s still escaping the
&
o

orangy

01/28/2023, 4:05 PM
Did you try using Kotlin unicode escape instead of HTML?
\uNNNN
j

javaru

01/30/2023, 1:48 PM
Thanks @orangy That worked. As soon as I read your answer, I was like 🤦 “of course”.
34 Views