Latest 0.3.1
Homepage https://github.com/lm2343635/MGFormatter
License MIT
Platforms ios 8.0
Dependencies SwiftyJSON, Fuzi, AttributedTextView, SnapKit
Authors

Swift 4.2
CI Status
Version
License
Platform

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

MGFormatterMGFormatter

Example

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

Requirements

  • iOS 8.0+
  • Xcode 9.0+

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.

  • Formatter type(JSON or HTML) and the colors of key words.
  • Font.
  • Line spacing.

Dark and light style can be used directly.

Supported code style and colors

The following colors of keywords can be customized.

  • JSON type
    • normal
    • attribute
    • boolean
    • string
    • number
  • HTML
    • normal
    • tag
    • attribute name
    • attribute value

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', '~> 0.3'

Author

Meng Li, [email protected]

License

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

Latest podspec

{
    "name": "MGFormatter",
    "version": "0.3.1",
    "summary": "A code formatting library for iOS.",
    "description": "MGFormatter can format the JSON or HRML code in a view with customized keyword color and font.",
    "homepage": "https://github.com/lm2343635/MGFormatter",
    "screenshots": [
        "https://raw.githubusercontent.com/lm2343635/MGFormatter/master/screenshot/json-dark.png",
        "https://raw.githubusercontent.com/lm2343635/MGFormatter/master/screenshot/html-dark.png"
    ],
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "lm2343635": "[email protected]"
    },
    "source": {
        "git": "https://github.com/lm2343635/MGFormatter.git",
        "tag": "0.3.1"
    },
    "social_media_url": "https://github.com/lm2343635/MGFormatter",
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "MGFormatter/Classes/**/*",
    "dependencies": {
        "SwiftyJSON": [
            "~> 4"
        ],
        "Fuzi": [
            "~> 2"
        ],
        "AttributedTextView": [
            "~> 1.2"
        ],
        "SnapKit": [
            "~> 4"
        ]
    }
}

Pin It on Pinterest

Share This