Skip to content

Commit adb5aaa

Browse files
committed
Merge branch 'main' of github.com:ZhgChgLi/ZMarkupParser
2 parents a3b79ff + f9467d1 commit adb5aaa

File tree

5 files changed

+130
-0
lines changed

5 files changed

+130
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,23 @@ If you want to render huge html string, please use async instead.
316316
- If you're using a UILabel to render attributed strings, note that you can't change the color of .link text using the NSAttributedString.Key.foregroundColor attribute.
317317
- The ZHTMLParser library is intended for rendering partial HTML content, and may not be suitable for rendering very large or complex HTML documents. For these use cases, it's better to use a web view to render the HTML content.
318318

319+
## Sponsor
320+
321+
- If this project has been helpful to you, I would greatly appreciate your support.
322+
- If you're willing, you can consider buying me a cup of coffee as a token of encouragement.
323+
- Your brand will be displayed here, and the colors will be implemented in [MarkupStyleSponsorColor](https://github.com/ZhgChgLi/ZMarkupParser/blob/main/Sources/ZMarkupParser/Core/MarkupStyle/MarkupStyleSponsorColor.swift).
324+
- You can initialize the color directly using `MarkupStyleColor(sponsor: .pinkoi(.navy))`.
325+
319326
## Who is using
320327
[![pinkoi](https://user-images.githubusercontent.com/33706588/221343295-3e3831e6-f76d-430a-87e3-4daf9815297d.jpg)](https://en.pinkoi.com)
321328

322329
[Pinkoi.com](https://en.pinkoi.com) is Asia's leading online marketplace for original design goods, digital creations, and workshop experiences.
323330

331+
---
332+
- If your project/product is using ZMarkupParser, feel free to create a PR (Pull Request) here (the "Who is using" section in the Readme file). :)
333+
- Please also add your brand and brand colors to [MarkupStyleVendorColor.swift](https://github.com/ZhgChgLi/ZMarkupParser/blob/main/Sources/ZMarkupParser/Core/MarkupStyle/MarkupStyleVendorColor.swift).
334+
- You can initialize the color directly using `MarkupStyleVendorColor(vendor: .pinkoi(.navy))`.
335+
324336
## About
325337
- [ZhgChg.Li](https://zhgchg.li/)
326338
- [ZhgChgLi's Medium](https://blog.zhgchg.li/)

Sources/ZMarkupParser/Core/MarkupStyle/MarkupStyleColor.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ public struct MarkupStyleColor {
3636
let rgb = name.rgb
3737
self.init(red: rgb.0, green: rgb.1, blue: rgb.2, alpha: CGFloat(1.0))
3838
}
39+
40+
public init?(vendor: MarkupStyleVendorColor) {
41+
let rgb = vendor.rgb
42+
self.init(red: rgb.0, green: rgb.1, blue: rgb.2, alpha: CGFloat(1.0))
43+
}
44+
45+
public init?(sponsor: MarkupStyleSponsorColor) {
46+
let rgb = sponsor.rgb
47+
self.init(red: rgb.0, green: rgb.1, blue: rgb.2, alpha: CGFloat(1.0))
48+
}
3949

4050
public init?(string: String) {
4151
let rgba: (Int,Int,Int,CGFloat)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// MarkupStyleSponsorColor.swift
3+
//
4+
//
5+
// Created by zhgchgli on 2023/8/15.
6+
//
7+
8+
import Foundation
9+
10+
/// # If this project has been helpful to you, I would greatly appreciate your support.
11+
/// # If you're willing, you can consider buying me a cup of coffee as a token of encouragement.
12+
/// # Thank you very much for your support!
13+
/// ## Your brand and colors will be implemented here.
14+
///
15+
public enum MarkupStyleSponsorColor {
16+
17+
// == Pinkoi.com ==
18+
public enum PinkoiColor: CaseIterable {
19+
case nvay
20+
case salmon
21+
22+
var rgb: (Int, Int, Int) {
23+
switch self {
24+
case .nvay:
25+
return (0,20,33)
26+
case .salmon:
27+
return (93,52,49)
28+
}
29+
}
30+
}
31+
case pinkoi(PinkoiColor)
32+
// == Pinkoi.com ==
33+
34+
var rgb: (Int, Int, Int) {
35+
switch self {
36+
case .pinkoi(let color):
37+
return color.rgb
38+
}
39+
}
40+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// MarkupStyleVendorColor.swift
3+
//
4+
//
5+
// Created by zhgchgli on 2023/8/15.
6+
//
7+
8+
import Foundation
9+
10+
/// # If your project/product is using ZMarkupParser, feel free to create a PR (Pull Request) to add your brand and brand colors. :)
11+
/// # Please also add your project/product to the "Who is using" section in the Readme file.
12+
///
13+
/// ## Tools:
14+
/// Conver HEX String Color to RGB Online: https://www.colorhexa.com/ee847d
15+
///
16+
17+
public enum MarkupStyleVendorColor {
18+
19+
// == Pinkoi.com ==
20+
public enum PinkoiColor: CaseIterable {
21+
case nvay
22+
case salmon
23+
24+
var rgb: (Int, Int, Int) {
25+
switch self {
26+
case .nvay:
27+
return (0,20,33)
28+
case .salmon:
29+
return (93,52,49)
30+
}
31+
}
32+
}
33+
case pinkoi(PinkoiColor)
34+
// == Pinkoi.com ==
35+
36+
var rgb: (Int, Int, Int) {
37+
switch self {
38+
case .pinkoi(let color):
39+
return color.rgb
40+
}
41+
}
42+
}

Tests/ZMarkupParserTests/Core/MarkupStyleColorTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,32 @@ import AppKit
1717
// helper: https://www.uicolor.io
1818
final class MarkupStyleColorTests: XCTestCase {
1919

20+
func testInitStyleFromSponsorPinkoiColor() throws {
21+
let allCases = MarkupStyleSponsorColor.PinkoiColor.allCases
22+
for colorName in allCases {
23+
let sponsor = MarkupStyleSponsorColor.pinkoi(colorName)
24+
25+
let markupStyleColor = MarkupStyleColor(sponsor: sponsor)
26+
XCTAssertEqual(markupStyleColor?.red, colorName.rgb.0)
27+
XCTAssertEqual(markupStyleColor?.green, colorName.rgb.1)
28+
XCTAssertEqual(markupStyleColor?.blue, colorName.rgb.2)
29+
XCTAssertEqual(markupStyleColor?.alpha, 1)
30+
}
31+
}
32+
33+
func testInitStyleFromVendorPinkoiColor() throws {
34+
let allCases = MarkupStyleVendorColor.PinkoiColor.allCases
35+
for colorName in allCases {
36+
let vendor = MarkupStyleVendorColor.pinkoi(colorName)
37+
38+
let markupStyleColor = MarkupStyleColor(vendor: vendor)
39+
XCTAssertEqual(markupStyleColor?.red, colorName.rgb.0)
40+
XCTAssertEqual(markupStyleColor?.green, colorName.rgb.1)
41+
XCTAssertEqual(markupStyleColor?.blue, colorName.rgb.2)
42+
XCTAssertEqual(markupStyleColor?.alpha, 1)
43+
}
44+
}
45+
2046
func testInitStyleFromColorName() throws {
2147
let allCases = MarkupStyleColorName.allCases
2248
for colorName in allCases {

0 commit comments

Comments
 (0)