Reputation: 329
I use this code to convert the text of edittext to html
String html = Html.toHtml(edittext.getText);
But it keeps nesting tags. That's not my problem. But I don't want to nest some specific tags like <img>
For example, this is the text of EditText:
Hello how are you?
[Here's an image.]
Expected result:
<p dir="ltr">Hello how are you</p>
<img src="path/to/image">
But it gives me this:
<p dir="ltr">Hello how are you<br> <img src="path/to/image"> </p>
I don't want that <img>
tag gets nested in the the <p>
. Because I couldn't show the image later.
I just need to avoid only <img>
gets nested. Not other tags.
Upvotes: 1
Views: 67
Reputation: 59
You can split the string before converting it by delimiter:
String getHtml = "<p dir="ltr">Hello how are you</p> <img src="path/to/image">";
String[] splitElements = getHtml.split("</p>");
And after that, you can pass both strings and convert those. They will be separate and non-nested.
Upvotes: 1