All Projects → fourlastor → Dante

fourlastor / Dante

Licence: mit
A sane rich text parsing and styling library.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Dante

richvariables
DEPRECATED Allows you to easily use Craft Globals as variables in Rich Text fields
Stars: ✭ 44 (-90.22%)
Mutual labels:  rich-text
Text
📑 Collaborative document editing using Markdown
Stars: ✭ 282 (-37.33%)
Mutual labels:  rich-text
Bearparser
Portable Executable parsing library (from PE-bear)
Stars: ✭ 415 (-7.78%)
Mutual labels:  parser-library
html2any
🌀 parse and convert html string to anything
Stars: ✭ 43 (-90.44%)
Mutual labels:  rich-text
booleval
Header-only C++17 library for evaluating logical expressions.
Stars: ✭ 54 (-88%)
Mutual labels:  parser-library
Attributedstring
基于Swift插值方式优雅的构建富文本, 支持点击长按事件, 支持不同类型过滤, 支持自定义视图等.
Stars: ✭ 294 (-34.67%)
Mutual labels:  rich-text
unity-rich-text
🌈 Forget about rich text tags pain
Stars: ✭ 14 (-96.89%)
Mutual labels:  rich-text
Slate
A completely customizable framework for building rich text editors. (Currently in beta.)
Stars: ✭ 23,104 (+5034.22%)
Mutual labels:  rich-text
Dart Petitparser
Dynamic parser combinators in Dart.
Stars: ✭ 266 (-40.89%)
Mutual labels:  parser-library
Mercury Parser
📜 Extract meaningful content from the chaos of a web page
Stars: ✭ 4,025 (+794.44%)
Mutual labels:  parser-library
richTextParse
微信小程序富文本解析(仅支持HTML),在rich-text标签引用结果“树”
Stars: ✭ 53 (-88.22%)
Mutual labels:  rich-text
microparsec
⭐ A performant Nim parsing library built for humans.
Stars: ✭ 26 (-94.22%)
Mutual labels:  parser-library
Hricheditor
Android端富文本编辑器HEichEditor
Stars: ✭ 311 (-30.89%)
Mutual labels:  rich-text
tanto
C json parser and creator library.
Stars: ✭ 21 (-95.33%)
Mutual labels:  parser-library
Angular Editor
A simple native WYSIWYG editor component for Angular 6 -10+
Stars: ✭ 428 (-4.89%)
Mutual labels:  rich-text
leftry
Leftry - A left-recursion enabled recursive-descent parser combinator library for Lua.
Stars: ✭ 32 (-92.89%)
Mutual labels:  parser-library
Spedittool
An efficient and scalable library for inputing and displaying gif or @mention on graph-text mixed TextView/EditText
Stars: ✭ 292 (-35.11%)
Mutual labels:  rich-text
Nudein
An easy-to-use attributed text view for iOS Apps,use like masonry
Stars: ✭ 450 (+0%)
Mutual labels:  rich-text
Biojava
📖🔬☕️ BioJava is an open-source project dedicated to providing a Java library for processing biological data.
Stars: ✭ 434 (-3.56%)
Mutual labels:  parser-library
Kgt
BNF wrangling and railroad diagrams
Stars: ✭ 312 (-30.67%)
Mutual labels:  parser-library

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].