Giter VIP home page Giter VIP logo

dante's Introduction

Dante

Dante is a text parser to easily generate a Spannable from a raw input, right now it supports only HTML but the idea is to be able to support multiple input types (e.g., MarkDown).

Originally I authored Dante in Pause, the project is now dead and I decided to open source it.

This is the very first release of Dante, the api will (most likely) change for the better with successive iterations.

Installation

Simply add the following to your build.gradle:

repositories {
  jcenter()
}

dependencies {
  compile 'com.fourlastor:dante:1.0.1'
}

Usage with HTML

FlavoredHtml flavoredHtml = new FlavoredHtml.Builder(context)
  .newLine("p", "h1", "h2", "h3", "h4", "h5", "h6", "li")
  .textAppearance(R.style.headline, "h1")
  .textAppearance(R.style.title, "h2")
  .textAppearance(R.style.subhead, "h3")
  .textAppearance(R.style.body, "p", "li")
  .style(Typeface.BOLD, "b", "strong")
  .style(Typeface.ITALIC, "i", "em")
  .bullet(15, "li")
  .build();

Spanned styledHtml = flavoredHtml.parse(htmlString);

Keep in mind that this will be executed on the same thread on which flavoredHtml.parse() is executed. Since loading images might entail executing network requests, make sure you invoke flavoredHtml.parse() outside of the main thread if you are also loading images.

Loading images

You'll have to implement either ImgLoader to load images, if you need to load bitmaps (e.g., from the network) you can use ImgLoader.BitmapLoader:

FlavoredHtml flavoredHtml = new FlavoredHtml.Builder(context)
  .img(new ImgListener.BitmapImgGetter(getResources()) {
                      @Override
                      protected Bitmap getBitmap(String src) {
                          try {
                              return Picasso.with(MainActivity.this)
                                      .load(src)
                                      .get();
                          } catch (IOException e) {
                              throw new RuntimeException("Whoops!");
                          }
                      }
                  });

Keep in mind that this will be executed in the same thread in which flavoredHtml.parse() is executed, if you wish to execute network requests, do so invoking flavoredHtml.parse() outside of the main thread.

Different input types

As long as you implement Parser, it shouldn't be hard to support a different text style, see HtmlParser's implementation as a reference.

dante's People

Contributors

fourlastor avatar ultrah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dante's Issues

Fix tests

Tests are broken right now, gotta make them run again

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.