Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Formatting issue #78

Closed
vijaykd opened this issue Dec 15, 2016 · 5 comments
Closed

Formatting issue #78

vijaykd opened this issue Dec 15, 2016 · 5 comments

Comments

@vijaykd
Copy link

vijaykd commented Dec 15, 2016

Hi,

This is really great library. Thanks for making it.
I have formatting issue when showing my HTML.

HTML line has:

<p>Heading &amp; Details are here</p>
                                                                 <ul>
                                                                 <li>db connection Error:An existing connection was forcibly closed by the remote host 10:54:23 Connection attempts: 1</li>
                                                                 <li>Point 2</li>
                                                                 <li>Point 3</li>
                                                                 <li>Point 4</li>
                                                                 <li>Point 5</li>
                                                                 <li>Point 6</li>
                                                                 </ul>

The formatting is not that great: Any idea on why?

image

Screen shot above is from Nexus 5X.

The code used:

HtmlTextView hv = new HtmlTextView(Activity_New.this);
                            hv.setX(40);
                            hv.setHtml(htmldescription);
                           alert.setView(hv);

I am not in a situation to use the web view hence I was looking for textFieldHTML solution.

Can you let me know what could be wrong?

@kevinvanmierlo
Copy link

@vijaykd I've just now bumped in to the same issue, but it's not the fault of this library. In the new version of Html.fromHtml (which this library uses) they also included the ul en li tag, but as you can see it doesn't look good at all. No clue how to fix this issue though, still working on it myself

@DevGary
Copy link
Contributor

DevGary commented Dec 16, 2016

You can fix it by replacing the tag labels with your own strings before passing it into Html.fromHtml() like so:

public static final String UNORDERED_LIST = "ESCAPED_UL_TAG";
public static final String ORDERED_LIST = "ESCAPED_OL_TAG";
public static final String LIST_ITEM = "ESCAPED_LI_TAG";

public static String overrideTags(@Nullable String html){

    if (html == null) return null;

    html = html.replace("<ul", "<" + UNORDERED_LIST);
    html = html.replace("</ul>", "</" + UNORDERED_LIST + ">");
    html = html.replace("<ol", "<" + ORDERED_LIST);
    html = html.replace("</ol>", "</" + ORDERED_LIST + ">");
    html = html.replace("<li", "<" + LIST_ITEM);
    html = html.replace("</li>", "</" + LIST_ITEM + ">");

    return html;
}

Then those tags will not be recognized by the default tag handler and will be passed to this library's tag handler. You then have to edit this library's HtmlTagHandler and replace all the instances where it tries to match the tags "ol", "ul', "li" with your corresponding overridden string.

@dschuermann
Copy link
Member

@xGary this is an awesome idea for a fix! Can you make a pull request that in-cooperates this into the library? I would definitely merge this.

@DevGary
Copy link
Contributor

DevGary commented Dec 17, 2016

@dschuermann Done #79

@dschuermann
Copy link
Member

release in 3.1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants