billthefarmer / MarkdownView

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

  • context - Context
  • attrs - AttributeSet
  void loadMarkdown(String text)
  void loadMarkdown(String text, String cssFileUrl)
  void loadMarkdown(String baseUrl, String text, String cssFileUrl)
  void loadMarkdown(String baseUrl, String text, String cssFileUrl, String jsFileUrl)

Parameters

  • text - markdown text
  • cssFileUrl - url of styles css file
  • baseUrl - base url to allow loading of images
  void loadMarkdownFile(String url)
  void loadMarkdownFile(String url, String cssFileUrl)
  void loadMarkdownFile(String baseUrl, String url, String cssFileUrl)
  void loadMarkdownFile(String baseUrl, String url, String cssFileUrl, String jsFileUrl)

Parameters

  • url - url of markdown text
  • cssFileUrl - url of styles css file
  • jsFileUrl - url of javascript file
  • baseUrl - base url to allow loading of images

About

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

License:Apache License 2.0


Languages

Language:Java 99.6%Language:CSS 0.3%Language:JavaScript 0.2%