diff --git a/CDMarkdownKit.podspec b/CDMarkdownKit.podspec index 67cdcb4..22e40e4 100644 --- a/CDMarkdownKit.podspec +++ b/CDMarkdownKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'CDMarkdownKit' - s.version = '2.4.0' + s.version = '2.5.0' s.license = { :type => 'MIT', :file => 'LICENSE' } s.summary = 'An extensive Swift framework providing simple and customizable markdown parsing.' s.description = <<-DESC diff --git a/CDMarkdownKit.xcodeproj/project.pbxproj b/CDMarkdownKit.xcodeproj/project.pbxproj index 8321979..6de03f4 100644 --- a/CDMarkdownKit.xcodeproj/project.pbxproj +++ b/CDMarkdownKit.xcodeproj/project.pbxproj @@ -987,7 +987,7 @@ INFOPLIST_FILE = Source/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 10.0; MACOSX_DEPLOYMENT_TARGET = 10.12; - MARKETING_VERSION = 2.4.0; + MARKETING_VERSION = 2.5.0; ONLY_ACTIVE_ARCH = YES; PRODUCT_BUNDLE_IDENTIFIER = com.christopherdehaan.CDMarkdownKit; PRODUCT_NAME = CDMarkdownKit; @@ -1050,7 +1050,7 @@ INFOPLIST_FILE = Source/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 10.0; MACOSX_DEPLOYMENT_TARGET = 10.12; - MARKETING_VERSION = 2.4.0; + MARKETING_VERSION = 2.5.0; PRODUCT_BUNDLE_IDENTIFIER = com.christopherdehaan.CDMarkdownKit; PRODUCT_NAME = CDMarkdownKit; SWIFT_COMPILATION_MODE = wholemodule; diff --git a/CHANGELOG.md b/CHANGELOG.md index f46efab..b618855 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. `CDMarkdownKit` adheres to [Semantic Versioning](https://semver.org/). #### 2.x Releases +- `2.5.x` Releases - [2.5.0](#250) - `2.4.x` Releases - [2.4.0](#240) - `2.3.x` Releases - [2.3.0](#230) - `2.2.x` Releases - [2.2.0](#220) @@ -16,6 +17,17 @@ All notable changes to this project will be documented in this file. --- +## [2.5.0](https://github.com/chrisdhaan/CDMarkdownKit/releases/tag/2.5.0) +## Markdown Parsing +Released on 2022-12-12. + +#### Added + +- [x] Markdown Parsing + - [x] Underline color and style on all elements + +--- + ## [2.4.0](https://github.com/chrisdhaan/CDMarkdownKit/releases/tag/2.4.0) ## Markdown Parsing Released on 2022-12-03. diff --git a/Example/Source/BaseViewController.swift b/Example/Source/BaseViewController.swift index 3c719c5..a9d373c 100644 --- a/Example/Source/BaseViewController.swift +++ b/Example/Source/BaseViewController.swift @@ -62,6 +62,8 @@ class BaseViewController: UIViewController { // Example of a markdown parser with custom properties self.customMarkdownParser.bold.color = UIColor.cyan self.customMarkdownParser.bold.backgroundColor = UIColor.purple + self.customMarkdownParser.bold.underlineColor = UIColor.red + self.customMarkdownParser.bold.underlineStyle = .double let boldParagraphStyle = NSMutableParagraphStyle() boldParagraphStyle.paragraphSpacing = 10 boldParagraphStyle.paragraphSpacingBefore = 0 diff --git a/README.md b/README.md index edfe866..f776e39 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ For a demonstration of the capabilities of CDMarkdownKit; run the iOS Example pr [CocoaPods](https://cocoapods.org) is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate CDMarkdownKit into your Xcode project using CocoaPods, specify it in your `Podfile`: ```ruby -pod 'CDMarkdownKit', '2.4.0' +pod 'CDMarkdownKit', '2.5.0' ``` ### Carthage @@ -107,7 +107,7 @@ pod 'CDMarkdownKit', '2.4.0' [Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate CDMarkdownKit into your Xcode project using Carthage, specify it in your `Cartfile`: ```ogdl -github "chrisdhaan/CDMarkdownKit" == 2.4.0 +github "chrisdhaan/CDMarkdownKit" == 2.5.0 ``` ### Swift Package Manager @@ -118,7 +118,7 @@ Once you have your Swift package set up, adding CDMarkdownKit as a dependency is ```swift dependencies: [ - .package(url: "https://github.com/chrisdhaan/CDMarkdownKit.git", .upToNextMajor(from: "2.4.0")) + .package(url: "https://github.com/chrisdhaan/CDMarkdownKit.git", .upToNextMajor(from: "2.5.0")) ] ``` @@ -192,6 +192,8 @@ let markdownParser = CDMarkdownParser(font: UIFont(name: "HelveticaNeue", size: /// Bold markdownParser.bold.color = UIColor.cyan markdownParser.bold.backgroundColor = UIColor.purple +markdownParser.bold.underlineColor = UIColor.red +markdownParser.bold.underlineStyle = .double /// Header markdownParser.header.color = UIColor.black markdownParser.header.backgroundColor = UIColor.orange @@ -225,6 +227,11 @@ markdownParser.syntax.backgroundColor = UIColor.black /// Image markdownParser.image.size = CGSize(width: 100, height: 50) +/// Strikethrough +markdownParser.strikethrough.font = UIFont.systemFont(ofSize: 20) +markdownParser.strikethrough.color = UIColor.magenta +markdownParser.strikethrough.strikethroughColor = UIColor.darkGray +markdownParser.strikethrough.strikethroughStyle = .double // Parse markdown let markdown = "This *framework* helps **with** parsing `markdown`." label.attributedText = markdownParser.parse(markdown) diff --git a/Source/CDMarkdownBold.swift b/Source/CDMarkdownBold.swift index af59e2f..7ef4595 100644 --- a/Source/CDMarkdownBold.swift +++ b/Source/CDMarkdownBold.swift @@ -39,6 +39,8 @@ open class CDMarkdownBold: CDMarkdownCommonElement { open var color: CDColor? open var backgroundColor: CDColor? open var paragraphStyle: NSParagraphStyle? + open var underlineColor: CDColor? + open var underlineStyle: NSUnderlineStyle? open var regex: String { return CDMarkdownBold.regex @@ -48,7 +50,9 @@ open class CDMarkdownBold: CDMarkdownCommonElement { customBoldFont: CDFont? = nil, color: CDColor? = nil, backgroundColor: CDColor? = nil, - paragraphStyle: NSParagraphStyle? = nil) { + paragraphStyle: NSParagraphStyle? = nil, + underlineColor: CDColor? = nil, + underlineStyle: NSUnderlineStyle? = nil) { if let customBoldFont = customBoldFont { self.font = customBoldFont } else { @@ -58,5 +62,7 @@ open class CDMarkdownBold: CDMarkdownCommonElement { self.color = color self.backgroundColor = backgroundColor self.paragraphStyle = paragraphStyle + self.underlineColor = underlineColor + self.underlineStyle = underlineStyle } } diff --git a/Source/CDMarkdownCode.swift b/Source/CDMarkdownCode.swift index df4e51e..1b7f1af 100644 --- a/Source/CDMarkdownCode.swift +++ b/Source/CDMarkdownCode.swift @@ -39,6 +39,8 @@ open class CDMarkdownCode: CDMarkdownCommonElement { open var color: CDColor? open var backgroundColor: CDColor? open var paragraphStyle: NSParagraphStyle? + open var underlineColor: CDColor? + open var underlineStyle: NSUnderlineStyle? open var regex: String { return CDMarkdownCode.regex @@ -47,11 +49,15 @@ open class CDMarkdownCode: CDMarkdownCommonElement { public init(font: CDFont? = CDFont(name: "Menlo-Regular", size: 12), color: CDColor? = CDColor.codeTextRed(), backgroundColor: CDColor? = CDColor.codeBackgroundRed(), - paragraphStyle: NSParagraphStyle? = nil) { + paragraphStyle: NSParagraphStyle? = nil, + underlineColor: CDColor? = nil, + underlineStyle: NSUnderlineStyle? = nil) { self.font = font self.color = color self.backgroundColor = backgroundColor self.paragraphStyle = paragraphStyle + self.underlineColor = underlineColor + self.underlineStyle = underlineStyle } open func addAttributes(_ attributedString: NSMutableAttributedString, diff --git a/Source/CDMarkdownHeader.swift b/Source/CDMarkdownHeader.swift index 005a564..040d216 100644 --- a/Source/CDMarkdownHeader.swift +++ b/Source/CDMarkdownHeader.swift @@ -44,12 +44,14 @@ open class CDMarkdownHeader: CDMarkdownLevelElement { static let zero = 0 } - open var maxLevel: Int open var font: CDFont? + open var maxLevel: Int + open var fontIncrease: Int open var color: CDColor? open var backgroundColor: CDColor? open var paragraphStyle: NSParagraphStyle? - open var fontIncrease: Int + open var underlineColor: CDColor? + open var underlineStyle: NSUnderlineStyle? open var regex: String { let level: String = maxLevel > 0 ? "\(maxLevel)" : "" @@ -61,9 +63,12 @@ open class CDMarkdownHeader: CDMarkdownLevelElement { fontIncrease: Int = 2, color: CDColor? = nil, backgroundColor: CDColor? = nil, - paragraphStyle: NSParagraphStyle? = nil) { - self.maxLevel = maxLevel + paragraphStyle: NSParagraphStyle? = nil, + underlineColor: CDColor? = nil, + underlineStyle: NSUnderlineStyle? = nil) { self.font = font + self.maxLevel = maxLevel + self.fontIncrease = fontIncrease self.color = color self.backgroundColor = backgroundColor if let paragraphStyle = paragraphStyle { @@ -74,7 +79,8 @@ open class CDMarkdownHeader: CDMarkdownLevelElement { paragraphStyle.paragraphSpacingBefore = 12 self.paragraphStyle = paragraphStyle } - self.fontIncrease = fontIncrease + self.underlineColor = underlineColor + self.underlineStyle = underlineStyle } open func formatText(_ attributedString: NSMutableAttributedString, diff --git a/Source/CDMarkdownImage.swift b/Source/CDMarkdownImage.swift index 12c9b3c..d778bb3 100644 --- a/Source/CDMarkdownImage.swift +++ b/Source/CDMarkdownImage.swift @@ -42,6 +42,8 @@ open class CDMarkdownImage: CDMarkdownLinkElement { open var backgroundColor: CDColor? open var paragraphStyle: NSParagraphStyle? open var size: CGSize? + open var underlineColor: CDColor? + open var underlineStyle: NSUnderlineStyle? open var regex: String { return CDMarkdownImage.regex @@ -56,12 +58,16 @@ open class CDMarkdownImage: CDMarkdownLinkElement { color: CDColor? = CDColor.blue, backgroundColor: CDColor? = nil, paragraphStyle: NSParagraphStyle? = nil, - size: CGSize? = nil) { + size: CGSize? = nil, + underlineColor: CDColor? = nil, + underlineStyle: NSUnderlineStyle? = nil) { self.font = font self.color = color self.backgroundColor = backgroundColor self.paragraphStyle = paragraphStyle self.size = size + self.underlineColor = underlineColor + self.underlineStyle = underlineStyle } open func formatText(_ attributedString: NSMutableAttributedString, diff --git a/Source/CDMarkdownItalic.swift b/Source/CDMarkdownItalic.swift index 1a8e4bc..4e38017 100644 --- a/Source/CDMarkdownItalic.swift +++ b/Source/CDMarkdownItalic.swift @@ -39,6 +39,8 @@ open class CDMarkdownItalic: CDMarkdownCommonElement { open var color: CDColor? open var backgroundColor: CDColor? open var paragraphStyle: NSParagraphStyle? + open var underlineColor: CDColor? + open var underlineStyle: NSUnderlineStyle? open var regex: String { return CDMarkdownItalic.regex @@ -48,7 +50,9 @@ open class CDMarkdownItalic: CDMarkdownCommonElement { customItalicFont: CDFont? = nil, color: CDColor? = nil, backgroundColor: CDColor? = nil, - paragraphStyle: NSParagraphStyle? = nil) { + paragraphStyle: NSParagraphStyle? = nil, + underlineColor: CDColor? = nil, + underlineStyle: NSUnderlineStyle? = nil) { if let customItalicFont = customItalicFont { self.font = customItalicFont } else { @@ -58,5 +62,7 @@ open class CDMarkdownItalic: CDMarkdownCommonElement { self.color = color self.backgroundColor = backgroundColor self.paragraphStyle = paragraphStyle + self.underlineColor = underlineColor + self.underlineStyle = underlineStyle } } diff --git a/Source/CDMarkdownKit.swift b/Source/CDMarkdownKit.swift index 0f4877e..0a18542 100644 --- a/Source/CDMarkdownKit.swift +++ b/Source/CDMarkdownKit.swift @@ -33,4 +33,4 @@ import Foundation #endif /// Current CDMarkdownKit version. Necessary since SPM doesn't use dynamic libraries. Plus this will be more accurate. -let version = "2.4.0" +let version = "2.5.0" diff --git a/Source/CDMarkdownLink.swift b/Source/CDMarkdownLink.swift index 64a8c53..1b99780 100644 --- a/Source/CDMarkdownLink.swift +++ b/Source/CDMarkdownLink.swift @@ -39,6 +39,8 @@ open class CDMarkdownLink: CDMarkdownLinkElement { open var color: CDColor? open var backgroundColor: CDColor? open var paragraphStyle: NSParagraphStyle? + open var underlineColor: CDColor? + open var underlineStyle: NSUnderlineStyle? open var regex: String { return CDMarkdownLink.regex @@ -52,11 +54,15 @@ open class CDMarkdownLink: CDMarkdownLinkElement { public init(font: CDFont? = nil, color: CDColor? = CDColor.blue, backgroundColor: CDColor? = nil, - paragraphStyle: NSParagraphStyle? = nil) { + paragraphStyle: NSParagraphStyle? = nil, + underlineColor: CDColor? = nil, + underlineStyle: NSUnderlineStyle? = nil) { self.font = font self.color = color self.backgroundColor = backgroundColor self.paragraphStyle = paragraphStyle + self.underlineColor = underlineColor + self.underlineStyle = underlineStyle } open func formatText(_ attributedString: NSMutableAttributedString, diff --git a/Source/CDMarkdownList.swift b/Source/CDMarkdownList.swift index d5be69e..ee9aba6 100644 --- a/Source/CDMarkdownList.swift +++ b/Source/CDMarkdownList.swift @@ -35,13 +35,15 @@ open class CDMarkdownList: CDMarkdownLevelElement { fileprivate static let regex = "^\\s*([\\*\\+\\-]{1,%@})[ \t]+(.+)$" - open var maxLevel: Int open var font: CDFont? + open var maxLevel: Int + open var indicator: String + open var separator: String open var color: CDColor? open var backgroundColor: CDColor? open var paragraphStyle: NSParagraphStyle? - open var separator: String - open var indicator: String + open var underlineColor: CDColor? + open var underlineStyle: NSUnderlineStyle? open var regex: String { let level: String = maxLevel > 0 ? "\(maxLevel)" : "" @@ -55,11 +57,13 @@ open class CDMarkdownList: CDMarkdownLevelElement { separator: String = " ", color: CDColor? = nil, backgroundColor: CDColor? = nil, - paragraphStyle: NSParagraphStyle? = nil) { + paragraphStyle: NSParagraphStyle? = nil, + underlineColor: CDColor? = nil, + underlineStyle: NSUnderlineStyle? = nil) { + self.font = font self.maxLevel = maxLevel self.indicator = indicator self.separator = separator - self.font = font self.color = color self.backgroundColor = backgroundColor if let paragraphStyle = paragraphStyle { @@ -72,6 +76,8 @@ open class CDMarkdownList: CDMarkdownLevelElement { paragraphStyle.lineSpacing = 1.0 self.paragraphStyle = paragraphStyle } + self.underlineColor = underlineColor + self.underlineStyle = underlineStyle } open func formatText(_ attributedString: NSMutableAttributedString, diff --git a/Source/CDMarkdownQuote.swift b/Source/CDMarkdownQuote.swift index 3e8ae43..f758ea2 100644 --- a/Source/CDMarkdownQuote.swift +++ b/Source/CDMarkdownQuote.swift @@ -35,13 +35,15 @@ open class CDMarkdownQuote: CDMarkdownLevelElement { fileprivate static let regex = "^(\\>{1,%@})\\s*(.+)$" - open var maxLevel: Int open var font: CDFont? + open var maxLevel: Int + open var indicator: String + open var separator: String open var color: CDColor? open var backgroundColor: CDColor? open var paragraphStyle: NSParagraphStyle? - open var separator: String - open var indicator: String + open var underlineColor: CDColor? + open var underlineStyle: NSUnderlineStyle? open var regex: String { let level: String = maxLevel > 0 ? "\(maxLevel)" : "" @@ -55,14 +57,18 @@ open class CDMarkdownQuote: CDMarkdownLevelElement { separator: String = " ", color: CDColor? = nil, backgroundColor: CDColor? = nil, - paragraphStyle: NSParagraphStyle? = nil) { + paragraphStyle: NSParagraphStyle? = nil, + underlineColor: CDColor? = nil, + underlineStyle: NSUnderlineStyle? = nil) { + self.font = font self.maxLevel = maxLevel self.indicator = indicator self.separator = separator - self.font = font self.color = color self.backgroundColor = backgroundColor self.paragraphStyle = paragraphStyle + self.underlineColor = underlineColor + self.underlineStyle = underlineStyle } open func formatText(_ attributedString: NSMutableAttributedString, diff --git a/Source/CDMarkdownStrikethrough.swift b/Source/CDMarkdownStrikethrough.swift index 160567f..59f2627 100644 --- a/Source/CDMarkdownStrikethrough.swift +++ b/Source/CDMarkdownStrikethrough.swift @@ -41,8 +41,8 @@ open class CDMarkdownStrikethrough: CDMarkdownCommonElement { open var paragraphStyle: NSParagraphStyle? open var strikethroughColor: CDColor? open var strikethroughStyle: NSUnderlineStyle? - open var underlineStyle: NSUnderlineStyle? open var underlineColor: CDColor? + open var underlineStyle: NSUnderlineStyle? open var regex: String { return CDMarkdownStrikethrough.regex @@ -52,25 +52,29 @@ open class CDMarkdownStrikethrough: CDMarkdownCommonElement { color: CDColor? = nil, backgroundColor: CDColor? = nil, paragraphStyle: NSParagraphStyle? = nil, + strikethroughColor: CDColor? = nil, strikethroughStyle: NSUnderlineStyle? = .single, - strikethroughColor: CDColor? = nil) { + underlineColor: CDColor? = nil, + underlineStyle: NSUnderlineStyle? = nil) { self.font = font self.color = color self.backgroundColor = backgroundColor self.paragraphStyle = paragraphStyle self.strikethroughColor = strikethroughColor self.strikethroughStyle = strikethroughStyle + self.underlineColor = underlineColor + self.underlineStyle = underlineStyle } public func addAttributes(_ attributedString: NSMutableAttributedString, range: NSRange) { var adjustedAttributes = attributes - if let strikethroughStyle = strikethroughStyle { - adjustedAttributes.addStrikethroughStyle(strikethroughStyle) - } if let strikethroughColor = strikethroughColor { adjustedAttributes.addStrikethroughColor(strikethroughColor) } + if let strikethroughStyle = strikethroughStyle { + adjustedAttributes.addStrikethroughStyle(strikethroughStyle) + } attributedString.addAttributes(adjustedAttributes, range: range) } diff --git a/Source/CDMarkdownStyle.swift b/Source/CDMarkdownStyle.swift index 7ac6a0e..91888f3 100644 --- a/Source/CDMarkdownStyle.swift +++ b/Source/CDMarkdownStyle.swift @@ -38,6 +38,8 @@ public protocol CDMarkdownStyle { var color: CDColor? { get } var backgroundColor: CDColor? { get } var paragraphStyle: NSParagraphStyle? { get } + var underlineColor: CDColor? { get } + var underlineStyle: NSUnderlineStyle? { get } var attributes: [CDAttributedStringKey: AnyObject] { get } } @@ -58,6 +60,12 @@ public extension CDMarkdownStyle { if let paragraphStyle = paragraphStyle { attributes.addParagraphStyle(paragraphStyle) } + if let underlineColor = underlineColor { + attributes.addUnderlineColor(underlineColor) + } + if let underlineStyle = underlineStyle { + attributes.addUnderlineStyle(underlineStyle) + } return attributes } diff --git a/Source/CDMarkdownSyntax.swift b/Source/CDMarkdownSyntax.swift index 27e63b1..1ac9a4d 100644 --- a/Source/CDMarkdownSyntax.swift +++ b/Source/CDMarkdownSyntax.swift @@ -39,6 +39,8 @@ open class CDMarkdownSyntax: CDMarkdownCommonElement { open var color: CDColor? open var backgroundColor: CDColor? open var paragraphStyle: NSParagraphStyle? + open var underlineColor: CDColor? + open var underlineStyle: NSUnderlineStyle? open var regex: String { return CDMarkdownSyntax.regex @@ -47,11 +49,15 @@ open class CDMarkdownSyntax: CDMarkdownCommonElement { public init(font: CDFont? = CDFont(name: "Menlo-Regular", size: 12), color: CDColor? = CDColor.syntaxTextGray(), backgroundColor: CDColor? = CDColor.syntaxBackgroundGray(), - paragraphStyle: NSParagraphStyle? = nil) { + paragraphStyle: NSParagraphStyle? = nil, + underlineColor: CDColor? = nil, + underlineStyle: NSUnderlineStyle? = nil) { self.font = font self.color = color self.backgroundColor = backgroundColor self.paragraphStyle = paragraphStyle + self.underlineColor = underlineColor + self.underlineStyle = underlineStyle } open func addAttributes(_ attributedString: NSMutableAttributedString, diff --git a/Source/Dictionary+CDMarkdownKit.swift b/Source/Dictionary+CDMarkdownKit.swift index a657a94..eac975d 100644 --- a/Source/Dictionary+CDMarkdownKit.swift +++ b/Source/Dictionary+CDMarkdownKit.swift @@ -56,4 +56,12 @@ internal extension Dictionary where Key == CDAttributedStringKey { mutating func addStrikethroughStyle(_ strikethroughStyle: NSUnderlineStyle) { self[NSAttributedString.Key.strikethroughStyle] = strikethroughStyle.rawValue as? Value } + + mutating func addUnderlineColor(_ underlineColor: Value) { + self[NSAttributedString.Key.underlineColor] = underlineColor + } + + mutating func addUnderlineStyle(_ underlineStyle: NSUnderlineStyle) { + self[NSAttributedString.Key.underlineStyle] = underlineStyle.rawValue as? Value + } }