• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

GrenderG/MarkdownView: WebView implementation supporting Markdown rendering.

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

GrenderG/MarkdownView

开源软件地址(OpenSource Url):

https://github.com/GrenderG/MarkdownView

开源编程语言(OpenSource Language):

Java 70.7%

开源软件介绍(OpenSource Introduction):

ko-fi

MarkdownView

API Android Arsenal

WebView implementation supporting Markdown rendering.

Prerequisites

Add this in your root build.gradle file (not your module build.gradle file):

allprojects {
	repositories {
		...
		maven { url "https://jitpack.io" }
	}
}

Dependency

Add this to your module's build.gradle file (make sure the version matches the JitPack badge above):

dependencies {
	...
	implementation 'com.github.GrenderG:MarkdownView:0.1.2'
}

Basic usage

NOTE: You will need to specify INTERNET permission in your project if you want to load Internet resources.

First of all, all the View where you want:

<es.dmoral.markdownview.MarkdownView
        android:id="@+id/markdown_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

Loading Markdown text:

markdownView.loadFromText("### Loading some Markdown!\nHey there.");

Loading Markdown from a File:

markdownView.loadFromFile(new File("path/to/md/file"));

Loading Markdown from Android assets:

markdownView.loadFromAssets("path/to/file/in/assets");

Loading Markdown from URL:

markdownView.loadFromURL("https://raw.githubusercontent.com/GrenderG/MarkdownView/master/README.md");

Advanced usage

MarkdownView uses css files to stylize everything, you can customize them too:

markdownView.setCurrentConfig(new Config(
	"file:///android_asset/custom_css_file.css",
	Config.CssCodeHighlight.MONOKAI_SUBLIME // This can be a custom one too, but there are already added some options.
));

Internally, MarkdownView uses an OkHttpClient to load files from URLs, you can set a custom one if you want:

Config defaultConfig = Config.getDefaultConfig();
        
defaultConfig.setDefaultOkHttpClient(new OkHttpClient().newBuilder().addInterceptor(
        new Interceptor() {
            @Override
            public Response intercept(Chain chain) throws IOException {
                Request request = chain.request();
                Request authenticatedRequest = request.newBuilder()
                        .header("Authorization", "Basic OIxhJGHpbjpvcGVuc2VzYW1l").build();
                return chain.proceed(authenticatedRequest);
            }
        }
).build());

markdownView.setCurrentConfig(defaultConfig);

You can also set the margins of the content (in px):

Config defaultConfig = Config.getDefaultConfig();
        
defaultConfig.setDefaultMargin(16);

markdownView.setCurrentConfig(defaultConfig);

There's also a rendering listener which will provide you info if there's an error rendering the Markdown and when it has finished rendering (near perfect timing).

markdownView.setOnMarkdownRenderingListener(new MarkdownView.OnMarkdownRenderingListener() {
        @Override
        public void onMarkdownFinishedRendering() {
            // Rendered!
        }

        @Override
        public void onMarkdownRenderError() {
	    // Error rendering
        }
    });

Acknowledgements

This library is heavily influenced by MarkedView-for-Android from @mittsuu.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap