ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - bmoliveira/MarkdownKit: A simple and customizable Markdown Parser for Swift
A simple and customizable Markdown Parser for Swift - bmoliveira/MarkdownKit
Visit Site

GitHub - bmoliveira/MarkdownKit: A simple and customizable Markdown Parser for Swift

GitHub - bmoliveira/MarkdownKit: A simple and customizable Markdown Parser for Swift

Logo

MarkdownKit

Version Carthage compatible License Platform CI

MarkdownKit is a customizable and extensible Markdown parser for iOS and macOS. It supports many of the standard Markdown elements through the use of Regular Expressions. It also allows customization of font and color attributes for all the Markdown elements.

Screenshot

Example

Installation

Installation via CocoaPods

MarkdownKit is available through CocoaPods. CocoaPods is a dependency manager that automates and simplifies the process of using 3rd-party libraries like MarkdownKit in your projects. You can install CocoaPods with the following command:

gem install cocoapods

To integrate MarkdownKit into your Xcode project using CocoaPods, simply add the following line to your Podfile:

pod "MarkdownKit"

Afterwards, run the following command:

pod install

Installation via Carthage

MarkdownKit is available through Carthage. Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage via Homebrew with the following command:

brew update
brew install carthage

To integrate MarkdownKit into your Xcode project using Carthage, simply add the following line to your Cartfile:

github "ivanbruel/MarkdownKit"

Afterwards, run the following command:

carthage update --use-xcframeworks

Installation via Swift Package Manager

MarkdownKit is available through Swift Package Manager.

To add MarkdownKit as a dependency of your Swift package, simply add the following line to your Package.swift file:

.package(url: "https://github.com/bmoliveira/MarkdownKit.git", from: "1.7.0")

Supported Elements

*italic* or _italics_
**bold** or __bold__
~~strikethrough~~

# Header 1
## Header 2
### Header 3
#### Header 4
##### Header 5
###### Header 6

> Quote

* List
- List
+ List

`code` or ```code```
[Links](http://github.com/ivanbruel/MarkdownKit/)

Usage

In order to use MarkdownKit to transform Markdown into NSAttributedString, all you have to do is create an instance of MarkdownParser and call the parse(_) function.

let markdownParser = MarkdownParser()
let markdown = "I support a *lot* of custom Markdown **Elements**, even `code`!"
label.attributedText = markdownParser.parse(markdown)

Customization

let markdownParser = MarkdownParser(font: UIFont.systemFont(ofSize: 18))
markdownParser.enabledElements = .disabledAutomaticLink
markdownParser.bold.color = UIColor.red
markdownParser.italic.font = UIFont.italicSystemFont(ofSize: 300)
markdownParser.header.fontIncrease = 4

Extensibility

To add new Markdown elements all you have to do is implement the MarkdownElement protocol (or descendants) and add it to the MarkdownParser.

import MarkdownKit

class MarkdownSubreddit: MarkdownLink {

  private static let regex = "(^|\\s|\\W)(/?r/(\\w+)/?)"

  override var regex: String {
    return MarkdownSubreddit.regex
  }

  override func match(match: NSTextCheckingResult,
                             attributedString: NSMutableAttributedString) {
    let subredditName = attributedString.attributedSubstringFromRange(match.rangeAtIndex(3)).string
    let linkURLString = "http://reddit.com/r/\(subredditName)"
    formatText(attributedString, range: match.range, link: linkURLString)
    addAttributes(attributedString, range: match.range, link: linkURLString)
  }

}
let markdownParser = MarkdownParser(customElements: [MarkdownSubreddit()])
let markdown = "**/r/iosprogramming** can be *markdown* as well!"
label.attributedText = markdownParser.parse(markdown)

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Acknowledgements

This library is heavily inspired in TSMarkdownParser and also SwiftyMarkdown.

Special thanks to Michael Brown for helping out with the UTF-16 Escaping/Unescaping.

License

MarkdownKit is available under the MIT license. See the LICENSE file for more info.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory