kinsell
kinsell

Reputation: 358

Remove HTML from a String and showing the Gists inside the script tags - Android

Trying to display the Github Gists from a String in a TextView. When I clean the String from the HTML with 'Html.fromHtml()' -->

<p>Lorem ipsum dolor sit <a href="http://Lorem ipsum.com/Lorem ipsum dolor sit amet">amet</a>,</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam ultrices lorem scelerisque year&#8217;s Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam ultrices lorem scelerisque<br />
</p>
<p>Interdum et malesuada fames ac ante ipsum primis in faucibus</p>
<p><script src="https://gist.github.com/LoremIpsum/d3c4dff75f555a54aa0f.js"></script>Donec ac ultrices elit. Curabitur elementum pulvinar augue a congue. Phasellus in quam ligula.<script src="https://gist.github.com/dolorSitAmet/53ae35ddd74bb0837c12.js"></script></p>
* I get the same result as when running the code snippet.

How can I show the Gists like in the picture below: enter image description here

Upvotes: 2

Views: 212

Answers (2)

B&#246; macht Blau
B&#246; macht Blau

Reputation: 13019

As the official documentation tells us, the Html.fromHtml() method

Returns displayable styled text from the provided HTML string

Unfortunately, the reference is a bit vague about which HMTL tags are supported. I searched around a bit, and the source code at grepcode.com shows that the <script> tag is not evaluated.

So the answer to your question is: with a TextView, you can't. Use a WebView instead. Click this link for a short introduction.

Upvotes: 1

Hari Krishnan
Hari Krishnan

Reputation: 6312

textView.setText(Html.fromHtml(htmlCode));

It will do your job.

Upvotes: 0

Related Questions