- Notifications
You must be signed in to change notification settings - Fork93
yydcdut/RxMarkdown
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
RxMarkdown is an Android library that helps to display simple markdown text inandroid.widget.EditText
orandroid.widget.TextView
, at same time, it supports code high light .
It is backed by RxJava, implementing complicated APIs as handy reactive observables.
Demo apk :DOWNLOAD
QR Code :CLICK
Change Log :SEE
implementation'com.yydcdut:markdown-processor:0.1.3'implementation'com.yydcdut:rxmarkdown-wrapper:0.1.3'
Or if you don't want to use RxJava, you can simply refer tomarkdown-processor
:
implementation'com.yydcdut:markdown-processor:0.1.3'
RxMarkdown now provides 2 factories to parse markdown,TextFactory
andEditFactory
.
TextFactory
: Supports most of the markdown syntax,but it will destroy the integrity of the content. So, it applies to render inTextView
.
EditFactory
: Supports some syntax,and it won't destroy the integrity of the content, the parsing speed is faster thanTextFactory
, So, it applies to real-time preview inEditText
.
- Header
#
/##
/###
/####
/#####
/#######
- BlockQuote
>
- Nested BlockQuote
> >
- Emphasis Bold
**
__
- Emphasis Italic
*
_
- Nested Bold && Italic
- Ordered List
1.
- Nested Ordered List
- UnOrdered List
*
/+
/-
- Nested UnOrdered List
- Image
![]()
- Hyper Link
[]()
- Inline Code
- Code
- Backslash
\
- Horizontal Rules
***
/*****
/---
/-----------------
- Strike Through
~~
- Footnote
[^]
- Todo
- [ ]
/- [x]
- Table
| Table | Table |
- code high light
- Center Align
[]
- Header
#
/##
/###
/####
/#####
/#######
- BlockQuote
>
- Nested BlockQuote
> >
- Emphasis Bold
**
__
- Emphasis Italic
*
_
- Nested Bold && Italic
- Ordered List
1.
- Nested Ordered List
- UnOrdered List
*
/+
/-
- Nested UnOrdered List
- Image
![]()
- Hyper Link
[]()
- Inline Code
- Code
- Backslash
\
- Horizontal Rules
***
/*****
/---
/-----------------
- Strike Through
~~
- Footnote
[^]
- Todo
- [ ]
/- [x]
- Table
| Table | Table |
- code high light
- Center Align
[]
//TODO
implementation'com.yydcdut:markdown-processor:0.1.3'implementation'com.yydcdut:rxmarkdown-wrapper:0.1.3'implementation'io.reactivex:rxandroid:1.2.0'implementation'io.reactivex:rxjava:1.1.5'
All options in Configuration builder are optional. Use only those you really want to customize (RxMDConfiguration#Builder
andMarkdownConfiguration#Builder
are the same usage):
RxMDConfigurationrxMDConfiguration =newRxMDConfiguration.Builder(context) .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 .setBlockQuotesLineColor(Color.LTGRAY)//default color of block quotes line .setBlockQuotesBgColor(Color.LTGRAY,Color.RED,Color.BLUE)//default color of block quotes background and nested background .setBlockQuotesRelativeSize(Color.LTGRAY,Color.RED,Color.BLUE)//default relative size of block quotes text size .setHorizontalRulesColor(Color.LTGRAY)//default color of horizontal rules's background .setHorizontalRulesHeight(Color.LTGRAY)//default height of horizontal rules .setCodeFontColor(Color.LTGRAY)//default color of inline code's font .setCodeBgColor(Color.LTGRAY)//default color of inline code's background .setTheme(newThemeDefault())//default code block theme .setTodoColor(Color.DKGRAY)//default color of todo .setTodoDoneColor(Color.DKGRAY)//default color of done .setOnTodoClickCallback(newOnTodoClickCallback() {//todo or done click callback@OverridepublicCharSequenceonTodoClicked(Viewview,Stringline) {returntextView.getText(); } }) .setUnOrderListColor(Color.BLACK)//default color of unorder list .setLinkFontColor(Color.RED)//default color of link text .showLinkUnderline(true)//default value of whether displays link underline .setOnLinkClickCallback(newOnLinkClickCallback() {//link click callback@OverridepublicvoidonLinkClicked(Viewview,Stringlink) { } }) .setRxMDImageLoader(newDefaultLoader(context))//default image loader .setDefaultImageSize(100,100)//default image width & height .build();
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(newSubscriber<CharSequence>() {@OverridepublicvoidonCompleted() {}@OverridepublicvoidonError(Throwablee) {}@OverridepublicvoidonNext(CharSequencecharSequence) {rxMDTextView.setText(charSequence,TextView.BufferType.SPANNABLE); } });
EditText
, live preview :MarkdownProcessormarkdownProcessor =newMarkdownProcessor(this);markdownProcessor.config(markdownConfiguration);markdownProcessor.factory(EditFactory.create());markdownProcessor.live(markdownEditText);
cancel real-time preview :
markdownEditText.clear();
TextView
render :MarkdownProcessormarkdownProcessor =newMarkdownProcessor(this);markdownProcessor.factory(TextFactory.create());markdownProcessor.config(markdownConfiguration);textView.setText(markdownProcessor.parse(content));
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
publicclassMDLoaderimplementsRxMDImageLoader {@Nullable@Overridepublicbyte[]loadSync(@NonNullStringurl)throwsIOException {returnnewbyte[0]; }}
The image of 320 pixels width and 320 pixels height will display on the screen :

The lib supports some themes,ThemeDefault
,ThemeDesert
,ThemeSonsOfObsidian
andThemeSunburst
.
ThemeDefault | ThemeDesert | ThemeSonsOfObsidian | ThemeSunburst |
---|---|---|---|
![]() | ![]() | ![]() | ![]() |
You can implement the interfaceTheme
to realize your own theme.
publicclassCodeHighLightThemeimplementsTheme {@OverridepublicintgetBackgroundColor() {//background colorreturn0xffcccccc; }@OverridepublicintgetTypeColor() {//color for typereturn0xff660066; }@OverridepublicintgetKeyWordColor() {//color for keywordreturn0xff000088; }@OverridepublicintgetLiteralColor() {//color for literalreturn0xff006666; }@OverridepublicintgetCommentColor() {//color for commentreturn0xff880000; }@OverridepublicintgetStringColor() {//color for stringreturn0xff008800; }@OverridepublicintgetPunctuationColor() {//color for punctuationreturn0xff666600; }@OverridepublicintgetTagColor() {//color for html/xml tagreturn0xff000088; }@OverridepublicintgetPlainTextColor() {//color for a plain textreturn0xff000000; }@OverridepublicintgetDecimalColor() {//color for a markup declaration such as a DOCTYPEreturn0xff000000; }@OverridepublicintgetAttributeNameColor() {//color for html/xml attribute namereturn0xff660066; }@OverridepublicintgetAttributeValueColor() {//color for html/xml attribute valuereturn0xff008800; }@OverridepublicintgetOpnColor() {//color for opnreturn0xff666600; }@OverridepublicintgetCloColor() {//color for cloreturn0xff666600; }@OverridepublicintgetVarColor() {//color for varreturn0xff660066; }@OverridepublicintgetFunColor() {//color for funreturnColor.RED; }@OverridepublicintgetNocodeColor() {colorfornocodereturn0xff000000; }}
Copyright 2016 yydcdut
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
About
📠Markdown for Android, supports TextView && EditText (Live Preview), supports code high light.