项目作者: billthefarmer

项目描述 :
Android markdown view forked from https://github.com/falnatsheh/MarkdownView
高级语言: Java
项目地址: git://github.com/billthefarmer/MarkdownView.git
创建时间: 2017-06-06T13:10:31Z
项目社区:https://github.com/billthefarmer/MarkdownView

开源协议:Apache License 2.0

下载


MarkdownView " class="reference-link">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:

  1. allprojects {
  2. repositories {
  3. jcenter()
  4. google()
  5. maven { url "https://jitpack.io" }
  6. }
  7. }
  8. dependencies {
  9. implementation 'com.github.billthefarmer:MarkdownView:v1.09'
  10. }

Usage

Add MarkdownView to your layout:

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

and reference it in your Activity/Fragment:

  1. MarkdownView markdownView = (MarkdownView) findViewById(R.id.markdown);
  2. 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:

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

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

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

API

  1. MarkdownView(Context context)
  2. MarkdownView(Context context, AttributeSet attrs)

Parameters

  • context - Context
  • attrs - AttributeSet
    1. void loadMarkdown(String text)
    2. void loadMarkdown(String text, String cssFileUrl)
    3. void loadMarkdown(String baseUrl, String text, String cssFileUrl)
    4. 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
    1. void loadMarkdownFile(String url)
    2. void loadMarkdownFile(String url, String cssFileUrl)
    3. void loadMarkdownFile(String baseUrl, String url, String cssFileUrl)
    4. 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