is there a cross platform way to describe markup? ...
# multiplatform
b
is there a cross platform way to describe markup? I've got JSON files which include something like:
Copy code
"description": "<p>Once you perform this action, <button>gain 3 gold</button> and one of the following:</p><ul><li>a ring</li><li>a staff</li></ul>"
I'm currently trying to figure out how to translate these strings while using them in an Android and web app
1
j
If your backend already does sanitization, you can just insert the string as raw
innerHTML
into a DOM node.
On Android it depends on the UI toolkit. There's a basic HTML parser which gives you a spanned
CharSequence
.
b
right, I was thinking of running it through JSoup at compile time
j
Not sure if Compose UI has an equivalent to that. I believe it's like
Html.fromHtml()
e
I think there might be a Compose UI equivalent
b
basically I need paragraphs, bold, buttons and lists
e
Before there was Compose support, my team built their own (I think using KSoup). Was challenging for lists, but everything else was pretty straightforward.
b
I tried to come up with a custom embeddable language like bb code (e.g. [button action=x]) but I found implementing a parser for a context free grammar to be quite exhausting
in the end it felt like re-implementing html
hm, I guess I could just use an HTML lib on android and construct ui components from the parsed DOM
e
Compose has AnnotatedString.fromHtml which I believe uses Android's Html underneath - it's not multiplatform