Skip to content

Commit

Permalink
feat: Add underline color and style to elements (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdhaan authored Dec 12, 2022
1 parent c23c137 commit 85f7731
Show file tree
Hide file tree
Showing 18 changed files with 128 additions and 33 deletions.
2 changes: 1 addition & 1 deletion CDMarkdownKit.podspec
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions CDMarkdownKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions Example/Source/BaseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ 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

[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
Expand All @@ -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"))
]
```

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion Source/CDMarkdownBold.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -58,5 +62,7 @@ open class CDMarkdownBold: CDMarkdownCommonElement {
self.color = color
self.backgroundColor = backgroundColor
self.paragraphStyle = paragraphStyle
self.underlineColor = underlineColor
self.underlineStyle = underlineStyle
}
}
8 changes: 7 additions & 1 deletion Source/CDMarkdownCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
16 changes: 11 additions & 5 deletions Source/CDMarkdownHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)" : ""
Expand All @@ -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 {
Expand All @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion Source/CDMarkdownImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion Source/CDMarkdownItalic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -58,5 +62,7 @@ open class CDMarkdownItalic: CDMarkdownCommonElement {
self.color = color
self.backgroundColor = backgroundColor
self.paragraphStyle = paragraphStyle
self.underlineColor = underlineColor
self.underlineStyle = underlineStyle
}
}
2 changes: 1 addition & 1 deletion Source/CDMarkdownKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
8 changes: 7 additions & 1 deletion Source/CDMarkdownLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
16 changes: 11 additions & 5 deletions Source/CDMarkdownList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)" : ""
Expand All @@ -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 {
Expand All @@ -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,
Expand Down
16 changes: 11 additions & 5 deletions Source/CDMarkdownQuote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)" : ""
Expand All @@ -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,
Expand Down
Loading

0 comments on commit 85f7731

Please sign in to comment.