在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):bmoliveira/MarkdownKit开源软件地址(OpenSource Url):https://github.com/bmoliveira/MarkdownKit开源编程语言(OpenSource Language):Swift 94.9%开源软件介绍(OpenSource Introduction):MarkdownKitMarkdownKit 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. ScreenshotInstallationInstallation via CocoaPodsMarkdownKit 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 CarthageMarkdownKit 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 ManagerMarkdownKit is available through Swift Package Manager. To add MarkdownKit as a dependency of your Swift package, simply add the following line to your .package(url: "https://github.com/bmoliveira/MarkdownKit.git", from: "1.7.0") Supported Elements
UsageIn order to use MarkdownKit to transform Markdown into NSAttributedString, all you have to do is create an instance of let markdownParser = MarkdownParser()
let markdown = "I support a *lot* of custom Markdown **Elements**, even `code`!"
label.attributedText = markdownParser.parse(markdown) Customizationlet 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 ExtensibilityTo add new Markdown elements all you have to do is implement the 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) ExampleTo run the example project, clone the repo, and run AcknowledgementsThis library is heavily inspired in TSMarkdownParser and also SwiftyMarkdown. Special thanks to Michael Brown for helping out with the UTF-16 Escaping/Unescaping. LicenseMarkdownKit is available under the MIT license. See the LICENSE file for more info. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论