Skip to content

Commit 6343fa1

Browse files
committed
Add new support area
1 parent 77eaab9 commit 6343fa1

40 files changed

+4551
-7
lines changed

Modules/Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/Package.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ let package = Package(
1616
.library(name: "NotificationServiceExtensionCore", targets: ["NotificationServiceExtensionCore"]),
1717
.library(name: "ShareExtensionCore", targets: ["ShareExtensionCore"]),
1818
.library(name: "SFHFKeychainUtils", targets: ["SFHFKeychainUtils"]),
19+
.library(name: "Support", targets: ["Support"]),
1920
.library(name: "WordPressFlux", targets: ["WordPressFlux"]),
2021
.library(name: "WordPressShared", targets: ["WordPressShared"]),
2122
.library(name: "WordPressUI", targets: ["WordPressUI"]),
@@ -52,8 +53,8 @@ let package = Package(
5253
.package(url: "https://github.com/wordpress-mobile/NSURL-IDN", revision: "b34794c9a3f32312e1593d4a3d120572afa0d010"),
5354
.package(url: "https://github.com/zendesk/support_sdk_ios", from: "8.0.3"),
5455
// We can't use wordpress-rs branches nor commits here. Only tags work.
55-
.package(url: "https://github.com/Automattic/wordpress-rs", revision: "alpha-20250926"),
5656
.package(url: "https://github.com/wordpress-mobile/GutenbergKit", from: "0.9.0"),
57+
.package(url: "https://github.com/Automattic/wordpress-rs", revision: "alpha-20251007"),
5758
.package(
5859
url: "https://github.com/Automattic/color-studio",
5960
revision: "bf141adc75e2769eb469a3e095bdc93dc30be8de"
@@ -132,6 +133,12 @@ let package = Package(
132133
name: "SFHFKeychainUtils",
133134
cSettings: [.unsafeFlags(["-fno-objc-arc"])]
134135
),
136+
.target(
137+
name: "Support",
138+
dependencies: [
139+
"AsyncImageKit"
140+
]
141+
),
135142
.target(name: "TextBundle"),
136143
.target(
137144
name: "TracksMini",
@@ -329,6 +336,7 @@ enum XcodeSupport {
329336
"NotificationServiceExtensionCore",
330337
"SFHFKeychainUtils",
331338
"ShareExtensionCore",
339+
"Support",
332340
"WordPressFlux",
333341
"WordPressShared",
334342
"WordPressLegacy",
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import Foundation
2+
3+
extension Date {
4+
var isToday: Bool {
5+
let calendar = Calendar.autoupdatingCurrent
6+
return calendar.isDateInToday(self)
7+
}
8+
}
9+
10+
extension AttributedString {
11+
func toHtml() -> String {
12+
NSAttributedString(self).toHtml()
13+
}
14+
}
15+
16+
extension NSAttributedString {
17+
func toHtml() -> String {
18+
let documentAttributes = [
19+
NSAttributedString.DocumentAttributeKey.documentType: NSAttributedString.DocumentType.html
20+
]
21+
22+
guard
23+
let htmlData = try? self.data(from: NSMakeRange(0, self.length), documentAttributes: documentAttributes),
24+
let htmlString = String(data: htmlData, encoding: .utf8)
25+
else {
26+
return self.string
27+
}
28+
29+
return htmlString
30+
}
31+
}
32+
33+
func convertMarkdownHeadingsToBold(in markdown: String) -> String {
34+
let lines = markdown.components(separatedBy: .newlines)
35+
var convertedLines: [String] = []
36+
37+
for line in lines {
38+
let trimmedLine = line.trimmingCharacters(in: .whitespaces)
39+
40+
// Check if line starts with one or more # characters followed by a space
41+
if trimmedLine.hasPrefix("#") {
42+
// Find the first non-# character
43+
let hashCount = trimmedLine.prefix(while: { $0 == "#" }).count
44+
45+
// Make sure there's at least one # and that it's followed by a space or end of string
46+
if hashCount > 0 && hashCount < trimmedLine.count {
47+
let remainingText = String(trimmedLine.dropFirst(hashCount))
48+
49+
// Check if there's a space after the hashes (proper markdown heading format)
50+
if remainingText.hasPrefix(" ") {
51+
let headingText = remainingText.trimmingCharacters(in: .whitespaces)
52+
if !headingText.isEmpty {
53+
// Convert to bold text
54+
convertedLines.append("**\(headingText)**")
55+
continue
56+
}
57+
}
58+
}
59+
}
60+
61+
// If not a heading, keep the original line
62+
convertedLines.append(line)
63+
}
64+
65+
return convertedLines.joined(separator: "\n")
66+
}
67+
68+
func convertMarkdownTextToAttributedString(_ text: String) -> AttributedString {
69+
do {
70+
// The iOS Markdown parser doesn't support headings, so we need to convert those
71+
let modifiedText = convertMarkdownHeadingsToBold(in: text)
72+
return try AttributedString(
73+
markdown: modifiedText,
74+
options: AttributedString.MarkdownParsingOptions(
75+
interpretedSyntax: .inlineOnlyPreservingWhitespace
76+
)
77+
)
78+
} catch {
79+
// Fallback to plain-text rendering
80+
return AttributedString(text)
81+
}
82+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import SwiftUI
2+
3+
extension EdgeInsets {
4+
static let zero = EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)
5+
}

0 commit comments

Comments
 (0)