Latest 2.0.5
Homepage https://github.com/davidlari/Haring
License MIT
Platforms ios 8.0
Frameworks UIKit
Authors

Logo

Version
Carthage compatible
License
Platform

Haring is a customizable and extensible Markdown parser for iOS. 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.

Haring was forked from Ivan Bruel’s MarkdownKit which appears to be no longer maintained.

Haring is named after PopArt artist Keith Haring.

Screenshot

Example

Installation

Installation via CocoaPods

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

pod 'Haring'

Version 2.x supports Xcode 9 and Swift 4.

Version 1.5 supports Xcode 9 and Swift 3.2. If you need this, add the version:

pod 'Haring', '~> 1.5.0'

Version 1.4 supports Xcode 8 and Swift 3.1. If you need this, add the version:

pod 'Haring', '~> 1.4.0'

Afterwards, run the following command:

pod install

Installation via Carthage

Haring 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 Haring into your Xcode project using Carthage, simply add the following line to your Cartfile:

github "davidlari/Haring"

Afterwards, run the following command:

carthage update

Supported Elements

*italic* or _italics_
**bold** or __bold__

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

> Quote

* List
- List
+ List

`code` or ```code```
[Links](http://github.com/davidlari/Haring/)

Usage

In order to use Haring 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.systemFontOfSize(18))
markdownParser.automaticLinkDetectionEnabled = false
markdownParser.bold.color = UIColor.redColor()
markdownParser.italic.font = UIFont.italicSystemFontOfSize(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 Haring

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.

About

Haring is maintained by David Lari. Contributions and pull requests are welcomed.

Acknowledgements

Haring was derived from MarkdownKit by Ivan Bruel. It was created due to the apparent abandonment of MarkdownKit.

MarkdownKit in turn, was heavily inspired by TSMarkdownParser and also SwiftyMarkdown.

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

License

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

Latest podspec

{
    "name": "Haring",
    "version": "2.0.5",
    "summary": "Haring is a customizable and extensible Markdown parser for iOS.",
    "description": "Haring is a customizable and extensible Markdown parser for iOS.nIt supports many of the standard Markdown elements through the use of RegularnExpressions. It also allows customization of font and color attributes fornall the Markdown elements.",
    "homepage": "https://github.com/davidlari/Haring",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "David Lari": "[email protected]"
    },
    "source": {
        "git": "https://github.com/davidlari/Haring.git",
        "tag": "2.0.5"
    },
    "social_media_url": "https://twitter.com/davidlari",
    "platforms": {
        "ios": "8.0"
    },
    "pod_target_xcconfig": {
        "SWIFT_VERSION": "4.0"
    },
    "source_files": "Haring/Classes/**/*",
    "frameworks": "UIKit",
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This