MarkdownKit

所属分类:代码编辑器
开发工具:Swift
文件大小:120KB
下载次数:0
上传日期:2022-09-09 14:43:38
上 传 者sh-1993
说明:  一个简单且可定制的Swift标记分析器
(A simple and customizable Markdown Parser for Swift)

文件列表:
Examples (0, 2021-08-22)
Examples\ViewModel.swift (1162, 2021-08-22)
Examples\iOS (0, 2021-08-22)
Examples\iOS\AppDelegate.swift (2185, 2021-08-22)
Examples\iOS\Extensions (0, 2021-08-22)
Examples\iOS\Extensions\String+HTMLDecode.swift (3033, 2021-08-22)
Examples\iOS\Fonts (0, 2021-08-22)
Examples\iOS\Fonts\Product Sans Regular.ttf (41116, 2021-08-22)
Examples\iOS\MarkdownSubreddit.swift (790, 2021-08-22)
Examples\iOS\Resources (0, 2021-08-22)
Examples\iOS\Resources\Base.lproj (0, 2021-08-22)
Examples\iOS\Resources\Base.lproj\LaunchScreen.xib (3873, 2021-08-22)
Examples\iOS\Resources\Base.lproj\Main.storyboard (5541, 2021-08-22)
Examples\iOS\Resources\Images.xcassets (0, 2021-08-22)
Examples\iOS\Resources\Images.xcassets\AppIcon.appiconset (0, 2021-08-22)
Examples\iOS\Resources\Images.xcassets\AppIcon.appiconset\Contents.json (848, 2021-08-22)
Examples\iOS\Resources\Info.plist (1235, 2021-08-22)
Examples\iOS\Resources\Localizable.strings (6145, 2021-08-22)
Examples\iOS\ViewController.swift (3110, 2021-08-22)
Examples\macOS (0, 2021-08-22)
Examples\macOS\AppDelegate.swift (498, 2021-08-22)
Examples\macOS\Assets.xcassets (0, 2021-08-22)
Examples\macOS\Assets.xcassets\AppIcon.appiconset (0, 2021-08-22)
Examples\macOS\Assets.xcassets\AppIcon.appiconset\Contents.json (903, 2021-08-22)
Examples\macOS\Assets.xcassets\Contents.json (62, 2021-08-22)
Examples\macOS\Base.lproj (0, 2021-08-22)
Examples\macOS\Base.lproj\Main.storyboard (64497, 2021-08-22)
Examples\macOS\Example-AppKit.entitlements (420, 2021-08-22)
Examples\macOS\Example_Appkit.entitlements (181, 2021-08-22)
Examples\macOS\Info.plist (1053, 2021-08-22)
Examples\macOS\ViewController.swift (1500, 2021-08-22)
LICENSE (1077, 2021-08-22)
MarkdownKit.podspec (1403, 2021-08-22)
MarkdownKit.xcodeproj (0, 2021-08-22)
MarkdownKit.xcodeproj\project.pbxproj (61430, 2021-08-22)
... ...

![Logo](https://raw.githubusercontent.com/ivanbruel/MarkdownKit/master/Resources/MarkdownKitLogo.png) MarkdownKit ========= [![Version](https://img.shields.io/cocoapods/v/MarkdownKit.svg?style=flat)](http://cocoapods.org/pods/MarkdownKit) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![License](https://img.shields.io/cocoapods/l/MarkdownKit.svg?style=flat)](http://cocoapods.org/pods/MarkdownKit) [![Platform](https://img.shields.io/cocoapods/p/MarkdownKit.svg?style=flat)](http://cocoapods.org/pods/MarkdownKit) [![CI](https://github.com/bmoliveira/MarkdownKit/actions/workflows/CI.yml/badge.svg)](https://github.com/bmoliveira/MarkdownKit/actions/workflows/CI.yml) 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](https://raw.githubusercontent.com/ivanbruel/MarkdownKit/master/Resources/MarkdownKitExample.png) ## Installation ### Installation via CocoaPods MarkdownKit is available through [CocoaPods](http://cocoapods.org). 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: ```ruby gem install cocoapods ``` To integrate MarkdownKit into your Xcode project using CocoaPods, simply add the following line to your Podfile: ```ruby pod "MarkdownKit" ``` Afterwards, run the following command: ```ruby pod install ``` ### Installation via Carthage MarkdownKit is available through [Carthage](https://github.com/Carthage/Carthage). Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. You can install Carthage via [Homebrew](http://brew.sh) with the following command: ```ruby brew update brew install carthage ``` To integrate MarkdownKit into your Xcode project using Carthage, simply add the following line to your Cartfile: ```ruby github "ivanbruel/MarkdownKit" ``` Afterwards, run the following command: ```ruby carthage update --use-xcframeworks ``` ### Installation via Swift Package Manager MarkdownKit is available through [Swift Package Manager](https://swift.org/package-manager/). To add MarkdownKit as a dependency of your Swift package, simply add the following line to your `Package.swift` file: ```swift .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. ```swift let markdownParser = MarkdownParser() let markdown = "I support a *lot* of custom Markdown **Elements**, even `code`!" label.attributedText = markdownParser.parse(markdown) ``` ## Customization ```swift 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`. ```swift 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) } } ``` ```swift 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](https://github.com/laptobbe/TSMarkdownParser) and also [SwiftyMarkdown](https://github.com/SimonFairbairn/SwiftyMarkdown). Special thanks to [Michael Brown](https://github.com/mluisbrown) for helping out with the [UTF-16 Escaping/Unescaping](https://github.com/ivanbruel/MarkdownKit/blob/master/MarkdownKit/Classes/Extensions/String%2BUTF16.swift). ## License MarkdownKit is available under the MIT license. See the LICENSE file for more info.

近期下载者

相关文件


收藏者