Weird Taghandler Behavior Detecting Opening And Closing Tags
Solution 1:
I solved this problem by adding to the beginning of the string "zero width joiner"
String looks like:
"‍<articlelink>text1</articlelink>padding<articlelink>text2</articlelink>"
In result textview, this symbol is not visible and text looks like the original string
Solution 2:
I have also encountered this issue while writing my custom TagHandler. This seems to me like an Android bug. Even though the question is old, because there isn't really much info on this issue out there, I will still post my solution... it may help someone.
The problematic case appears when the text starts with the HTML tag (at index 0), the callback to "handleTag()" with the closing flag will be triggered when processing reaches the end of the text.
My (kind of ugly) workaround for this problem was to use separate tags for opening and closing marks, like:
"<start>text1<end> padding<start>text2<end>"
Notice the "end" tag is not a closing one (it is not preceded by "/").
By doing this, you will need to change your logic in the handleTag() method, with the following general form:
publicvoidhandleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) {
if (tag.equalsIgnoreCase("start")) {
// Handle opening of your tag
} elseif (tag.equalsIgnoreCase("end")) {
// Handle closing of your tag
}
}
The boolean "opening" parameter is no longer needed, and also the output.length() will be correctly returned since the problem is only with the closing tag, which you won't be using.
Solution 3:
Ran into this issue as well, what seems to work is to wrap the text in <html>...</html>
tags. That way the html
tag will be the one that gets closed last anyway and the rest of the enclosed tags will work fine.
Post a Comment for "Weird Taghandler Behavior Detecting Opening And Closing Tags"