Skip to content

Commit 940dbe5

Browse files
committed
Support iOS.
1 parent 7be017b commit 940dbe5

File tree

7 files changed

+235
-55
lines changed

7 files changed

+235
-55
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 1.0.3 (2021-02-03)
4+
- Make framework available to iOS
5+
36
## 1.0.2 (2020-10-04)
47
- Improved extensibility of `AttributedStringGenerator` class
58

MarkdownKit.xcodeproj/project.pbxproj

Lines changed: 153 additions & 5 deletions
Large diffs are not rendered by default.

Package.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// swift build -c release
1111
//
1212
// Created by Matthias Zenger on 09/08/2019.
13-
// Copyright © 2019 Google LLC.
13+
// Copyright © 2019-2021 Google LLC.
1414
//
1515
// Licensed under the Apache License, Version 2.0 (the "License");
1616
// you may not use this file except in compliance with the License.
@@ -30,7 +30,8 @@ import PackageDescription
3030
let package = Package(
3131
name: "MarkdownKit",
3232
platforms: [
33-
.macOS(.v10_12)
33+
.macOS(.v10_12),
34+
.iOS(.v12)
3435
],
3536
products: [
3637
.library(name: "MarkdownKit", targets: ["MarkdownKit"]),

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Swift MarkdownKit
22

33
<p>
4-
<a href="https://developer.apple.com/osx/"><img src="https://img.shields.io/badge/Platform-macOS-blue.svg?style=flat" alt="Platform: macOS" /></a>
4+
<a href="https://developer.apple.com/osx/"><img src="https://img.shields.io/badge/Platform-macOS%20%7C%20iOS-blue.svg?style=flat" alt="Platform: macOS | iOS" /></a>
55
<a href="https://developer.apple.com/swift/"><img src="https://img.shields.io/badge/Language-Swift%205.3-green.svg?style=flat" alt="Language: Swift 5.3" /></a>
6-
<a href="https://developer.apple.com/xcode/"><img src="https://img.shields.io/badge/IDE-Xcode%2012.0-orange.svg?style=flat" alt="IDE: Xcode 12.0" /></a>
6+
<a href="https://developer.apple.com/xcode/"><img src="https://img.shields.io/badge/IDE-Xcode%2012.4-orange.svg?style=flat" alt="IDE: Xcode 12.4" /></a>
77
<a href="https://raw.github.com/objecthub/swift-markdownkit/master/LICENSE"><img src="http://img.shields.io/badge/License-Apache-lightgrey.svg?style=flat" alt="License: Apache" /></a>
88
</p>
99

@@ -239,12 +239,12 @@ The command-line tool can be compiled with the _Swift Package Manager_, so _Xcod
239239
for that. Similarly, just for compiling the framework and trying the command-line tool in _Xcode_, the
240240
_Swift Package Manager_ is not needed.
241241

242-
- [Xcode 12.0](https://developer.apple.com/xcode/)
242+
- [Xcode 12.4](https://developer.apple.com/xcode/)
243243
- [Swift 5.3](https://developer.apple.com/swift/)
244244
- [Swift Package Manager](https://swift.org/package-manager/)
245245

246246
## Copyright
247247

248248
Author: Matthias Zenger (<matthias@objecthub.net>)
249-
Copyright © 2019-2020 Google LLC.
249+
Copyright © 2019-2021 Google LLC.
250250
_Please note: This is not an official Google product._

Sources/MarkdownKit/AttributedString/AttributedStringGenerator.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
// limitations under the License.
1919
//
2020

21-
import Cocoa
21+
#if os(iOS)
22+
import UIKit
23+
#elseif os(OSX)
24+
import Cocoa
25+
#endif
2226

2327
///
2428
/// `AttributedStringGenerator` provides functionality for converting Markdown blocks into
@@ -157,20 +161,20 @@ open class AttributedStringGenerator {
157161
/// Constructor providing customization options for the generated `NSAttributedString` markup.
158162
public init(fontSize: Float = 14.0,
159163
fontFamily: String = "\"Times New Roman\",Times,serif",
160-
fontColor: String = NSColor.textColor.hexString,
164+
fontColor: String = mdDefaultColor,
161165
codeFontSize: Float = 13.0,
162166
codeFontFamily: String =
163167
"\"Consolas\",\"Andale Mono\",\"Courier New\",Courier,monospace",
164-
codeFontColor: String = NSColor.textColor.hexString,
168+
codeFontColor: String = mdDefaultColor,
165169
codeBlockFontSize: Float = 12.0,
166-
codeBlockFontColor: String = NSColor.textColor.hexString,
167-
codeBlockBackground: String = NSColor.textBackgroundColor.hexString,
170+
codeBlockFontColor: String = mdDefaultColor,
171+
codeBlockBackground: String = mdDefaultBackgroundColor,
168172
borderColor: String = "#bbb",
169173
blockquoteColor: String = "#99c",
170-
h1Color: String = NSColor.textColor.hexString,
171-
h2Color: String = NSColor.textColor.hexString,
172-
h3Color: String = NSColor.textColor.hexString,
173-
h4Color: String = NSColor.textColor.hexString) {
174+
h1Color: String = mdDefaultColor,
175+
h2Color: String = mdDefaultColor,
176+
h3Color: String = mdDefaultColor,
177+
h4Color: String = mdDefaultColor) {
174178
self.fontSize = fontSize
175179
self.fontFamily = fontFamily
176180
self.fontColor = fontColor
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//
2+
// Color.swift
3+
// MarkdownKit
4+
//
5+
// Created by Matthias Zenger on 18/08/2019.
6+
// Copyright © 2019 Google LLC.
7+
//
8+
// Licensed under the Apache License, Version 2.0 (the "License");
9+
// you may not use this file except in compliance with the License.
10+
// You may obtain a copy of the License at
11+
//
12+
// http://www.apache.org/licenses/LICENSE-2.0
13+
//
14+
// Unless required by applicable law or agreed to in writing, software
15+
// distributed under the License is distributed on an "AS IS" BASIS,
16+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
// See the License for the specific language governing permissions and
18+
// limitations under the License.
19+
//
20+
21+
#if os(iOS)
22+
import UIKit
23+
24+
extension UIColor {
25+
26+
public var hexString: String {
27+
guard let components = self.cgColor.components, components.count >= 3 else {
28+
return "#FFFFFF"
29+
}
30+
let red = Int(round(components[0] * 0xff))
31+
let green = Int(round(components[1] * 0xff))
32+
let blue = Int(round(components[2] * 0xff))
33+
return String(format: "#%02X%02X%02X", red, green, blue)
34+
}
35+
}
36+
37+
public let mdDefaultColor = UIColor.darkText.hexString
38+
public let mdDefaultBackgroundColor = UIColor.systemBackground.hexString
39+
40+
#elseif os(OSX)
41+
import Cocoa
42+
43+
extension NSColor {
44+
45+
public var hexString: String {
46+
guard let rgb = self.usingColorSpaceName(NSColorSpaceName.calibratedRGB) else {
47+
return "#FFFFFF"
48+
}
49+
let red = Int(round(rgb.redComponent * 0xff))
50+
let green = Int(round(rgb.greenComponent * 0xff))
51+
let blue = Int(round(rgb.blueComponent * 0xff))
52+
return String(format: "#%02X%02X%02X", red, green, blue)
53+
}
54+
}
55+
56+
public let mdDefaultColor = NSColor.textColor.hexString
57+
public let mdDefaultBackgroundColor = NSColor.textBackgroundColor.hexString
58+
59+
#endif

Sources/MarkdownKit/AttributedString/NSColor.swift

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)