0

I have the following text:

<div>Answer the following <span class='title'>Question:</span><br> (a+b)<sup>2</sup>=?</div>

I want to do the following with this text:

  • parse it tag by tag, so that I can render each of the tag in a custom way. I could, very well, achieve that using this library: https://github.com/Thomas101/react-native-fence-html.
  • while parsing the superscript/subscript tags, render the content in proper fashion. This is where I'm stuck right now.

What I'm doing right now, is that I put the entire text (from start to end) in a Text component; and each span and br tags are also rendered as Text components nested within the parent Text component (the one for the div tag).
How do I render the superscript/subscript text?

Note: I did find a solution here: Superscript Text in React Native
But, creating a View inside a Text component needs the View to have fixed dimensions, and that is something not achievable.

Community
  • 1
  • 1
  • If you found a solution would be nice to share it. Nested view is not supported in Android, isn't it? – Max Jun 15 '17 at 07:36
  • @Max What I did end up doing was **render a webview with the html text** wherever required. In my application, there's not many instances where I need to do this, and hence, this works all right. However, for future use-cases like these, I guess, an in-built feature of RN to render html text in a Text/View component is required. – Anuraag Basu Jun 16 '17 at 10:17

1 Answers1

-1

One option would be to convert the HTML to Markdown first and then render the markdown. I believe for both of those actions there are libraries available.

Athaphian
  • 129
  • 7