Markdown is a popular markup language for wikitext and the like. While there are Java-based Markdown processors available, these are likely to be slow on Android, where they run at all.
This project offers an Android-compliant wrapper around sundown, a C-based Markdown parser and HTML generator. By using the NDK with this C library, parsing speeds are nice and fast -- 5K of input can be converted into HTML in about 1 millisecond. Also, sundown is a fairly popular Markdown processor and is the brains behind GitHub-flavored Markdown.
Option #1: Clone the repository and add it as an Android library project to your
application. You will also need to install the NDK and run
from the project root directory, in order to build the
Option #2: UnZIP the ZIP file found in the Downloads area of this site into
libs/ directory of your project. This only works for ARM targets, and
this has been very lightly tested.
Create an instance of
com.commonsware.cwac.anddown.AndDown, then call
markdownToHtml() on it, supplying
String containing your Markdown source. This method returns a
containing HTML generated from that source.
And, that's pretty much it, at least at this time.
There is no statefulness in the
AndDown object. It should be reusable
without having to create a fresh instance each time. It might even
be thread-safe, though this has not been tested.
The Markdown spec says that Markdown converted to HTML should use
<strong> tags. On most browsers, those map to italics and
boldface, respectively. However, the
Html.fromHtml() method in Android
that creates a
SpannedString from HTML source flips those, so what you
might be used to seeing in boldface turns into italics and vice-versa.
This should only be an issue if you are displaing the Markdown-generated
HTML in a
WebView in particular should behave more
Also, while sundown is very fast, using the resulting HTML will inevitably
be slower. The same 5K sample file that sundown processes in about 1
millisecond takes a few hundred milliseconds to convert into a
The author of this project is a complete klutz when it comes to C/JNI/NDK development. You have been warned.
This project has no dependencies. This repository includes a copy of the relevant files from the sundown project.
This is version v0.1 of this module, which means it is really new. Moreover, it is the first CWAC project incorporating the NDK, so there may be new and exiciting issues as a result.
demo/ sub-project you will find
a sample activity that demonstrates the use of
AndDown, loading the
sundown README out of a raw resource and displaying it in a
wrapped in a
Future editions of this project will add things like:
- a custom sundown renderer that generates a
SpannedStringdirectly, bypassing HTML
- code to convert a
SpannedStringback into Markdown source
The code in this project is licensed under the Apache Software License 2.0, per the terms of the included LICENSE file.
The sundown source code is available under its own license, which appears to be a modified BSD license.
If you have questions regarding the use of this code, please post a question
on StackOverflow tagged with
android. Be sure to indicate
what CWAC module you are having issues with, and be sure to include source code
and stack traces if you are encountering crashes.
v0.1.0: initial release