Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/silence0201/simarkdown
MarkdownView
https://github.com/silence0201/simarkdown
ios markdown objective-c
Last synced: 4 months ago
JSON representation
MarkdownView
- Host: GitHub
- URL: https://github.com/silence0201/simarkdown
- Owner: silence0201
- License: mit
- Created: 2017-05-30T14:11:17.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-08-11T12:31:54.000Z (over 7 years ago)
- Last Synced: 2024-10-14T16:44:04.393Z (4 months ago)
- Topics: ios, markdown, objective-c
- Language: Objective-C
- Size: 368 KB
- Stars: 7
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SIMarkdown
![Language](https://img.shields.io/badge/language-objc-orange.svg)
![License](https://img.shields.io/badge/license-MIT-blue.svg)利用WKWebView实现简单的Markdown数据解析,核心利用了bootstrap进行解析
### 导入
将项目中`MarkdownView`文件夹拖到项目里或者使用`Pod`安装
pod 'SIMarkdown', '~> 1.0'
### 使用
1. 导入头文件```objective-c
#import "MediaMetaManager.h"
```
2. 初始化```objective-c
SIMarkdownView *markdownView = [[SIMarkdownView alloc] initWithFrame:self.view.bounds] ;
markdownView.scrollEnabled = YES ; // 是否可以滑动
markdownView.showsScrollIndicator = NO ; // 是否显示滑动指示器
```
3. 根据需求设置回调```objective-c
markdownView.renderedAction = ^(CGFloat height) {
NSLog(@"Height:%lf",height) ;
} ; // 获取结果回调
markdownView.linkTouchAction = ^BOOL(NSURLRequest *request) {
NSURL *url = request.URL ;
if (url) {
if ([url.scheme isEqualToString:@"file"]) {
return true ;
}else if ([url.scheme isEqualToString:@"https"] || [url.scheme isEqualToString:@"http"]) {
SFSafariViewController *sfvc = [[SFSafariViewController alloc]initWithURL:url] ;
[self.navigationController pushViewController:sfvc animated:YES] ;
return false ;
}
}
return false ;
} ; // 捕捉点击回调
```
4. 加载本地markdown字符串```objective-c
NSString *path = [[NSBundle mainBundle] pathForResource:@"Sample" ofType:@"md"] ;
NSError *error ;
NSString *markStr = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error] ;
if (!error) {
[markdownView loadMarkdownString:markStr] ;
}
```
5. 加载网络markdown资源```objective-c
[markdownView loadMarkdownWithURL:[NSURL URLWithString:@"https://raw.githubusercontent.com/matteocrippa/awesome-swift/master/README.md"]withSuccess:^(SIMarkdownView *markView, NSData *data) {
markdownView.webView.scrollView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0) ;
NSString *markdown = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding] ;
NSLog(@"%@",markdown) ;
}];
```
6. 自定义显示的WebView,必须在加载网络资源之后调用```objective-c
markdownView.webView.UIDelegate = self ;
```
### 要求
iOS 8 or later.
## SIMarkdown[bootstrap](http://getbootstrap.com/) is licensed under [MIT license](https://github.com/twbs/bootstrap/blob/v4-dev/LICENSE).
SIMarkdown is available under the MIT license. See the LICENSE file for more info.