billthefarmer / MarkdownView

Android markdown view forked from https://github.com/falnatsheh/MarkdownView
Apache License 2.0
11 stars 2 forks source link
android-markdown markdownview

Logo MarkdownView .github/workflows/build.yml

Android markdown view forked from https://github.com/falnatsheh/MarkdownView

Markdown

About

MarkdownView is an Android library that helps you display Markdown text or files (local/remote) as formatted HTML, and style the output using CSS.

The MarkdownView itself extends Android WebView and adds the necessary logic to parse Markdown (using Commonmark) and display the output HTML on the view.

Getting started

To add MarkdownView to your project, add the following to the build.gradle file:

allprojects {
    repositories {
        jcenter()
        google()
        maven { url "https://jitpack.io" }
    }
}

dependencies {
    implementation 'com.github.billthefarmer:MarkdownView:v1.09'
}

Usage

Add MarkdownView to your layout:

  <org.billthefarmer.markdown.MarkdownView
    android:id="@+id/markdown"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

and reference it in your Activity/Fragment:

MarkdownView markdownView = (MarkdownView) findViewById(R.id.markdown);
markdownView.loadMarkdown("## Hello Markdown");

You could also create the view by code. Below an example of how to set the whole activity to be a MarkdownView by adding the following to your onCreate method:

  MarkdownView markdownView = new MarkdownView(this);
  setContentView(markdownView);
  markdownView.loadMarkdown("## Hello Markdown");

To load markdown from the app assets folder, including styles, javascript and base url:

  markdownView.loadMarkdownFile("file:///android_assets/",
                                "file:///android_assets/markdown.md",
                                "file:///android_assets/styles.css",
                                "file:///android_assets/javascript.js");

API

  MarkdownView(Context context)
  MarkdownView(Context context, AttributeSet attrs)

Parameters