Markdown

Project Url: zzhoujay/Markdown
Introduction: Android 平台下的原生 Markdown 解析器
More: Author   ReportBugs   
Tags:
Markdown-

Android 平台的原生 Markdown 解析器,已整合进 RichText

  • 由 markdown 文本直接转换为 Spanned,快捷高效
  • 不依赖特定控件,低侵入性
  • 遵循 Github Flavored Markdown 标准

效果展示

效果图

使用

Markdown.fromMarkdown(text,imageGetter,textView);

注意: 此方法需要在 textView 的 Measure 完成后调用,因为需要获取 textView 的宽高

例子:

textView.post(new Runnable() {
     @Override
     public void run() {
     Spanned spanned = MarkDown.fromMarkdown(stream, new Html.ImageGetter() {
           @Override
           public Drawable getDrawable(String source) {
                 Drawable drawable = getResources().getDrawable(R.mipmap.ic_launcher);
                 drawable.setBounds(0, 0, 400, 400);
                 return drawable;
           }
     }, textView);
     textView.setText(spanned);
}

自定义样式

在可以你的主题里加入 markdownStyle 来自定义样式,如果没有指定样式会使用自带的亮色主题。

例子:

<style name="你的主题">
    <!--<item name="markdownStyle">@style/Markdown</item>--> <!-- 暗色主题 -->
    <item name="markdownStyle">@style/Markdown.Light</item> <!-- 亮色主题 -->
</style>

在 RichText 中使用

RichText 包含了一些对图片和其它东西的处理,使用更简单

RichText.fromMarkdown(markdown).into(textView);

Use in Gradle

compile 'com.zzhoujay.markdown:markdown:1.0.5'

已知问题

  • 暂不支持使用反斜杠 \ 转义
  • 不支持表格
  • TextView 设置了setTextIsSelectable(true)后和长按事件冲突
  • 暂时不支持内嵌 html

后续计划

  • 修复一些已知问题
  • 加入多选框支持
  • 增加对简单 html 标签的支持

License

The MIT License (MIT)

Copyright (c) 2015 zzhoujay

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

by zzhoujay

Apps
About Me
GitHub: Trinea
Facebook: Dev Tools