Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/keitaoouchi/MarkdownView
Markdown View for iOS.
https://github.com/keitaoouchi/MarkdownView
ios markdown swift
Last synced: 3 months ago
JSON representation
Markdown View for iOS.
- Host: GitHub
- URL: https://github.com/keitaoouchi/MarkdownView
- Owner: keitaoouchi
- License: mit
- Created: 2017-05-11T04:33:42.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-03-18T13:43:59.000Z (8 months ago)
- Last Synced: 2024-07-18T17:13:15.524Z (4 months ago)
- Topics: ios, markdown, swift
- Language: Swift
- Homepage:
- Size: 3.83 MB
- Stars: 1,964
- Watchers: 24
- Forks: 205
- Open Issues: 40
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-swift - MarkdownView - iOS Markdown view. (Libs / Text)
- awesome-swift - MarkdownView - iOS Markdown view. (Libs / Text)
- awesome-ios-star - MarkdownView - Markdown View for iOS. (Text / Other Testing)
- fucking-awesome-swift - MarkdownView - iOS Markdown view. (Libs / Text)
- awesome-ios - MarkdownView - Markdown View for iOS. (Text / Other Testing)
- awesome-swift - MarkdownView - Markdown View for iOS. ` 📝 9 months ago ` (Text [🔝](#readme))
README
# MarkdownView
[![CI Status](http://img.shields.io/travis/keitaoouchi/MArkdownView.svg?style=flat)](https://travis-ci.org/keitaoouchi/MarkdownView)
[![Swift 5.2](https://img.shields.io/badge/Swift-5.2-orange.svg?style=flat)](https://swift.org/)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
[![Version](https://img.shields.io/cocoapods/v/MarkdownView.svg?style=flat)](http://cocoapods.org/pods/MarkdownView)
[![License](https://img.shields.io/cocoapods/l/MarkdownView.svg?style=flat)](http://cocoapods.org/pods/MarkdownView)
[![Swift Package Manager compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)> MarkdownView is a WKWebView based UI element, and internally use markdown-it, highlight-js.
![GIF](https://github.com/keitaoouchi/MarkdownView/blob/master/sample.gif "GIF")
## How to use
#### UIViewController
```swift
import MarkdownViewlet md = MarkdownView()
md.load(markdown: "# Hello World!")
```#### SwiftUI
```swift
import SwiftUI
import MarkdownViewstruct SampleUI: View {
var body: some View {
ScrollView {
MarkdownUI(body: markdown)
.onTouchLink { link in
print(link)
return false
}
.onRendered { height in
print(height)
}
}
}
private var markdown: String {
let path = Bundle.main.path(forResource: "sample", ofType: "md")!
let url = URL(fileURLWithPath: path)
return try! String(contentsOf: url, encoding: String.Encoding.utf8)
}
}```
### Options
```swift
md.isScrollEnabled = false// called when rendering finished
md.onRendered = { [weak self] height in
self?.mdViewHeight.constant = height
self?.view.setNeedsLayout()
}// called when user touch link
md.onTouchLink = { [weak self] request in
guard let url = request.url else { return false }if url.scheme == "file" {
return false
} else if url.scheme == "https" {
let safari = SFSafariViewController(url: url)
self?.navigationController?.pushViewController(safari, animated: true)
return false
} else {
return false
}
}
```### Experimental Features
This is not stable :bow:
#### Custom CSS Styling
Please check [Example/ViewController/CustomCss.swift](https://github.com/keitaoouchi/MarkdownView/blob/master/Example/Example/ViewController/CustomCss.swift).
#### Plugins
Please check [Example/ViewController/Plugins.swift](https://github.com/keitaoouchi/MarkdownView/blob/master/Example/Example/ViewController/Plugins.swift).
Each plugin should be self-contained, with no external dependent plugins.[Here](https://github.com/keitaoouchi/markdownview-sample-plugin) is a sample project that builds `markdown-it-new-katex` as a compatible library.
## Requirements
| Target | Version |
|-------------------|---------|
| iOS | => 13.0 |
| Swift | => 5.2 |## Installation
MarkdownView is available through [Swift Package Manager](https://swift.org/package-manager/) or [CocoaPods](http://cocoapods.org) or [Carthage](https://github.com/Carthage/Carthage).
### Swift Package Manager
```swift
dependencies: [
.package(url: "https://github.com/keitaoouchi/MarkdownView.git", from: "1.7.1")
]
```
Alternatively, you can add the package directly via Xcode.### CocoaPods
```ruby
pod "MarkdownView"
```### Carthage
```
github "keitaoouchi/MarkdownView"
```for detail, please follow the [Carthage Instruction](https://github.com/Carthage/Carthage#if-youre-building-for-ios-tvos-or-watchos)
## Author
keita.oouchi, [email protected]
## License
[bootstrap](http://getbootstrap.com/) is licensed under [MIT license](https://github.com/twbs/bootstrap/blob/v4-dev/LICENSE).
[highlight.js](https://highlightjs.org/) is licensed under [BSD-3-Clause license](https://github.com/isagalaev/highlight.js/blob/master/LICENSE).
[markdown-it](https://markdown-it.github.io/) is licensed under [MIT license](https://github.com/markdown-it/markdown-it/blob/master/LICENSE).MarkdownView is available under the MIT license. See the LICENSE file for more info.