RxMarkdown 是一个运用 RxJava API 在 TextView 或 EditText 中编辑和(实时)预览基本 markdown 语法的 Android 库

RxMarkdown

项目地址: yydcdut/RxMarkdown
简介:RxMarkdown 是一个运用 RxJava API 在 TextView 或 EditText 中编辑和(实时)预览基本 markdown 语法的 Android 库。

RxMarkdown is an Android library that helps to display simple markdown text in android.widget.EditText orandroid.widget.TextView .

It is backed by RxJava, implementing complicated APIs as handy reactive observables.

中文:README-zh-rCN.md

Demo apk : DOWNLOAD

QR Code : CLICK

Change Log : SEE

RxMarkdown.gif

Support Grammar

RxMarkdown now provides 2 factories to parse markdown, TextFactory and EditFactory .

TextFactory : Supports most of the markdown grammars,but it will destroy the integrity of the content. So, it applies to render in TextView .

EditFactory : Supports some grammars,and it won't destroy the integrity of the content, the parsing speed is faster than TextFactory , So, it applies to real-time preview in EditText .

TextFactory

  • [x] Header # / ## / ### / #### / ##### / #######
  • [x] BlockQuote >
  • [x] Nested BlockQuote > >
  • [x] Emphasis Bold ** __
  • [x] Emphasis Italic * _
  • [x] Nested Bold && Italic
  • [x] Ordered List 1.
  • [x] Nested Ordered List
  • [x] UnOrdered List * / + / -
  • [x] Nested UnOrdered List
  • [x] Image ![]()
  • [x] Hyper Link []()
  • [x] Inline Code
  • [x] Code
  • [x] Backslash \
  • [x] Horizontal Rules *** / ***** / --- / -----------------
  • [x] Strike Through ~~
  • [x] Footnote [^]
  • [x] Todo - [ ] / - [x]
  • [ ] Table | Table | Table |
Other Grammar
  • [x] Center Align []

EditFactory

  • [x] Header # / ## / ### / #### / ##### / #######
  • [x] BlockQuote >
  • [x] Nested BlockQuote > >
  • [x] Emphasis Bold ** __
  • [x] Emphasis Italic * _
  • [x] Nested Bold && Italic
  • [x] Ordered List 1.
  • [x] Nested Ordered List
  • [x] UnOrdered List * / + / -
  • [x] Nested UnOrdered List
  • [ ] Image ![]()
  • [ ] Hyper Link []()
  • [x] Inline Code
  • [x] Code
  • [ ] Backslash \
  • [x] Horizontal Rules *** / ***** / --- / -----------------
  • [x] Strike Through ~~
  • [ ] Footnote [^]
  • [ ] Todo - [ ] / - [x]
  • [ ] Table | Table | Table |
Other Grammar
  • [x] Center Align []

HtmlFactory

//TODO

Quick Start

Setup

compile 'com.yydcdut:rxmarkdown:0.0.7'

compile 'io.reactivex:rxandroid:1.2.0'
compile 'io.reactivex:rxjava:1.1.5'

Configuration

All options in Configuration builder are optional. Use only those you really want to customize.

RxMDConfiguration rxMDConfiguration = new RxMDConfiguration.Builder(context)
        .setDefaultImageSize(100, 100)//default image width & height
        .setBlockQuotesColor(Color.LTGRAY)//default color of block quotes
        .setHeader1RelativeSize(1.6f)//default relative size of header1
        .setHeader2RelativeSize(1.5f)//default relative size of header2
        .setHeader3RelativeSize(1.4f)//default relative size of header3
        .setHeader4RelativeSize(1.3f)//default relative size of header4
        .setHeader5RelativeSize(1.2f)//default relative size of header5
        .setHeader6RelativeSize(1.1f)//default relative size of header6
        .setHorizontalRulesColor(Color.LTGRAY)//default color of horizontal rules's background
        .setInlineCodeBgColor(Color.LTGRAY)//default color of inline code's background
        .setCodeBgColor(Color.LTGRAY)//default color of code's background
        .setTodoColor(Color.DKGRAY)//default color of todo
        .setTodoDoneColor(Color.DKGRAY)//default color of done
        .setUnOrderListColor(Color.BLACK)//default color of unorder list
        .setLinkColor(Color.RED)//default color of link text
        .setLinkUnderline(true)//default value of whether displays link underline
        .setRxMDImageLoader(new DefaultLoader(context))//default image loader
        .setDebug(true)//default value of debug
        .setOnLinkClickCallback(new OnLinkClickCallback() {//link click callback
            @Override
            public void onLinkClicked(View view, String link) {
            }
        })
        .build();

Usage

  • EditText , live preview :

    RxMarkdown.live(rxMDEditText)
            .config(rxMDConfiguration)
            .factory(EditFactory.create())
            .intoObservable()
            .subscribe();
    
  • cancel real-time preview :

    rxMDEditText.clear();
    
  • TextView render :

    RxMarkdown.with(content, this)
            .config(rxMDConfiguration)
            .factory(TextFactory.create())
            .intoObservable()
            .subscribeOn(Schedulers.computation())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Subscriber<CharSequence>() {
                @Override
                public void onCompleted() {}
    
                @Override
                public void onError(Throwable e) {}
    
                @Override
                public void onNext(CharSequence charSequence) {
                    rxMDTextView.setText(charSequence, TextView.BufferType.SPANNABLE);
                }
            });
    

Note

RxMDImageLoader
  • Acceptable URIs examples

    "http://web.com/image.png" // from Web
    "file:///mnt/sdcard/image.png" // from SD card
    "assets://image.png" // from assets
    "drawable://" + R.drawable.img // from drawables (non-9patch images)
    
  • Custom image loader

    public class MDLoader implements RxMDImageLoader {
        @Nullable
        @Override
        public byte[] loadSync(@NonNull String url) throws IOException {
            return new byte[0];
        }
    }
    
Image Size

The image of 320 pixels width and 320 pixels height will display on the screen :

![image](http://web.com/image.png/320$320)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值