Home

Awesome

MGFormatter

Swift 5.0 build_check Version License Platform

MGFormatter can format the JSON or HTML code in a view with customized keyword color and font.

<div> <img src="https://raw.githubusercontent.com/lm2343635/MGFormatter/master/screenshot/json-dark.png" width="300"> <img src="https://raw.githubusercontent.com/lm2343635/MGFormatter/master/screenshot/html-dark.png" width="300"> </div>

Example

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

Requirements

Usage

Just create a FormatterView and set the code you want to format.

formatterView.format(string: utf8Text, style: .jsonDark)

About style

The follow style can be customized be the developers.

Dark and light style can be used directly.

Supported code style and colors

The following colors of keywords can be customized.

Here is the demo code for customized style.

let color = JSONColor(
    normal: .white,
    attribute: .yellow,
    boolean: .green,
    string: .cyan,
    number: .orange
)
let style = FormatterStyle(font: UIFont.systemFont(ofSize: 12), lineSpacing: 5, type: .json(JSONColor()))
self.formatterView.format(string: utf8Text, style: style)

Installation

MGFormatter is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'MGFormatter'

Author

Meng Li, lm2343635@126.com

License

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