Giter Site home page Giter Site logo

htmlcompat's Introduction

HtmlCompat

Compatibility library for Android's Html class.

Why?

Nougat introduced improvements to the Html class for converting HTML to spannables. Unfortunately, these new features lay within the Android SDK itself. This means that the behavior in which HTML is converted is subject to the version of Android that the user is running.

HtmlCompat attempts to address this problem by providing developers with a compatibility library. All logic for converting HTML is enclosed within this library and can be bundled within an app. This means that the presentation is agnostic to the version of Android of the device.

How can I use it?

Gradle:

compile 'com.pixplicity.htmlcompat:library:1.0.0'

Java:

Spanned fromHtml = HtmlCompat.fromHtml(context, source, 0);
// You may want to provide an ImageGetter, TagHandler and SpanCallback:
//Spanned fromHtml = HtmlCompat.fromHtml(context, source, 0,
//        imageGetter, tagHandler, spanCallback);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setText(fromHtml);

What’s supported?

All the latest functionality from the current Html for Android Nougat is included in this library. While this may continue to be improved in the future, currently, the following tags are supported out of the box:

  • <br>
  • <p>
  • <ul>
  • <li>
  • <div>
  • <span>
  • <strong>, <b>
  • <em>, <i>
  • <u>
  • <s>, <strike>, <del>
  • <cite>
  • <dfn>
  • <big>
  • <small>
  • <font>
  • <blockquote>
  • <tt>
  • <a>
  • <sup>
  • <sub>
  • <h1>, <h2>, <h3>, <h4>, <h5>, <h6>
  • <img>

The following CSS inline styles are supported:

  • text-align
  • color
  • background, background-color
  • text-decoration

All CSS color declarations as defined here are supported.

What’s added?

A few new features have been added to the interface to ease the life of the developer:

  • Callbacks into ImageGetter and TagHandler provide the tag attributes;
  • SpanCallback can be registered so the implementor may be informed of new spans; this allows for spans to be modified;
  • All CSS color declarations have been added.

What’s next?

We’re looking to support more tags and styles in future releases. Feel free to contribute with pull requests or by reporting issues on the GitHub project page.

Made with ❤ by Pixplicity

htmlcompat's People

Contributors

pflammertsma avatar colinrtwhite avatar

Watchers

Alp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.