Last active
March 6, 2024 18:30
-
-
Save nickgrim/7a59115d4b249e31c1c2701b213742e7 to your computer and use it in GitHub Desktop.
Html.fromHtml() on Android Nougat shows different behaviour to that of Android Marshmallow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| I/TAG: opening: true, tag: html | |
| I/TAG: opening: true, tag: body | |
| I/TAG: opening: true, tag: ol | |
| I/TAG: opening: true, tag: li | |
| I/TAG: opening: false, tag: li | |
| I/TAG: opening: false, tag: ol | |
| I/TAG: opening: true, tag: ul | |
| I/TAG: opening: true, tag: li | |
| I/TAG: opening: false, tag: li | |
| I/TAG: opening: false, tag: ul | |
| I/TAG: opening: false, tag: body | |
| I/TAG: opening: false, tag: html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| I/TAG: opening: true, tag: html | |
| I/TAG: opening: true, tag: body | |
| I/TAG: opening: true, tag: ol | |
| I/TAG: opening: false, tag: ol | |
| I/TAG: opening: false, tag: body | |
| I/TAG: opening: false, tag: html |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package tag; | |
| import android.app.Activity; | |
| import android.os.Bundle; | |
| import android.text.Editable; | |
| import android.text.Html; | |
| import android.util.Log; | |
| import org.xml.sax.XMLReader; | |
| import java.util.Locale; | |
| public class TagHandlerActivity extends Activity { | |
| private static final String HTML = "<p>This is a paragraph. Below are some lists.</p>\n" + | |
| "<ol><li>Numbers</li></ol>\n" + | |
| "<ul><li>Bullets</li></ul>\n" + | |
| "<p>A trailing paragraph</p>"; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| Html.fromHtml(HTML, null, new LoggingTagHandler()); | |
| } | |
| private class LoggingTagHandler implements Html.TagHandler { | |
| @Override | |
| public void handleTag(boolean opening, String tag, Editable output, XMLReader xmlReader) { | |
| Log.i("TAG", String.format(Locale.US, "opening: %s, tag: %s", opening, tag)); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment